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 |
|
---|
145 | public VRPSolution() : base() { }
|
---|
146 |
|
---|
147 | public VRPSolution(DoubleMatrix coordinates, IVRPEncoding solution, DoubleValue quality,
|
---|
148 | DoubleValue distance, DoubleValue overload, DoubleValue tardiness, DoubleValue travelTime,
|
---|
149 | DoubleValue vehicleUtilization)
|
---|
150 | : base() {
|
---|
151 | this.coordinates = coordinates;
|
---|
152 | this.solution = solution;
|
---|
153 | this.quality = quality;
|
---|
154 | this.distance = distance;
|
---|
155 | this.overload = overload;
|
---|
156 | this.tardiness = tardiness;
|
---|
157 | this.travelTime = travelTime;
|
---|
158 | this.vehicleUtilization = vehicleUtilization;
|
---|
159 | Initialize();
|
---|
160 | }
|
---|
161 | [StorableConstructor]
|
---|
162 | private VRPSolution(bool deserializing) : base(deserializing) { }
|
---|
163 |
|
---|
164 | [StorableHook(HookType.AfterDeserialization)]
|
---|
165 | private void Initialize() {
|
---|
166 | if (coordinates != null) RegisterCoordinatesEvents();
|
---|
167 | if (solution != null) RegisterSolutionEvents();
|
---|
168 | if (quality != null) RegisterQualityEvents();
|
---|
169 | }
|
---|
170 |
|
---|
171 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
172 | VRPSolution clone = new VRPSolution();
|
---|
173 | cloner.RegisterClonedObject(this, clone);
|
---|
174 | clone.coordinates = (DoubleMatrix)cloner.Clone(coordinates);
|
---|
175 | clone.solution = (IVRPEncoding)cloner.Clone(solution);
|
---|
176 | clone.quality = (DoubleValue)cloner.Clone(quality);
|
---|
177 | clone.distance = (DoubleValue)cloner.Clone(distance);
|
---|
178 | clone.overload = (DoubleValue)cloner.Clone(overload);
|
---|
179 | clone.tardiness = (DoubleValue)cloner.Clone(tardiness);
|
---|
180 | clone.travelTime = (DoubleValue)cloner.Clone(travelTime);
|
---|
181 | clone.vehicleUtilization = (DoubleValue)cloner.Clone(vehicleUtilization);
|
---|
182 | clone.Initialize();
|
---|
183 | return clone;
|
---|
184 | }
|
---|
185 |
|
---|
186 | #region Events
|
---|
187 | public event EventHandler CoordinatesChanged;
|
---|
188 | private void OnCoordinatesChanged() {
|
---|
189 | var changed = CoordinatesChanged;
|
---|
190 | if (changed != null)
|
---|
191 | changed(this, EventArgs.Empty);
|
---|
192 | }
|
---|
193 | public event EventHandler SolutionChanged;
|
---|
194 | private void OnSolutionChanged() {
|
---|
195 | var changed = SolutionChanged;
|
---|
196 | if (changed != null)
|
---|
197 | changed(this, EventArgs.Empty);
|
---|
198 | }
|
---|
199 | public event EventHandler QualityChanged;
|
---|
200 | private void OnQualityChanged() {
|
---|
201 | var changed = QualityChanged;
|
---|
202 | if (changed != null)
|
---|
203 | changed(this, EventArgs.Empty);
|
---|
204 | }
|
---|
205 | public event EventHandler DistanceChanged;
|
---|
206 | private void OnDistanceChanged() {
|
---|
207 | var changed = DistanceChanged;
|
---|
208 | if (changed != null)
|
---|
209 | changed(this, EventArgs.Empty);
|
---|
210 | }
|
---|
211 | public event EventHandler OverloadChanged;
|
---|
212 | private void OnOverloadChanged() {
|
---|
213 | var changed = OverloadChanged;
|
---|
214 | if (changed != null)
|
---|
215 | changed(this, EventArgs.Empty);
|
---|
216 | }
|
---|
217 | public event EventHandler TardinessChanged;
|
---|
218 | private void OnTardinessChanged() {
|
---|
219 | var changed = TardinessChanged;
|
---|
220 | if (changed != null)
|
---|
221 | changed(this, EventArgs.Empty);
|
---|
222 | }
|
---|
223 | public event EventHandler TravelTimeChanged;
|
---|
224 | private void OnTravelTimeChanged() {
|
---|
225 | var changed = TravelTimeChanged;
|
---|
226 | if (changed != null)
|
---|
227 | changed(this, EventArgs.Empty);
|
---|
228 | }
|
---|
229 | public event EventHandler VehicleUtilizationChanged;
|
---|
230 | private void OnVehicleUtilizationChanged() {
|
---|
231 | var changed = VehicleUtilizationChanged;
|
---|
232 | if (changed != null)
|
---|
233 | changed(this, EventArgs.Empty);
|
---|
234 | }
|
---|
235 |
|
---|
236 | private void RegisterCoordinatesEvents() {
|
---|
237 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
238 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
239 | }
|
---|
240 | private void DeregisterCoordinatesEvents() {
|
---|
241 | Coordinates.ItemChanged -= new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
242 | Coordinates.Reset -= new EventHandler(Coordinates_Reset);
|
---|
243 | }
|
---|
244 | private void RegisterSolutionEvents() {
|
---|
245 | Solution.ToStringChanged += new EventHandler(Solution_ToStringChanged);
|
---|
246 | }
|
---|
247 | private void DeregisterSolutionEvents() {
|
---|
248 | Solution.ToStringChanged -= new EventHandler(Solution_ToStringChanged);
|
---|
249 | }
|
---|
250 | private void RegisterQualityEvents() {
|
---|
251 | Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
252 | }
|
---|
253 | private void DeregisterQualityEvents() {
|
---|
254 | Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
255 | }
|
---|
256 | private void RegisterDistanceEvents() {
|
---|
257 | Distance.ValueChanged += new EventHandler(Distance_ValueChanged);
|
---|
258 | }
|
---|
259 | private void DeregisterDistanceEvents() {
|
---|
260 | Distance.ValueChanged -= new EventHandler(Distance_ValueChanged);
|
---|
261 | }
|
---|
262 | private void RegisterOverloadEvents() {
|
---|
263 | Overload.ValueChanged += new EventHandler(Overload_ValueChanged);
|
---|
264 | }
|
---|
265 | private void DeregisterOverloadEvents() {
|
---|
266 | Overload.ValueChanged -= new EventHandler(Overload_ValueChanged);
|
---|
267 | }
|
---|
268 | private void RegisterTardinessEvents() {
|
---|
269 | Tardiness.ValueChanged += new EventHandler(Tardiness_ValueChanged);
|
---|
270 | }
|
---|
271 | private void DeregisterTardinessEvents() {
|
---|
272 | Tardiness.ValueChanged -= new EventHandler(Tardiness_ValueChanged);
|
---|
273 | }
|
---|
274 | private void RegisterTravelTimeEvents() {
|
---|
275 | TravelTime.ValueChanged += new EventHandler(TravelTime_ValueChanged);
|
---|
276 | }
|
---|
277 | private void DeregisterTravelTimeEvents() {
|
---|
278 | TravelTime.ValueChanged -= new EventHandler(TravelTime_ValueChanged);
|
---|
279 | }
|
---|
280 | private void RegisterVehicleUtilizationEvents() {
|
---|
281 | VehicleUtilization.ValueChanged += new EventHandler(VehicleUtilization_ValueChanged);
|
---|
282 | }
|
---|
283 | private void DeregisterVehicleUtilizationEvents() {
|
---|
284 | VehicleUtilization.ValueChanged -= new EventHandler(VehicleUtilization_ValueChanged);
|
---|
285 | }
|
---|
286 |
|
---|
287 | private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
288 | OnCoordinatesChanged();
|
---|
289 | }
|
---|
290 | private void Coordinates_Reset(object sender, EventArgs e) {
|
---|
291 | OnCoordinatesChanged();
|
---|
292 | }
|
---|
293 | private void Solution_ToStringChanged(object sender, EventArgs e) {
|
---|
294 | OnSolutionChanged();
|
---|
295 | }
|
---|
296 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
297 | OnQualityChanged();
|
---|
298 | }
|
---|
299 | private void Distance_ValueChanged(object sender, EventArgs e) {
|
---|
300 | OnDistanceChanged();
|
---|
301 | }
|
---|
302 | private void Overload_ValueChanged(object sender, EventArgs e) {
|
---|
303 | OnOverloadChanged();
|
---|
304 | }
|
---|
305 | private void Tardiness_ValueChanged(object sender, EventArgs e) {
|
---|
306 | OnTardinessChanged();
|
---|
307 | }
|
---|
308 | private void TravelTime_ValueChanged(object sender, EventArgs e) {
|
---|
309 | OnTravelTimeChanged();
|
---|
310 | }
|
---|
311 | private void VehicleUtilization_ValueChanged(object sender, EventArgs e) {
|
---|
312 | OnVehicleUtilizationChanged();
|
---|
313 | }
|
---|
314 | #endregion
|
---|
315 | }
|
---|
316 | }
|
---|