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