Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringSolution.cs @ 11327

Last change on this file since 11327 was 11327, checked in by pfleck, 10 years ago

#2208

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