[7873] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Drawing;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.LinearAssignment {
|
---|
| 32 | [Item("LinearAssignmentProblem", "In the linear assignment problem (LAP) an assignment of workers to jobs has to be found such that each worker is assigned to exactly one job, each job is assigned to exactly one worker and the sum of the resulting costs needs to be minimal.")]
|
---|
| 33 | [Creatable("Problems")]
|
---|
| 34 | [StorableClass]
|
---|
| 35 | public sealed class LinearAssignmentProblem : Problem {
|
---|
| 36 | public override Image ItemImage {
|
---|
| 37 | get { return HeuristicLab.Common.Resources.VSImageLibrary.Type; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | #region Parameter Properties
|
---|
| 41 | public IValueParameter<DoubleMatrix> CostsParameter {
|
---|
| 42 | get { return (IValueParameter<DoubleMatrix>)Parameters["Costs"]; }
|
---|
| 43 | }
|
---|
| 44 | public IValueParameter<IntArray> SolutionParameter {
|
---|
| 45 | get { return (IValueParameter<IntArray>)Parameters["Solution"]; }
|
---|
| 46 | }
|
---|
| 47 | public IValueParameter<DoubleValue> QualityParameter {
|
---|
| 48 | get { return (IValueParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 49 | }
|
---|
| 50 | #endregion
|
---|
| 51 |
|
---|
| 52 | #region Properties
|
---|
| 53 | public DoubleMatrix Costs {
|
---|
| 54 | get { return CostsParameter.Value; }
|
---|
| 55 | set { CostsParameter.Value = value; }
|
---|
| 56 | }
|
---|
| 57 | public IntArray Solution {
|
---|
| 58 | get { return SolutionParameter.Value; }
|
---|
| 59 | set { SolutionParameter.Value = value; }
|
---|
| 60 | }
|
---|
| 61 | public DoubleValue Quality {
|
---|
| 62 | get { return QualityParameter.Value; }
|
---|
| 63 | set { QualityParameter.Value = value; }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | #endregion
|
---|
| 67 |
|
---|
| 68 | [StorableConstructor]
|
---|
| 69 | private LinearAssignmentProblem(bool deserializing) : base(deserializing) { }
|
---|
| 70 | private LinearAssignmentProblem(LinearAssignmentProblem original, Cloner cloner)
|
---|
| 71 | : base(original, cloner) {
|
---|
| 72 | AttachEventHandlers();
|
---|
| 73 | }
|
---|
| 74 | public LinearAssignmentProblem()
|
---|
| 75 | : base() {
|
---|
| 76 | Parameters.Add(new ValueParameter<DoubleMatrix>("Costs", "The cost matrix that describes the assignment of rows to columns.", new DoubleMatrix(3, 3)));
|
---|
| 77 | Parameters.Add(new OptionalValueParameter<IntArray>("Solution", "An optimal solution.", null));
|
---|
| 78 | Parameters.Add(new OptionalValueParameter<DoubleValue>("Quality", "The solution quality.", null));
|
---|
| 79 |
|
---|
| 80 | ((ValueParameter<DoubleMatrix>)CostsParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false;
|
---|
| 81 |
|
---|
| 82 | AttachEventHandlers();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 86 | return new LinearAssignmentProblem(this, cloner);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | #region Events
|
---|
| 90 | private void Costs_RowsChanged(object sender, EventArgs e) {
|
---|
| 91 | if (Costs.Rows != Costs.Columns)
|
---|
| 92 | ((IStringConvertibleMatrix)Costs).Columns = Costs.Rows;
|
---|
| 93 | }
|
---|
| 94 | private void Costs_ColumnsChanged(object sender, EventArgs e) {
|
---|
| 95 | if (Costs.Rows != Costs.Columns)
|
---|
| 96 | ((IStringConvertibleMatrix)Costs).Rows = Costs.Columns;
|
---|
| 97 | }
|
---|
| 98 | #endregion
|
---|
| 99 |
|
---|
| 100 | #region Helpers
|
---|
| 101 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 102 | private void AfterDeserializationHook() {
|
---|
| 103 | AttachEventHandlers();
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | private void AttachEventHandlers() {
|
---|
| 107 | Costs.RowsChanged += new EventHandler(Costs_RowsChanged);
|
---|
| 108 | Costs.ColumnsChanged += new EventHandler(Costs_ColumnsChanged);
|
---|
| 109 | }
|
---|
| 110 | #endregion
|
---|
| 111 | }
|
---|
| 112 | }
|
---|