Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveHiveEngine/HeuristicLab.Problems.VehicleRouting/3.3/VRPSolution.cs @ 7481

Last change on this file since 7481 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 13.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;
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 static new Image StaticItemImage {
37      get { return HeuristicLab.Common.Resources.VSImageLibrary.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    }
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    }
194
195    public VRPSolution() : base() { }
196
197    public VRPSolution(DoubleMatrix coordinates)
198      : base() {
199      this.coordinates = coordinates;
200    }
201
202    public VRPSolution(DoubleMatrix coordinates, IVRPEncoding solution, DoubleValue quality,
203      DoubleValue distance, DoubleValue overload, DoubleValue tardiness, DoubleValue travelTime,
204      DoubleValue vehicleUtilization, DoubleMatrix distanceMatrix, BoolValue useDistanceMatrix,
205      DoubleArray readyTime, DoubleArray dueTime, DoubleArray serviceTime)
206      : base() {
207      this.coordinates = coordinates;
208      this.solution = solution;
209      this.quality = quality;
210      this.distance = distance;
211      this.overload = overload;
212      this.tardiness = tardiness;
213      this.travelTime = travelTime;
214      this.vehicleUtilization = vehicleUtilization;
215      this.distanceMatrix = distanceMatrix;
216      this.useDistanceMatrix = useDistanceMatrix;
217      this.readyTime = readyTime;
218      this.dueTime = dueTime;
219      this.serviceTime = serviceTime;
220      Initialize();
221    }
222    [StorableConstructor]
223    private VRPSolution(bool deserializing) : base(deserializing) { }
224
225    private VRPSolution(VRPSolution original, Cloner cloner)
226      : base(original, cloner) {
227      coordinates = cloner.Clone(original.coordinates);
228      solution = cloner.Clone(original.solution);
229      quality = cloner.Clone(original.quality);
230      distance = cloner.Clone(original.distance);
231      overload = cloner.Clone(original.overload);
232      tardiness = cloner.Clone(original.tardiness);
233      travelTime = cloner.Clone(original.travelTime);
234      vehicleUtilization = cloner.Clone(original.vehicleUtilization);
235      distanceMatrix = cloner.Clone(original.distanceMatrix);
236      useDistanceMatrix = cloner.Clone(original.useDistanceMatrix);
237      readyTime = cloner.Clone(original.readyTime);
238      dueTime = cloner.Clone(original.dueTime);
239      serviceTime = cloner.Clone(original.serviceTime);
240      Initialize();
241    }
242
243    [StorableHook(HookType.AfterDeserialization)]
244    private void AfterDeserialization() {
245      Initialize();
246    }
247    private void Initialize() {
248      if (coordinates != null) RegisterCoordinatesEvents();
249      if (solution != null) RegisterSolutionEvents();
250      if (quality != null) RegisterQualityEvents();
251      if (distance != null) RegisterDistanceEvents();
252      if (overload != null) RegisterOverloadEvents();
253      if (tardiness != null) RegisterTardinessEvents();
254      if (travelTime != null) RegisterTravelTimeEvents();
255      if (vehicleUtilization != null) RegisterVehicleUtilizationEvents();
256    }
257
258    public override IDeepCloneable Clone(Cloner cloner) {
259      return new VRPSolution(this, cloner);
260    }
261
262    #region Events
263    public event EventHandler CoordinatesChanged;
264    private void OnCoordinatesChanged() {
265      var changed = CoordinatesChanged;
266      if (changed != null)
267        changed(this, EventArgs.Empty);
268    }
269    public event EventHandler SolutionChanged;
270    private void OnSolutionChanged() {
271      var changed = SolutionChanged;
272      if (changed != null)
273        changed(this, EventArgs.Empty);
274    }
275    public event EventHandler QualityChanged;
276    private void OnQualityChanged() {
277      var changed = QualityChanged;
278      if (changed != null)
279        changed(this, EventArgs.Empty);
280    }
281    public event EventHandler DistanceChanged;
282    private void OnDistanceChanged() {
283      var changed = DistanceChanged;
284      if (changed != null)
285        changed(this, EventArgs.Empty);
286    }
287    public event EventHandler OverloadChanged;
288    private void OnOverloadChanged() {
289      var changed = OverloadChanged;
290      if (changed != null)
291        changed(this, EventArgs.Empty);
292    }
293    public event EventHandler TardinessChanged;
294    private void OnTardinessChanged() {
295      var changed = TardinessChanged;
296      if (changed != null)
297        changed(this, EventArgs.Empty);
298    }
299    public event EventHandler TravelTimeChanged;
300    private void OnTravelTimeChanged() {
301      var changed = TravelTimeChanged;
302      if (changed != null)
303        changed(this, EventArgs.Empty);
304    }
305    public event EventHandler VehicleUtilizationChanged;
306    private void OnVehicleUtilizationChanged() {
307      var changed = VehicleUtilizationChanged;
308      if (changed != null)
309        changed(this, EventArgs.Empty);
310    }
311
312    private void RegisterCoordinatesEvents() {
313      Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
314      Coordinates.Reset += new EventHandler(Coordinates_Reset);
315    }
316    private void DeregisterCoordinatesEvents() {
317      Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
318      Coordinates.Reset -= new EventHandler(Coordinates_Reset);
319    }
320    private void RegisterSolutionEvents() {
321      Solution.ToStringChanged += new EventHandler(Solution_ToStringChanged);
322    }
323    private void DeregisterSolutionEvents() {
324      Solution.ToStringChanged -= new EventHandler(Solution_ToStringChanged);
325    }
326    private void RegisterQualityEvents() {
327      Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
328    }
329    private void DeregisterQualityEvents() {
330      Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
331    }
332    private void RegisterDistanceEvents() {
333      Distance.ValueChanged += new EventHandler(Distance_ValueChanged);
334    }
335    private void DeregisterDistanceEvents() {
336      Distance.ValueChanged -= new EventHandler(Distance_ValueChanged);
337    }
338    private void RegisterOverloadEvents() {
339      Overload.ValueChanged += new EventHandler(Overload_ValueChanged);
340    }
341    private void DeregisterOverloadEvents() {
342      Overload.ValueChanged -= new EventHandler(Overload_ValueChanged);
343    }
344    private void RegisterTardinessEvents() {
345      Tardiness.ValueChanged += new EventHandler(Tardiness_ValueChanged);
346    }
347    private void DeregisterTardinessEvents() {
348      Tardiness.ValueChanged -= new EventHandler(Tardiness_ValueChanged);
349    }
350    private void RegisterTravelTimeEvents() {
351      TravelTime.ValueChanged += new EventHandler(TravelTime_ValueChanged);
352    }
353    private void DeregisterTravelTimeEvents() {
354      TravelTime.ValueChanged -= new EventHandler(TravelTime_ValueChanged);
355    }
356    private void RegisterVehicleUtilizationEvents() {
357      VehicleUtilization.ValueChanged += new EventHandler(VehicleUtilization_ValueChanged);
358    }
359    private void DeregisterVehicleUtilizationEvents() {
360      VehicleUtilization.ValueChanged -= new EventHandler(VehicleUtilization_ValueChanged);
361    }
362
363    private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
364      OnCoordinatesChanged();
365    }
366    private void Coordinates_Reset(object sender, EventArgs e) {
367      OnCoordinatesChanged();
368    }
369    private void Solution_ToStringChanged(object sender, EventArgs e) {
370      OnSolutionChanged();
371    }
372    private void Quality_ValueChanged(object sender, EventArgs e) {
373      OnQualityChanged();
374    }
375    private void Distance_ValueChanged(object sender, EventArgs e) {
376      OnDistanceChanged();
377    }
378    private void Overload_ValueChanged(object sender, EventArgs e) {
379      OnOverloadChanged();
380    }
381    private void Tardiness_ValueChanged(object sender, EventArgs e) {
382      OnTardinessChanged();
383    }
384    private void TravelTime_ValueChanged(object sender, EventArgs e) {
385      OnTravelTimeChanged();
386    }
387    private void VehicleUtilization_ValueChanged(object sender, EventArgs e) {
388      OnVehicleUtilizationChanged();
389    }
390    #endregion
391  }
392}
Note: See TracBrowser for help on using the repository browser.