Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VRPSolution.cs @ 4185

Last change on this file since 4185 was 4185, checked in by svonolfe, 14 years ago

Improved VRP visualization (#1039)

File size: 13.3 KB
RevLine 
[3938]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.VehicleRouting {
30  /// <summary>
31  /// Represents a VRP solution which can be visualized in the GUI.
32  /// </summary>
33  [Item("VRPSolution", "Represents a VRP solution which can be visualized in the GUI.")]
34  [StorableClass]
35  public sealed class VRPSolution : Item {
36    public override Image ItemImage {
37      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Image; }
38    }
39
40    [Storable]
41    private DoubleMatrix coordinates;
42    public DoubleMatrix Coordinates {
43      get { return coordinates; }
44      set {
45        if (coordinates != value) {
46          if (coordinates != null) DeregisterCoordinatesEvents();
47          coordinates = value;
48          if (coordinates != null) RegisterCoordinatesEvents();
49          OnCoordinatesChanged();
50        }
51      }
52    }
53    [Storable]
54    private IVRPEncoding solution;
55    public IVRPEncoding Solution {
56      get { return solution; }
57      set {
58        if (solution != value) {
59          if (solution != null) DeregisterSolutionEvents();
60          solution = value;
61          if (solution != null) RegisterSolutionEvents();
62          OnSolutionChanged();
63        }
64      }
65    }
66    [Storable]
67    private DoubleValue quality;
68    public DoubleValue Quality {
69      get { return quality; }
70      set {
71        if (quality != value) {
72          if (quality != null) DeregisterQualityEvents();
73          quality = value;
74          if (quality != null) RegisterQualityEvents();
75          OnQualityChanged();
76        }
77      }
78    }
79    [Storable]
80    private DoubleValue distance;
81    public DoubleValue Distance {
82      get { return distance; }
83      set {
84        if (distance != value) {
85          if (distance != null) DeregisterDistanceEvents();
86          distance = value;
87          if (distance != null) RegisterDistanceEvents();
88          OnDistanceChanged();
89        }
90      }
91    }
92    [Storable]
93    private DoubleValue overload;
94    public DoubleValue Overload {
95      get { return overload; }
96      set {
97        if (overload != value) {
98          if (overload != null) DeregisterOverloadEvents();
99          overload = value;
100          if (overload != null) RegisterOverloadEvents();
101          OnOverloadChanged();
102        }
103      }
104    }
105    [Storable]
106    private DoubleValue tardiness;
107    public DoubleValue Tardiness {
108      get { return tardiness; }
109      set {
110        if (tardiness != value) {
111          if (tardiness != null) DeregisterTardinessEvents();
112          tardiness = value;
113          if (tardiness != null) RegisterTardinessEvents();
114          OnTardinessChanged();
115        }
116      }
117    }
118    [Storable]
119    private DoubleValue travelTime;
120    public DoubleValue TravelTime {
121      get { return travelTime; }
122      set {
123        if (travelTime != value) {
124          if (travelTime != null) DeregisterTravelTimeEvents();
125          travelTime = value;
126          if (travelTime != null) RegisterTravelTimeEvents();
127          OnTravelTimeChanged();
128        }
129      }
130    }
131    [Storable]
132    private DoubleValue vehicleUtilization;
133    public DoubleValue VehicleUtilization {
134      get { return vehicleUtilization; }
135      set {
136        if (vehicleUtilization != value) {
137          if (vehicleUtilization != null) DeregisterVehicleUtilizationEvents();
138          vehicleUtilization = value;
139          if (vehicleUtilization != null) RegisterVehicleUtilizationEvents();
140          OnVehicleUtilizationChanged();
141        }
142      }
143    }
[4015]144    [Storable]
145    private DoubleMatrix distanceMatrix;
146    public DoubleMatrix DistanceMatrix {
147      get { return distanceMatrix; }
148      set {
149        if (distanceMatrix != value) {
150          distanceMatrix = value;
151        }
152      }
153    }
154    [Storable]
155    private BoolValue useDistanceMatrix;
156    public BoolValue UseDistanceMatrix {
157      get { return useDistanceMatrix; }
158      set {
159        if (useDistanceMatrix != value) {
160          useDistanceMatrix = value;
161        }
162      }
163    }
164    [Storable]
165    private DoubleArray readyTime;
166    public DoubleArray ReadyTime {
167      get { return readyTime; }
168      set {
169        if (readyTime != value) {
170          readyTime = value;
171        }
172      }
173    }
174    [Storable]
175    private DoubleArray dueTime;
176    public DoubleArray DueTime {
177      get { return dueTime; }
178      set {
179        if (dueTime != value) {
180          dueTime = value;
181        }
182      }
183    }
184    [Storable]
185    private DoubleArray serviceTime;
186    public DoubleArray ServiceTime {
187      get { return serviceTime; }
188      set {
189        if (serviceTime != value) {
190          serviceTime = value;
191        }
192      }
193    }
[3938]194
195    public VRPSolution() : base() { }
196
[4185]197    public VRPSolution(DoubleMatrix coordinates): base() {
198      this.coordinates = coordinates;
199    }
200
[3938]201    public VRPSolution(DoubleMatrix coordinates, IVRPEncoding solution, DoubleValue quality,
202      DoubleValue distance, DoubleValue overload, DoubleValue tardiness, DoubleValue travelTime,
[4015]203      DoubleValue vehicleUtilization, DoubleMatrix distanceMatrix, BoolValue useDistanceMatrix,
204      DoubleArray readyTime, DoubleArray dueTime, DoubleArray serviceTime)
[3938]205      : base() {
206      this.coordinates = coordinates;
207      this.solution = solution;
208      this.quality = quality;
209      this.distance = distance;
210      this.overload = overload;
211      this.tardiness = tardiness;
212      this.travelTime = travelTime;
213      this.vehicleUtilization = vehicleUtilization;
[4015]214      this.distanceMatrix = distanceMatrix;
215      this.useDistanceMatrix = useDistanceMatrix;
216      this.readyTime = readyTime;
217      this.dueTime = dueTime;
218      this.serviceTime = serviceTime;
[3938]219      Initialize();
220    }
221    [StorableConstructor]
222    private VRPSolution(bool deserializing) : base(deserializing) { }
223
224    [StorableHook(HookType.AfterDeserialization)]
225    private void Initialize() {
226      if (coordinates != null) RegisterCoordinatesEvents();
227      if (solution != null) RegisterSolutionEvents();
228      if (quality != null) RegisterQualityEvents();
[4015]229      if (distance != null) RegisterDistanceEvents();
230      if (overload != null) RegisterOverloadEvents();
231      if (tardiness != null) RegisterTardinessEvents();
232      if (travelTime != null) RegisterTravelTimeEvents();
233      if (vehicleUtilization != null) RegisterVehicleUtilizationEvents();
[3938]234    }
235
236    public override IDeepCloneable Clone(Cloner cloner) {
237      VRPSolution clone = new VRPSolution();
238      cloner.RegisterClonedObject(this, clone);
239      clone.coordinates = (DoubleMatrix)cloner.Clone(coordinates);
240      clone.solution = (IVRPEncoding)cloner.Clone(solution);
241      clone.quality = (DoubleValue)cloner.Clone(quality);
242      clone.distance = (DoubleValue)cloner.Clone(distance);
243      clone.overload = (DoubleValue)cloner.Clone(overload);
244      clone.tardiness = (DoubleValue)cloner.Clone(tardiness);
245      clone.travelTime = (DoubleValue)cloner.Clone(travelTime);
246      clone.vehicleUtilization = (DoubleValue)cloner.Clone(vehicleUtilization);
[4015]247      clone.distanceMatrix = (DoubleMatrix)cloner.Clone(distanceMatrix);
248      clone.useDistanceMatrix = (BoolValue)cloner.Clone(useDistanceMatrix);
249      clone.readyTime = (DoubleArray)cloner.Clone(readyTime);
250      clone.dueTime = (DoubleArray)cloner.Clone(dueTime);
251      clone.serviceTime = (DoubleArray)cloner.Clone(serviceTime);
[3938]252      clone.Initialize();
253      return clone;
254    }
255
256    #region Events
257    public event EventHandler CoordinatesChanged;
258    private void OnCoordinatesChanged() {
259      var changed = CoordinatesChanged;
260      if (changed != null)
261        changed(this, EventArgs.Empty);
262    }
263    public event EventHandler SolutionChanged;
264    private void OnSolutionChanged() {
265      var changed = SolutionChanged;
266      if (changed != null)
267        changed(this, EventArgs.Empty);
268    }
269    public event EventHandler QualityChanged;
270    private void OnQualityChanged() {
271      var changed = QualityChanged;
272      if (changed != null)
273        changed(this, EventArgs.Empty);
274    }
275    public event EventHandler DistanceChanged;
276    private void OnDistanceChanged() {
277      var changed = DistanceChanged;
278      if (changed != null)
279        changed(this, EventArgs.Empty);
280    }
281    public event EventHandler OverloadChanged;
282    private void OnOverloadChanged() {
283      var changed = OverloadChanged;
284      if (changed != null)
285        changed(this, EventArgs.Empty);
286    }
287    public event EventHandler TardinessChanged;
288    private void OnTardinessChanged() {
289      var changed = TardinessChanged;
290      if (changed != null)
291        changed(this, EventArgs.Empty);
292    }
293    public event EventHandler TravelTimeChanged;
294    private void OnTravelTimeChanged() {
295      var changed = TravelTimeChanged;
296      if (changed != null)
297        changed(this, EventArgs.Empty);
298    }
299    public event EventHandler VehicleUtilizationChanged;
300    private void OnVehicleUtilizationChanged() {
301      var changed = VehicleUtilizationChanged;
302      if (changed != null)
303        changed(this, EventArgs.Empty);
304    }
305
306    private void RegisterCoordinatesEvents() {
307      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
308      Coordinates.Reset += new EventHandler(Coordinates_Reset);
309    }
310    private void DeregisterCoordinatesEvents() {
311      Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
312      Coordinates.Reset -= new EventHandler(Coordinates_Reset);
313    }
314    private void RegisterSolutionEvents() {
315      Solution.ToStringChanged += new EventHandler(Solution_ToStringChanged);
316    }
317    private void DeregisterSolutionEvents() {
318      Solution.ToStringChanged -= new EventHandler(Solution_ToStringChanged);
319    }
320    private void RegisterQualityEvents() {
321      Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
322    }
323    private void DeregisterQualityEvents() {
324      Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
325    }
326    private void RegisterDistanceEvents() {
327      Distance.ValueChanged += new EventHandler(Distance_ValueChanged);
328    }
329    private void DeregisterDistanceEvents() {
330      Distance.ValueChanged -= new EventHandler(Distance_ValueChanged);
331    }
332    private void RegisterOverloadEvents() {
333      Overload.ValueChanged += new EventHandler(Overload_ValueChanged);
334    }
335    private void DeregisterOverloadEvents() {
336      Overload.ValueChanged -= new EventHandler(Overload_ValueChanged);
337    }
338    private void RegisterTardinessEvents() {
339      Tardiness.ValueChanged += new EventHandler(Tardiness_ValueChanged);
340    }
341    private void DeregisterTardinessEvents() {
342      Tardiness.ValueChanged -= new EventHandler(Tardiness_ValueChanged);
343    }
344    private void RegisterTravelTimeEvents() {
345      TravelTime.ValueChanged += new EventHandler(TravelTime_ValueChanged);
346    }
347    private void DeregisterTravelTimeEvents() {
348      TravelTime.ValueChanged -= new EventHandler(TravelTime_ValueChanged);
349    }
350    private void RegisterVehicleUtilizationEvents() {
351      VehicleUtilization.ValueChanged += new EventHandler(VehicleUtilization_ValueChanged);
352    }
353    private void DeregisterVehicleUtilizationEvents() {
354      VehicleUtilization.ValueChanged -= new EventHandler(VehicleUtilization_ValueChanged);
355    }
356
357    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
358      OnCoordinatesChanged();
359    }
360    private void Coordinates_Reset(object sender, EventArgs e) {
361      OnCoordinatesChanged();
362    }
363    private void Solution_ToStringChanged(object sender, EventArgs e) {
364      OnSolutionChanged();
365    }
366    private void Quality_ValueChanged(object sender, EventArgs e) {
367      OnQualityChanged();
368    }
369    private void Distance_ValueChanged(object sender, EventArgs e) {
370      OnDistanceChanged();
371    }
372    private void Overload_ValueChanged(object sender, EventArgs e) {
373      OnOverloadChanged();
374    }
375    private void Tardiness_ValueChanged(object sender, EventArgs e) {
376      OnTardinessChanged();
377    }
378    private void TravelTime_ValueChanged(object sender, EventArgs e) {
379      OnTravelTimeChanged();
380    }
381    private void VehicleUtilization_ValueChanged(object sender, EventArgs e) {
382      OnVehicleUtilizationChanged();
383    }
384    #endregion
385  }
386}
Note: See TracBrowser for help on using the repository browser.