Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Problems.LinearAssignment/3.3/LAPAssignment.cs @ 8388

Last change on this file since 8388 was 8183, checked in by abeham, 12 years ago

#1855:

  • Added IStorableContent to HungarianAlgorithm, LinearAssignmentProblem, and LAPAssignment (it was only storable, because the result is storable)
  • Added separate AfterDeserialization hook and renamed AttachEventHandlers to RegisterEventHandlers
  • Added cloning of rowNames and columnNames in LAPAssignment
  • Changed the default instance of the LinearAssignmentProblem
File size: 4.2 KB
Line 
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
22using System.ComponentModel;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.LinearAssignment {
30  [Item("LAP Assignment", "Represents a solution to the LAP.")]
31  [StorableClass]
32  public sealed class LAPAssignment : Item, INotifyPropertyChanged, IStorableContent {
33    public string Filename { get; set; }
34
35    [Storable]
36    private DoubleMatrix costs;
37    public DoubleMatrix Costs {
38      get { return costs; }
39      set {
40        bool changed = (costs != value);
41        costs = value;
42        if (changed) OnPropertyChanged("Costs");
43      }
44    }
45
46    [Storable]
47    private StringArray rowNames;
48    public StringArray RowNames {
49      get { return rowNames; }
50      set {
51        bool changed = (rowNames != value);
52        rowNames = value;
53        if (changed) OnPropertyChanged("RowNames");
54      }
55    }
56
57    [Storable]
58    private StringArray columnNames;
59    public StringArray ColumnNames {
60      get { return columnNames; }
61      set {
62        bool changed = (columnNames != value);
63        columnNames = value;
64        if (changed) OnPropertyChanged("ColumnNames");
65      }
66    }
67
68    [Storable]
69    private Permutation assignment;
70    public Permutation Assignment {
71      get { return assignment; }
72      set {
73        bool changed = (assignment != value);
74        assignment = value;
75        if (changed) OnPropertyChanged("Assignment");
76      }
77    }
78
79    [Storable]
80    private DoubleValue quality;
81    public DoubleValue Quality {
82      get { return quality; }
83      set {
84        bool changed = (quality != value);
85        quality = value;
86        if (changed) OnPropertyChanged("Quality");
87      }
88    }
89
90    [StorableConstructor]
91    private LAPAssignment(bool deserializing) : base(deserializing) { }
92    private LAPAssignment(LAPAssignment original, Cloner cloner)
93      : base(original, cloner) {
94      costs = cloner.Clone(original.costs);
95      assignment = cloner.Clone(original.assignment);
96      rowNames = cloner.Clone(original.rowNames);
97      columnNames = cloner.Clone(original.columnNames);
98      quality = cloner.Clone(original.quality);
99    }
100    public LAPAssignment(DoubleMatrix costs, Permutation assignment) {
101      this.costs = costs;
102      this.assignment = assignment;
103    }
104    public LAPAssignment(DoubleMatrix costs, Permutation assignment, DoubleValue quality)
105      : this(costs, assignment) {
106      this.quality = quality;
107    }
108    public LAPAssignment(DoubleMatrix costs, StringArray rowNames, StringArray columnNames, Permutation assignment)
109      : this(costs, assignment) {
110      this.rowNames = rowNames;
111      this.columnNames = columnNames;
112    }
113    public LAPAssignment(DoubleMatrix costs, StringArray rowNames, StringArray columnNames, Permutation assignment, DoubleValue quality)
114      : this(costs, rowNames, columnNames, assignment) {
115      this.quality = quality;
116    }
117
118    public override IDeepCloneable Clone(Cloner cloner) {
119      return new LAPAssignment(this, cloner);
120    }
121
122    public event PropertyChangedEventHandler PropertyChanged;
123    private void OnPropertyChanged(string propertyName) {
124      var handler = PropertyChanged;
125      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.