Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2916_IndexedDataTableSerialization/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs @ 16008

Last change on this file since 16008 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 11.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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;
23using System.Drawing;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.IntegerVectorEncoding;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.Orienteering {
31  [Item("OrienteeringSolution", "Represents a Orienteering solution which can be visualized in the GUI.")]
32  [StorableClass]
33  public sealed class OrienteeringSolution : Item {
34    public static new Image StaticItemImage {
35      get { return HeuristicLab.Common.Resources.VSImageLibrary.Image; }
36    }
37
38    [Storable]
39    private IntegerVector integerVector;
40    public IntegerVector IntegerVector {
41      get { return integerVector; }
42      set {
43        if (integerVector != value) {
44          if (integerVector != null) DeregisterIntegerVectorEvents();
45          integerVector = value;
46          if (integerVector != null) RegisterIntegerVectorEvents();
47          OnIntegerVectorChanged();
48        }
49      }
50    }
51    [Storable]
52    private DoubleMatrix coordinates;
53    public DoubleMatrix Coordinates {
54      get { return coordinates; }
55      set {
56        if (coordinates != value) {
57          if (coordinates != null) DeregisterCoordinatesEvents();
58          coordinates = value;
59          if (coordinates != null) RegisterCoordinatesEvents();
60          OnCoordinatesChanged();
61        }
62      }
63    }
64    [Storable]
65    private IntValue startingPoint;
66    public IntValue StartingPoint {
67      get { return startingPoint; }
68      set {
69        if (startingPoint != value) {
70          if (startingPoint != null) DeregisterStartingPointEvents();
71          startingPoint = value;
72          if (startingPoint != null) RegisterStartingPointEvents();
73          OnStartingPointChanged();
74        }
75      }
76    }
77    [Storable]
78    private IntValue terminalPoint;
79    public IntValue TerminalPoint {
80      get { return terminalPoint; }
81      set {
82        if (terminalPoint != value) {
83          if (terminalPoint != null) DeregisterTerminalPointEvents();
84          terminalPoint = value;
85          if (terminalPoint != null) RegisterTerminalPointEvents();
86          OnTerminalPointChanged();
87        }
88      }
89    }
90    [Storable]
91    private DoubleArray scores;
92    public DoubleArray Scores {
93      get { return scores; }
94      set {
95        if (scores != value) {
96          if (scores != null) DeregisterScoresEvents();
97          scores = value;
98          if (scores != null) RegisterScoresEvents();
99          OnScoresChanged();
100        }
101      }
102    }
103    [Storable]
104    private DoubleValue quality;
105    public DoubleValue Quality {
106      get { return quality; }
107      set {
108        if (quality != value) {
109          if (quality != null) DeregisterQualityEvents();
110          quality = value;
111          if (quality != null) RegisterQualityEvents();
112          OnQualityChanged();
113        }
114      }
115    }
116    [Storable]
117    private DoubleValue penalty;
118    public DoubleValue Penalty {
119      get { return penalty; }
120      set {
121        if (penalty != value) {
122          if (penalty != null) DeregisterPenaltyEvents();
123          penalty = value;
124          if (penalty != null) RegisterPenaltyEvents();
125          OnPenaltyChanged();
126        }
127      }
128    }
129    [Storable]
130    private DoubleValue distance;
131    public DoubleValue Distance {
132      get { return distance; }
133      set {
134        if (distance != value) {
135          if (distance != null) DeregisterDistanceEvents();
136          distance = value;
137          if (distance != null) RegisterDistanceEvents();
138          OnDistanceChanged();
139        }
140      }
141    }
142
143    [StorableConstructor]
144    private OrienteeringSolution(bool deserializing)
145      : base(deserializing) { }
146    private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
147      : base(original, cloner) {
148      this.integerVector = cloner.Clone(original.integerVector);
149      this.coordinates = cloner.Clone(original.coordinates);
150      this.quality = cloner.Clone(original.quality);
151      this.penalty = cloner.Clone(original.penalty);
152      Initialize();
153    }
154    public OrienteeringSolution(IntegerVector integerVector, DoubleMatrix coordinates, IntValue startingPoint, IntValue terminalPoint,
155      DoubleArray scores, DoubleValue quality = null, DoubleValue penalty = null, DoubleValue distance = null)
156      : base() {
157      this.integerVector = integerVector;
158      this.coordinates = coordinates;
159      this.startingPoint = startingPoint;
160      this.terminalPoint = terminalPoint;
161      this.scores = scores;
162      this.quality = quality;
163      this.penalty = penalty;
164      this.distance = distance;
165      Initialize();
166    }
167
168    public override IDeepCloneable Clone(Cloner cloner) {
169      return new OrienteeringSolution(this, cloner);
170    }
171
172    [StorableHook(HookType.AfterDeserialization)]
173    private void AfterDeserialization() {
174      Initialize();
175    }
176
177    private void Initialize() {
178      if (integerVector != null) RegisterIntegerVectorEvents();
179      if (coordinates != null) RegisterCoordinatesEvents();
180      if (startingPoint != null) RegisterStartingPointEvents();
181      if (terminalPoint != null) RegisterTerminalPointEvents();
182      if (scores != null) RegisterScoresEvents();
183      if (quality != null) RegisterQualityEvents();
184      if (penalty != null) RegisterPenaltyEvents();
185      if (distance != null) RegisterDistanceEvents();
186    }
187
188    #region Events
189    public event EventHandler IntegerVectorChanged;
190    private void OnIntegerVectorChanged() {
191      var changed = IntegerVectorChanged;
192      if (changed != null)
193        changed(this, EventArgs.Empty);
194    }
195
196    public event EventHandler CoordinatesChanged;
197    private void OnCoordinatesChanged() {
198      var changed = CoordinatesChanged;
199      if (changed != null)
200        changed(this, EventArgs.Empty);
201    }
202
203    public event EventHandler StartingPointChanged;
204    private void OnStartingPointChanged() {
205      var changed = StartingPointChanged;
206      if (changed != null)
207        changed(this, EventArgs.Empty);
208    }
209
210    public event EventHandler TerminalPointChanged;
211    private void OnTerminalPointChanged() {
212      var changed = TerminalPointChanged;
213      if (changed != null)
214        changed(this, EventArgs.Empty);
215    }
216
217    public event EventHandler ScoresChanged;
218    private void OnScoresChanged() {
219      var changed = ScoresChanged;
220      if (changed != null)
221        changed(this, EventArgs.Empty);
222    }
223
224    public event EventHandler QualityChanged;
225    private void OnQualityChanged() {
226      var changed = QualityChanged;
227      if (changed != null)
228        changed(this, EventArgs.Empty);
229    }
230
231    public event EventHandler PenaltyChanged;
232    private void OnPenaltyChanged() {
233      var changed = PenaltyChanged;
234      if (changed != null)
235        changed(this, EventArgs.Empty);
236    }
237
238    public event EventHandler DistanceChanged;
239    private void OnDistanceChanged() {
240      var changed = DistanceChanged;
241      if (changed != null)
242        changed(this, EventArgs.Empty);
243    }
244
245    private void RegisterIntegerVectorEvents() {
246      IntegerVector.ItemChanged += new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
247      IntegerVector.Reset += new EventHandler(IntegerVector_Reset);
248    }
249    private void DeregisterIntegerVectorEvents() {
250      IntegerVector.ItemChanged -= new EventHandler<EventArgs<int>>(IntegerVector_ItemChanged);
251      IntegerVector.Reset -= new EventHandler(IntegerVector_Reset);
252    }
253    private void RegisterCoordinatesEvents() {
254      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
255      Coordinates.Reset += new EventHandler(Coordinates_Reset);
256    }
257    private void DeregisterCoordinatesEvents() {
258      Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
259      Coordinates.Reset -= new EventHandler(Coordinates_Reset);
260    }
261    private void RegisterStartingPointEvents() {
262      StartingPoint.ValueChanged += new EventHandler(StartingPoint_ValueChanged);
263    }
264    private void DeregisterStartingPointEvents() {
265      StartingPoint.ValueChanged -= new EventHandler(StartingPoint_ValueChanged);
266    }
267    private void RegisterTerminalPointEvents() {
268      TerminalPoint.ValueChanged += new EventHandler(TerminalPoint_ValueChanged);
269    }
270    private void DeregisterTerminalPointEvents() {
271      TerminalPoint.ValueChanged -= new EventHandler(TerminalPoint_ValueChanged);
272    }
273    private void RegisterScoresEvents() {
274      Scores.ItemChanged += new EventHandler<EventArgs<int>>(Scores_ItemChanged);
275      Scores.Reset += new EventHandler(Scores_Reset);
276    }
277    private void DeregisterScoresEvents() {
278      Scores.ItemChanged -= new EventHandler<EventArgs<int>>(Scores_ItemChanged);
279      Scores.Reset -= new EventHandler(Scores_Reset);
280    }
281    private void RegisterQualityEvents() {
282      Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
283    }
284    private void DeregisterQualityEvents() {
285      Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
286    }
287    private void RegisterPenaltyEvents() {
288      Penalty.ValueChanged += new EventHandler(Penalty_ValueChanged);
289    }
290    private void DeregisterPenaltyEvents() {
291      Penalty.ValueChanged -= new EventHandler(Penalty_ValueChanged);
292    }
293    private void RegisterDistanceEvents() {
294      Distance.ValueChanged += new EventHandler(Distance_ValueChanged);
295    }
296    private void DeregisterDistanceEvents() {
297      Distance.ValueChanged -= new EventHandler(Distance_ValueChanged);
298    }
299
300    private void IntegerVector_ItemChanged(object sender, EventArgs<int> e) {
301      OnIntegerVectorChanged();
302    }
303    private void IntegerVector_Reset(object sender, EventArgs e) {
304      OnIntegerVectorChanged();
305    }
306    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
307      OnCoordinatesChanged();
308    }
309    private void Coordinates_Reset(object sender, EventArgs e) {
310      OnCoordinatesChanged();
311    }
312    private void StartingPoint_ValueChanged(object sender, EventArgs e) {
313      OnStartingPointChanged();
314    }
315    private void TerminalPoint_ValueChanged(object sender, EventArgs e) {
316      OnTerminalPointChanged();
317    }
318    private void Scores_ItemChanged(object sender, EventArgs<int> e) {
319      OnCoordinatesChanged();
320    }
321    private void Scores_Reset(object sender, EventArgs e) {
322      OnCoordinatesChanged();
323    }
324    private void Quality_ValueChanged(object sender, EventArgs e) {
325      OnQualityChanged();
326    }
327    private void Penalty_ValueChanged(object sender, EventArgs e) {
328      OnPenaltyChanged();
329    }
330    private void Distance_ValueChanged(object sender, EventArgs e) {
331      OnDistanceChanged();
332    }
333    #endregion
334  }
335}
Note: See TracBrowser for help on using the repository browser.