1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 | using HeuristicLab.PluginInfrastructure;
|
---|
32 | using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
|
---|
33 | using HeuristicLab.Problems.VehicleRouting.Encodings.General;
|
---|
34 | using HeuristicLab.Problems.VehicleRouting.Encodings.Prins;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
37 | [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")]
|
---|
38 | [Creatable("Problems")]
|
---|
39 | [StorableClass]
|
---|
40 | public sealed class VehicleRoutingProblem : SingleObjectiveHeuristicOptimizationProblem<IVRPEvaluator, IVRPCreator>, IStorableContent {
|
---|
41 | public string Filename { get; set; }
|
---|
42 |
|
---|
43 | #region Parameter Properties
|
---|
44 | public ValueParameter<DoubleMatrix> CoordinatesParameter {
|
---|
45 | get { return (ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
|
---|
46 | }
|
---|
47 | public OptionalValueParameter<DoubleMatrix> DistanceMatrixParameter {
|
---|
48 | get { return (OptionalValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; }
|
---|
49 | }
|
---|
50 | public ValueParameter<BoolValue> UseDistanceMatrixParameter {
|
---|
51 | get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
|
---|
52 | }
|
---|
53 | public ValueParameter<IntValue> VehiclesParameter {
|
---|
54 | get { return (ValueParameter<IntValue>)Parameters["Vehicles"]; }
|
---|
55 | }
|
---|
56 | public ValueParameter<DoubleValue> CapacityParameter {
|
---|
57 | get { return (ValueParameter<DoubleValue>)Parameters["Capacity"]; }
|
---|
58 | }
|
---|
59 | public ValueParameter<DoubleArray> DemandParameter {
|
---|
60 | get { return (ValueParameter<DoubleArray>)Parameters["Demand"]; }
|
---|
61 | }
|
---|
62 | public ValueParameter<DoubleArray> ReadyTimeParameter {
|
---|
63 | get { return (ValueParameter<DoubleArray>)Parameters["ReadyTime"]; }
|
---|
64 | }
|
---|
65 | public ValueParameter<DoubleArray> DueTimeParameter {
|
---|
66 | get { return (ValueParameter<DoubleArray>)Parameters["DueTime"]; }
|
---|
67 | }
|
---|
68 | public ValueParameter<DoubleArray> ServiceTimeParameter {
|
---|
69 | get { return (ValueParameter<DoubleArray>)Parameters["ServiceTime"]; }
|
---|
70 | }
|
---|
71 | public IValueParameter<DoubleValue> FleetUsageFactorParameter {
|
---|
72 | get { return (IValueParameter<DoubleValue>)Parameters["EvalFleetUsageFactor"]; }
|
---|
73 | }
|
---|
74 | public IValueParameter<DoubleValue> TimeFactorParameter {
|
---|
75 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
|
---|
76 | }
|
---|
77 | public IValueParameter<DoubleValue> DistanceFactorParameter {
|
---|
78 | get { return (IValueParameter<DoubleValue>)Parameters["EvalDistanceFactor"]; }
|
---|
79 | }
|
---|
80 | public IValueParameter<DoubleValue> OverloadPenaltyParameter {
|
---|
81 | get { return (IValueParameter<DoubleValue>)Parameters["EvalOverloadPenalty"]; }
|
---|
82 | }
|
---|
83 | public IValueParameter<DoubleValue> TardinessPenaltyParameter {
|
---|
84 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
|
---|
85 | }
|
---|
86 | public OptionalValueParameter<IVRPEncoding> BestKnownSolutionParameter {
|
---|
87 | get { return (OptionalValueParameter<IVRPEncoding>)Parameters["BestKnownSolution"]; }
|
---|
88 | }
|
---|
89 | #endregion
|
---|
90 |
|
---|
91 | #region Properties
|
---|
92 | public DoubleMatrix Coordinates {
|
---|
93 | get { return CoordinatesParameter.Value; }
|
---|
94 | set { CoordinatesParameter.Value = value; }
|
---|
95 | }
|
---|
96 | public DoubleMatrix DistanceMatrix {
|
---|
97 | get { return DistanceMatrixParameter.Value; }
|
---|
98 | set { DistanceMatrixParameter.Value = value; }
|
---|
99 | }
|
---|
100 | public BoolValue UseDistanceMatrix {
|
---|
101 | get { return UseDistanceMatrixParameter.Value; }
|
---|
102 | set { UseDistanceMatrixParameter.Value = value; }
|
---|
103 | }
|
---|
104 | public IntValue Vehicles {
|
---|
105 | get { return VehiclesParameter.Value; }
|
---|
106 | set { VehiclesParameter.Value = value; }
|
---|
107 | }
|
---|
108 | public DoubleValue Capacity {
|
---|
109 | get { return CapacityParameter.Value; }
|
---|
110 | set { CapacityParameter.Value = value; }
|
---|
111 | }
|
---|
112 | public DoubleArray Demand {
|
---|
113 | get { return DemandParameter.Value; }
|
---|
114 | set { DemandParameter.Value = value; }
|
---|
115 | }
|
---|
116 | public DoubleArray ReadyTime {
|
---|
117 | get { return ReadyTimeParameter.Value; }
|
---|
118 | set { ReadyTimeParameter.Value = value; }
|
---|
119 | }
|
---|
120 | public DoubleArray DueTime {
|
---|
121 | get { return DueTimeParameter.Value; }
|
---|
122 | set { DueTimeParameter.Value = value; }
|
---|
123 | }
|
---|
124 | public DoubleArray ServiceTime {
|
---|
125 | get { return ServiceTimeParameter.Value; }
|
---|
126 | set { ServiceTimeParameter.Value = value; }
|
---|
127 | }
|
---|
128 | public IVRPEncoding BestKnownSolution {
|
---|
129 | get { return BestKnownSolutionParameter.Value; }
|
---|
130 | set { BestKnownSolutionParameter.Value = value; }
|
---|
131 | }
|
---|
132 | private BestVRPSolutionAnalyzer BestVRPSolutionAnalyzer {
|
---|
133 | get { return Operators.OfType<BestVRPSolutionAnalyzer>().FirstOrDefault(); }
|
---|
134 | }
|
---|
135 | private BestAverageWorstVRPToursAnalyzer BestAverageWorstVRPToursAnalyzer {
|
---|
136 | get { return Operators.OfType<BestAverageWorstVRPToursAnalyzer>().FirstOrDefault(); }
|
---|
137 | }
|
---|
138 | #endregion
|
---|
139 |
|
---|
140 | // BackwardsCompatibility3.3
|
---|
141 | #region Backwards compatible code, remove with 3.4
|
---|
142 | [Obsolete]
|
---|
143 | [Storable(Name = "operators")]
|
---|
144 | private IEnumerable<IOperator> oldOperators {
|
---|
145 | get { return null; }
|
---|
146 | set {
|
---|
147 | if (value != null && value.Any())
|
---|
148 | Operators.AddRange(value);
|
---|
149 | }
|
---|
150 | }
|
---|
151 | #endregion
|
---|
152 |
|
---|
153 | [StorableConstructor]
|
---|
154 | private VehicleRoutingProblem(bool deserializing) : base(deserializing) { }
|
---|
155 | private VehicleRoutingProblem(VehicleRoutingProblem original, Cloner cloner)
|
---|
156 | : base(original, cloner) {
|
---|
157 | AttachEventHandlers();
|
---|
158 | }
|
---|
159 | public VehicleRoutingProblem()
|
---|
160 | : base(new VRPEvaluator(), new RandomCreator()) {
|
---|
161 | Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrix()));
|
---|
162 | Parameters.Add(new OptionalValueParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
|
---|
163 | Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true)));
|
---|
164 | Parameters.Add(new ValueParameter<IntValue>("Vehicles", "The number of vehicles.", new IntValue(0)));
|
---|
165 | Parameters.Add(new ValueParameter<DoubleValue>("Capacity", "The capacity of each vehicle.", new DoubleValue(0)));
|
---|
166 | Parameters.Add(new ValueParameter<DoubleArray>("Demand", "The demand of each customer.", new DoubleArray()));
|
---|
167 | Parameters.Add(new ValueParameter<DoubleArray>("ReadyTime", "The ready time of each customer.", new DoubleArray()));
|
---|
168 | Parameters.Add(new ValueParameter<DoubleArray>("DueTime", "The due time of each customer.", new DoubleArray()));
|
---|
169 | Parameters.Add(new ValueParameter<DoubleArray>("ServiceTime", "The service time of each customer.", new DoubleArray()));
|
---|
170 | Parameters.Add(new OptionalValueParameter<IVRPEncoding>("BestKnownSolution", "The best known solution of this VRP instance."));
|
---|
171 | Parameters.Add(new ValueParameter<DoubleValue>("EvalFleetUsageFactor", "The fleet usage factor considered in the evaluation.", new DoubleValue(100)));
|
---|
172 | Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
|
---|
173 | Parameters.Add(new ValueParameter<DoubleValue>("EvalDistanceFactor", "The distance factor considered in the evaluation.", new DoubleValue(1)));
|
---|
174 | Parameters.Add(new ValueParameter<DoubleValue>("EvalOverloadPenalty", "The overload penalty considered in the evaluation.", new DoubleValue(100)));
|
---|
175 | Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
|
---|
176 |
|
---|
177 | Maximization.Value = false;
|
---|
178 | MaximizationParameter.Hidden = true;
|
---|
179 |
|
---|
180 | SolutionCreator.VRPToursParameter.ActualName = "VRPTours";
|
---|
181 | Evaluator.QualityParameter.ActualName = "VRPQuality";
|
---|
182 |
|
---|
183 | InitializeRandomVRPInstance();
|
---|
184 |
|
---|
185 | ParameterizeSolutionCreator();
|
---|
186 | ParameterizeEvaluator();
|
---|
187 |
|
---|
188 | InitializeOperators();
|
---|
189 | AttachEventHandlers();
|
---|
190 | }
|
---|
191 |
|
---|
192 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
193 | return new VehicleRoutingProblem(this, cloner);
|
---|
194 | }
|
---|
195 |
|
---|
196 | #region Events
|
---|
197 | protected override void OnSolutionCreatorChanged() {
|
---|
198 | base.OnSolutionCreatorChanged();
|
---|
199 | ParameterizeSolutionCreator();
|
---|
200 | ParameterizeEvaluator();
|
---|
201 | ParameterizeAnalyzer();
|
---|
202 | ParameterizeOperators();
|
---|
203 | }
|
---|
204 | protected override void OnEvaluatorChanged() {
|
---|
205 | base.OnEvaluatorChanged();
|
---|
206 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
207 | ParameterizeEvaluator();
|
---|
208 | UpdateMoveEvaluators();
|
---|
209 | ParameterizeAnalyzer();
|
---|
210 | }
|
---|
211 | private void VehiclesValue_ValueChanged(object sender, EventArgs e) {
|
---|
212 | ParameterizeSolutionCreator();
|
---|
213 | }
|
---|
214 | private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
215 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
216 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
217 | ParameterizeSolutionCreator();
|
---|
218 | ClearDistanceMatrix();
|
---|
219 |
|
---|
220 | BestKnownSolution = null;
|
---|
221 | }
|
---|
222 | private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
223 | ClearDistanceMatrix();
|
---|
224 |
|
---|
225 | BestKnownSolution = null;
|
---|
226 | }
|
---|
227 | private void Coordinates_Reset(object sender, EventArgs e) {
|
---|
228 | ParameterizeSolutionCreator();
|
---|
229 | ClearDistanceMatrix();
|
---|
230 |
|
---|
231 | BestKnownSolution = null;
|
---|
232 | }
|
---|
233 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
234 | ParameterizeAnalyzer();
|
---|
235 | }
|
---|
236 |
|
---|
237 | void DistanceFactor_ValueChanged(object sender, EventArgs e) {
|
---|
238 | DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactorValue_ValueChanged);
|
---|
239 | EvalBestKnownSolution();
|
---|
240 | }
|
---|
241 | void DistanceFactorValue_ValueChanged(object sender, EventArgs e) {
|
---|
242 | EvalBestKnownSolution();
|
---|
243 | }
|
---|
244 | void FleetUsageFactor_ValueChanged(object sender, EventArgs e) {
|
---|
245 | FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactorValue_ValueChanged);
|
---|
246 | EvalBestKnownSolution();
|
---|
247 | }
|
---|
248 | void FleetUsageFactorValue_ValueChanged(object sender, EventArgs e) {
|
---|
249 | EvalBestKnownSolution();
|
---|
250 | }
|
---|
251 | void OverloadPenalty_ValueChanged(object sender, EventArgs e) {
|
---|
252 | OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenaltyValue_ValueChanged);
|
---|
253 | EvalBestKnownSolution();
|
---|
254 | }
|
---|
255 | void OverloadPenaltyValue_ValueChanged(object sender, EventArgs e) {
|
---|
256 | EvalBestKnownSolution();
|
---|
257 | }
|
---|
258 | void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
|
---|
259 | TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenaltyValue_ValueChanged);
|
---|
260 | EvalBestKnownSolution();
|
---|
261 | }
|
---|
262 | void TardinessPenaltyValue_ValueChanged(object sender, EventArgs e) {
|
---|
263 | EvalBestKnownSolution();
|
---|
264 | }
|
---|
265 | void TimeFactor_ValueChanged(object sender, EventArgs e) {
|
---|
266 | TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactorValue_ValueChanged);
|
---|
267 | EvalBestKnownSolution();
|
---|
268 | }
|
---|
269 | void TimeFactorValue_ValueChanged(object sender, EventArgs e) {
|
---|
270 | EvalBestKnownSolution();
|
---|
271 | }
|
---|
272 | void DistanceMatrixParameter_ValueChanged(object sender, EventArgs e) {
|
---|
273 | if (DistanceMatrix != null) {
|
---|
274 | DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged);
|
---|
275 | DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset);
|
---|
276 | }
|
---|
277 | EvalBestKnownSolution();
|
---|
278 | }
|
---|
279 | void DistanceMatrix_Reset(object sender, EventArgs e) {
|
---|
280 | EvalBestKnownSolution();
|
---|
281 | }
|
---|
282 | void DistanceMatrix_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
283 | EvalBestKnownSolution();
|
---|
284 | }
|
---|
285 | void UseDistanceMatrixParameter_ValueChanged(object sender, EventArgs e) {
|
---|
286 | UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
|
---|
287 | EvalBestKnownSolution();
|
---|
288 | }
|
---|
289 | void UseDistanceMatrix_ValueChanged(object sender, EventArgs e) {
|
---|
290 | EvalBestKnownSolution();
|
---|
291 | }
|
---|
292 | void CapacityParameter_ValueChanged(object sender, EventArgs e) {
|
---|
293 | Capacity.ValueChanged += new EventHandler(Capacity_ValueChanged);
|
---|
294 | BestKnownSolution = null;
|
---|
295 | }
|
---|
296 | void Capacity_ValueChanged(object sender, EventArgs e) {
|
---|
297 | BestKnownSolution = null;
|
---|
298 | }
|
---|
299 | void DemandParameter_ValueChanged(object sender, EventArgs e) {
|
---|
300 | Demand.ItemChanged += new EventHandler<EventArgs<int>>(Demand_ItemChanged);
|
---|
301 | Demand.Reset += new EventHandler(Demand_Reset);
|
---|
302 | BestKnownSolution = null;
|
---|
303 | }
|
---|
304 | void Demand_Reset(object sender, EventArgs e) {
|
---|
305 | BestKnownSolution = null;
|
---|
306 | }
|
---|
307 | void Demand_ItemChanged(object sender, EventArgs<int> e) {
|
---|
308 | BestKnownSolution = null;
|
---|
309 | }
|
---|
310 | void DueTimeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
311 | DueTime.ItemChanged += new EventHandler<EventArgs<int>>(DueTime_ItemChanged);
|
---|
312 | DueTime.Reset += new EventHandler(DueTime_Reset);
|
---|
313 | BestKnownSolution = null;
|
---|
314 | }
|
---|
315 | void DueTime_Reset(object sender, EventArgs e) {
|
---|
316 | BestKnownSolution = null;
|
---|
317 | }
|
---|
318 | void DueTime_ItemChanged(object sender, EventArgs<int> e) {
|
---|
319 | BestKnownSolution = null;
|
---|
320 | }
|
---|
321 | void ReadyTimeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
322 | ReadyTime.ItemChanged += new EventHandler<EventArgs<int>>(ReadyTime_ItemChanged);
|
---|
323 | ReadyTime.Reset += new EventHandler(ReadyTime_Reset);
|
---|
324 | BestKnownSolution = null;
|
---|
325 | }
|
---|
326 | void ReadyTime_Reset(object sender, EventArgs e) {
|
---|
327 | BestKnownSolution = null;
|
---|
328 | }
|
---|
329 | void ReadyTime_ItemChanged(object sender, EventArgs<int> e) {
|
---|
330 | BestKnownSolution = null;
|
---|
331 | }
|
---|
332 | void ServiceTimeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
333 | ServiceTime.ItemChanged += new EventHandler<EventArgs<int>>(ServiceTime_ItemChanged);
|
---|
334 | ServiceTime.Reset += new EventHandler(ServiceTime_Reset);
|
---|
335 | BestKnownSolution = null;
|
---|
336 | }
|
---|
337 | void ServiceTime_Reset(object sender, EventArgs e) {
|
---|
338 | BestKnownSolution = null;
|
---|
339 | }
|
---|
340 | void ServiceTime_ItemChanged(object sender, EventArgs<int> e) {
|
---|
341 | BestKnownSolution = null;
|
---|
342 | }
|
---|
343 | void VehiclesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
344 | Vehicles.ValueChanged += new EventHandler(Vehicles_ValueChanged);
|
---|
345 | BestKnownSolution = null;
|
---|
346 | }
|
---|
347 | void Vehicles_ValueChanged(object sender, EventArgs e) {
|
---|
348 | BestKnownSolution = null;
|
---|
349 | }
|
---|
350 | void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
|
---|
351 | EvalBestKnownSolution();
|
---|
352 | }
|
---|
353 | #endregion
|
---|
354 |
|
---|
355 | #region Helpers
|
---|
356 | [StorableHook(HookType.AfterDeserialization)]
|
---|
357 | private void AfterDeserializationHook() {
|
---|
358 | #region Backwards Compatibility
|
---|
359 | if (!Parameters.ContainsKey("BestKnownSolution")) {
|
---|
360 | Parameters.Add(new OptionalValueParameter<IVRPEncoding>("BestKnownSolution", "The best known solution of this TSP instance."));
|
---|
361 | }
|
---|
362 | #endregion
|
---|
363 |
|
---|
364 | AttachEventHandlers();
|
---|
365 | }
|
---|
366 |
|
---|
367 | private void AttachEventHandlers() {
|
---|
368 | CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
|
---|
369 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
370 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
371 |
|
---|
372 | Vehicles.ValueChanged += new EventHandler(VehiclesValue_ValueChanged);
|
---|
373 |
|
---|
374 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
375 |
|
---|
376 | DistanceFactorParameter.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
|
---|
377 | DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactorValue_ValueChanged);
|
---|
378 | FleetUsageFactorParameter.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged);
|
---|
379 | FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactorValue_ValueChanged);
|
---|
380 | OverloadPenaltyParameter.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
|
---|
381 | OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenaltyValue_ValueChanged);
|
---|
382 | TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
|
---|
383 | TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenaltyValue_ValueChanged);
|
---|
384 | TimeFactorParameter.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
|
---|
385 | TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactorValue_ValueChanged);
|
---|
386 |
|
---|
387 | DistanceMatrixParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
|
---|
388 | UseDistanceMatrixParameter.ValueChanged += new EventHandler(UseDistanceMatrixParameter_ValueChanged);
|
---|
389 | UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
|
---|
390 |
|
---|
391 | CapacityParameter.ValueChanged += new EventHandler(CapacityParameter_ValueChanged);
|
---|
392 | Capacity.ValueChanged += new EventHandler(Capacity_ValueChanged);
|
---|
393 | DemandParameter.ValueChanged += new EventHandler(DemandParameter_ValueChanged);
|
---|
394 | Demand.ItemChanged += new EventHandler<EventArgs<int>>(Demand_ItemChanged);
|
---|
395 | Demand.Reset += new EventHandler(Demand_Reset);
|
---|
396 | DueTimeParameter.ValueChanged += new EventHandler(DueTimeParameter_ValueChanged);
|
---|
397 | DueTime.ItemChanged += new EventHandler<EventArgs<int>>(DueTime_ItemChanged);
|
---|
398 | DueTime.Reset += new EventHandler(DueTime_Reset);
|
---|
399 | ReadyTimeParameter.ValueChanged += new EventHandler(ReadyTimeParameter_ValueChanged);
|
---|
400 | ReadyTime.ItemChanged += new EventHandler<EventArgs<int>>(ReadyTime_ItemChanged);
|
---|
401 | ReadyTime.Reset += new EventHandler(ReadyTime_Reset);
|
---|
402 | ServiceTimeParameter.ValueChanged += new EventHandler(ServiceTimeParameter_ValueChanged);
|
---|
403 | ServiceTime.ItemChanged += new EventHandler<EventArgs<int>>(ServiceTime_ItemChanged);
|
---|
404 | ServiceTime.Reset += new EventHandler(ServiceTime_Reset);
|
---|
405 | VehiclesParameter.ValueChanged += new EventHandler(VehiclesParameter_ValueChanged);
|
---|
406 | Vehicles.ValueChanged += new EventHandler(Vehicles_ValueChanged);
|
---|
407 |
|
---|
408 | BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
|
---|
409 | }
|
---|
410 |
|
---|
411 | private void InitializeOperators() {
|
---|
412 | Operators.Add(new BestVRPSolutionAnalyzer());
|
---|
413 | Operators.Add(new BestAverageWorstVRPToursAnalyzer());
|
---|
414 | ParameterizeAnalyzer();
|
---|
415 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IVRPOperator>().Cast<IOperator>().OrderBy(op => op.Name));
|
---|
416 | ParameterizeOperators();
|
---|
417 | UpdateMoveEvaluators();
|
---|
418 | }
|
---|
419 | private void UpdateMoveEvaluators() {
|
---|
420 | ParameterizeOperators();
|
---|
421 | OnOperatorsChanged();
|
---|
422 | }
|
---|
423 | private void ParameterizeSolutionCreator() {
|
---|
424 | SolutionCreator.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
425 | SolutionCreator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
426 | Evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
427 | Evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
428 | SolutionCreator.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
429 | SolutionCreator.DemandParameter.ActualName = DemandParameter.Name;
|
---|
430 | SolutionCreator.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
431 | SolutionCreator.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
432 | SolutionCreator.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
433 | }
|
---|
434 | private void ParameterizeEvaluator() {
|
---|
435 | Evaluator.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
436 | Evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
437 | Evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
438 | Evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
439 | Evaluator.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
440 | Evaluator.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
441 | Evaluator.DemandParameter.ActualName = DemandParameter.Name;
|
---|
442 | Evaluator.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
443 | Evaluator.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
444 | Evaluator.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
445 | Evaluator.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
|
---|
446 | Evaluator.TimeFactor.ActualName = TimeFactorParameter.Name;
|
---|
447 | Evaluator.DistanceFactor.ActualName = DistanceFactorParameter.Name;
|
---|
448 | Evaluator.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
|
---|
449 | Evaluator.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
|
---|
450 | }
|
---|
451 | private void ParameterizeAnalyzer() {
|
---|
452 | BestVRPSolutionAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
453 | BestVRPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
454 | BestVRPSolutionAnalyzer.DistanceParameter.ActualName = Evaluator.DistanceParameter.ActualName;
|
---|
455 | BestVRPSolutionAnalyzer.OverloadParameter.ActualName = Evaluator.OverloadParameter.ActualName;
|
---|
456 | BestVRPSolutionAnalyzer.TardinessParameter.ActualName = Evaluator.TardinessParameter.ActualName;
|
---|
457 | BestVRPSolutionAnalyzer.TravelTimeParameter.ActualName = Evaluator.TravelTimeParameter.ActualName;
|
---|
458 | BestVRPSolutionAnalyzer.VehiclesUtilizedParameter.ActualName = Evaluator.VehcilesUtilizedParameter.ActualName;
|
---|
459 | BestVRPSolutionAnalyzer.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
460 | BestVRPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
461 |
|
---|
462 | BestAverageWorstVRPToursAnalyzer.DistanceParameter.ActualName = Evaluator.DistanceParameter.ActualName;
|
---|
463 | BestAverageWorstVRPToursAnalyzer.OverloadParameter.ActualName = Evaluator.OverloadParameter.ActualName;
|
---|
464 | BestAverageWorstVRPToursAnalyzer.TardinessParameter.ActualName = Evaluator.TardinessParameter.ActualName;
|
---|
465 | BestAverageWorstVRPToursAnalyzer.TravelTimeParameter.ActualName = Evaluator.TravelTimeParameter.ActualName;
|
---|
466 | BestAverageWorstVRPToursAnalyzer.VehiclesUtilizedParameter.ActualName = Evaluator.VehcilesUtilizedParameter.ActualName;
|
---|
467 | BestAverageWorstVRPToursAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
468 | }
|
---|
469 | private void ParameterizeOperators() {
|
---|
470 | foreach (IVRPOperator op in Operators.OfType<IVRPOperator>()) {
|
---|
471 | if (op.CoordinatesParameter != null) op.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
472 | if (op.DistanceMatrixParameter != null) op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
473 | if (op.UseDistanceMatrixParameter != null) op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
474 | if (op.VehiclesParameter != null) op.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
475 | if (op.CapacityParameter != null) op.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
476 | if (op.DemandParameter != null) op.DemandParameter.ActualName = DemandParameter.Name;
|
---|
477 | if (op.ReadyTimeParameter != null) op.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
478 | if (op.DueTimeParameter != null) op.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
479 | if (op.ServiceTimeParameter != null) op.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
480 | }
|
---|
481 |
|
---|
482 | foreach (IVRPMoveOperator op in Operators.OfType<IVRPMoveOperator>()) {
|
---|
483 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
484 | }
|
---|
485 |
|
---|
486 | foreach (IPrinsOperator op in Operators.OfType<IPrinsOperator>()) {
|
---|
487 | op.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
|
---|
488 | op.TimeFactor.ActualName = TimeFactorParameter.Name;
|
---|
489 | op.DistanceFactor.ActualName = DistanceFactorParameter.Name;
|
---|
490 | op.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
|
---|
491 | op.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
|
---|
492 | }
|
---|
493 |
|
---|
494 | foreach (IVRPMoveEvaluator op in Operators.OfType<IVRPMoveEvaluator>()) {
|
---|
495 | op.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
|
---|
496 | op.TimeFactor.ActualName = TimeFactorParameter.Name;
|
---|
497 | op.DistanceFactor.ActualName = DistanceFactorParameter.Name;
|
---|
498 | op.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
|
---|
499 | op.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
|
---|
500 | op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
501 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
502 | }
|
---|
503 | string translocationMove = Operators.OfType<IMoveGenerator>().OfType<IAlbaTranslocationMoveOperator>().First().TranslocationMoveParameter.ActualName;
|
---|
504 | foreach (IAlbaTranslocationMoveOperator op in Operators.OfType<IAlbaTranslocationMoveOperator>())
|
---|
505 | op.TranslocationMoveParameter.ActualName = translocationMove;
|
---|
506 |
|
---|
507 | foreach (IVRPCrossover op in Operators.OfType<IVRPCrossover>()) {
|
---|
508 | op.ParentsParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
509 | op.ChildParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
510 | }
|
---|
511 |
|
---|
512 | foreach (IVRPManipulator op in Operators.OfType<IVRPManipulator>()) {
|
---|
513 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
514 | }
|
---|
515 |
|
---|
516 | foreach (var op in Operators.OfType<IVRPMultiNeighborhoodShakingOperator>()) {
|
---|
517 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
518 | }
|
---|
519 | }
|
---|
520 | private void ClearDistanceMatrix() {
|
---|
521 | DistanceMatrixParameter.Value = null;
|
---|
522 | }
|
---|
523 | #endregion
|
---|
524 |
|
---|
525 | public void ImportFromSolomon(string solomonFileName) {
|
---|
526 | SolomonParser parser = new SolomonParser(solomonFileName);
|
---|
527 | parser.Parse();
|
---|
528 |
|
---|
529 | this.Name = parser.ProblemName;
|
---|
530 |
|
---|
531 | BestKnownSolution = null;
|
---|
532 | Coordinates = new DoubleMatrix(parser.Coordinates);
|
---|
533 | Vehicles.Value = parser.Vehicles;
|
---|
534 | Capacity.Value = parser.Capacity;
|
---|
535 | Demand = new DoubleArray(parser.Demands);
|
---|
536 | ReadyTime = new DoubleArray(parser.Readytimes);
|
---|
537 | DueTime = new DoubleArray(parser.Duetimes);
|
---|
538 | ServiceTime = new DoubleArray(parser.Servicetimes);
|
---|
539 |
|
---|
540 | OnReset();
|
---|
541 | }
|
---|
542 |
|
---|
543 | public void ImportFromTSPLib(string tspFileName) {
|
---|
544 | TSPLIBParser parser = new TSPLIBParser(tspFileName);
|
---|
545 | parser.Parse();
|
---|
546 |
|
---|
547 | this.Name = parser.Name;
|
---|
548 | int problemSize = parser.Demands.Length;
|
---|
549 |
|
---|
550 | BestKnownSolution = null;
|
---|
551 | Coordinates = new DoubleMatrix(parser.Vertices);
|
---|
552 | if (parser.Vehicles != -1)
|
---|
553 | Vehicles.Value = parser.Vehicles;
|
---|
554 | else
|
---|
555 | Vehicles.Value = problemSize - 1;
|
---|
556 | Capacity.Value = parser.Capacity;
|
---|
557 | Demand = new DoubleArray(parser.Demands);
|
---|
558 | ReadyTime = new DoubleArray(problemSize);
|
---|
559 | DueTime = new DoubleArray(problemSize);
|
---|
560 | ServiceTime = new DoubleArray(problemSize);
|
---|
561 |
|
---|
562 | for (int i = 0; i < problemSize; i++) {
|
---|
563 | ReadyTime[i] = 0;
|
---|
564 | DueTime[i] = int.MaxValue;
|
---|
565 | ServiceTime[i] = 0;
|
---|
566 | }
|
---|
567 |
|
---|
568 | if (parser.Distance != -1) {
|
---|
569 | DueTime[0] = parser.Distance;
|
---|
570 | }
|
---|
571 |
|
---|
572 | if (parser.Depot != 1)
|
---|
573 | ErrorHandling.ShowErrorDialog(new Exception("Invalid depot specification"));
|
---|
574 |
|
---|
575 | if (parser.WeightType != TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D)
|
---|
576 | ErrorHandling.ShowErrorDialog(new Exception("Invalid weight type"));
|
---|
577 |
|
---|
578 | OnReset();
|
---|
579 | }
|
---|
580 |
|
---|
581 | private void EvalBestKnownSolution() {
|
---|
582 | if (BestKnownSolution != null) {
|
---|
583 | //call evaluator
|
---|
584 | IValueParameter<DoubleMatrix> distMatrix = new ValueLookupParameter<DoubleMatrix>("DistMatrix",
|
---|
585 | DistanceMatrix);
|
---|
586 |
|
---|
587 | TourEvaluation eval = VRPEvaluator.Evaluate(
|
---|
588 | BestKnownSolution,
|
---|
589 | Vehicles,
|
---|
590 | DueTime,
|
---|
591 | ServiceTime,
|
---|
592 | ReadyTime,
|
---|
593 | Demand,
|
---|
594 | Capacity,
|
---|
595 | FleetUsageFactorParameter.Value,
|
---|
596 | TimeFactorParameter.Value,
|
---|
597 | DistanceFactorParameter.Value,
|
---|
598 | OverloadPenaltyParameter.Value,
|
---|
599 | TardinessPenaltyParameter.Value,
|
---|
600 | Coordinates,
|
---|
601 | distMatrix,
|
---|
602 | UseDistanceMatrix);
|
---|
603 |
|
---|
604 | DistanceMatrix = distMatrix.Value;
|
---|
605 |
|
---|
606 | BestKnownQuality = new DoubleValue(eval.Quality);
|
---|
607 | } else {
|
---|
608 | BestKnownQuality = null;
|
---|
609 | }
|
---|
610 | }
|
---|
611 |
|
---|
612 | public void ImportSolution(string solutionFileName) {
|
---|
613 | SolutionParser parser = new SolutionParser(solutionFileName);
|
---|
614 | parser.Parse();
|
---|
615 |
|
---|
616 | HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding encoding = new Encodings.Potvin.PotvinEncoding();
|
---|
617 |
|
---|
618 | int cities = 0;
|
---|
619 | foreach (List<int> route in parser.Routes) {
|
---|
620 | Encodings.Tour tour = new Encodings.Tour();
|
---|
621 | tour.Cities.AddRange(route);
|
---|
622 | cities += tour.Cities.Count;
|
---|
623 |
|
---|
624 | encoding.Tours.Add(tour);
|
---|
625 | }
|
---|
626 |
|
---|
627 | if (cities != Coordinates.Rows - 1)
|
---|
628 | ErrorHandling.ShowErrorDialog(new Exception("The optimal solution does not seem to correspond with the problem data."));
|
---|
629 | else
|
---|
630 | BestKnownSolutionParameter.Value = encoding;
|
---|
631 | }
|
---|
632 |
|
---|
633 | public void ImportFromORLib(string orFileName) {
|
---|
634 | ORLIBParser parser = new ORLIBParser(orFileName);
|
---|
635 | parser.Parse();
|
---|
636 |
|
---|
637 | this.Name = parser.Name;
|
---|
638 | int problemSize = parser.Demands.Length;
|
---|
639 |
|
---|
640 | BestKnownSolution = null;
|
---|
641 | Coordinates = new DoubleMatrix(parser.Vertices);
|
---|
642 | Vehicles.Value = problemSize - 1;
|
---|
643 | Capacity.Value = parser.Capacity;
|
---|
644 | Demand = new DoubleArray(parser.Demands);
|
---|
645 | ReadyTime = new DoubleArray(problemSize);
|
---|
646 | DueTime = new DoubleArray(problemSize);
|
---|
647 | ServiceTime = new DoubleArray(problemSize);
|
---|
648 |
|
---|
649 | ReadyTime[0] = 0;
|
---|
650 | DueTime[0] = parser.MaxRouteTime;
|
---|
651 | ServiceTime[0] = 0;
|
---|
652 |
|
---|
653 | for (int i = 1; i < problemSize; i++) {
|
---|
654 | ReadyTime[i] = 0;
|
---|
655 | DueTime[i] = int.MaxValue;
|
---|
656 | ServiceTime[i] = parser.ServiceTime;
|
---|
657 | }
|
---|
658 |
|
---|
659 | OnReset();
|
---|
660 | }
|
---|
661 |
|
---|
662 | private void InitializeRandomVRPInstance() {
|
---|
663 | System.Random rand = new System.Random();
|
---|
664 |
|
---|
665 | int cities = 100;
|
---|
666 |
|
---|
667 | Coordinates = new DoubleMatrix(cities + 1, 2);
|
---|
668 | Demand = new DoubleArray(cities + 1);
|
---|
669 | DueTime = new DoubleArray(cities + 1);
|
---|
670 | ReadyTime = new DoubleArray(cities + 1);
|
---|
671 | ServiceTime = new DoubleArray(cities + 1);
|
---|
672 |
|
---|
673 | Vehicles.Value = 100;
|
---|
674 | Capacity.Value = 200;
|
---|
675 |
|
---|
676 | for (int i = 0; i <= cities; i++) {
|
---|
677 | Coordinates[i, 0] = rand.Next(0, 100);
|
---|
678 | Coordinates[i, 1] = rand.Next(0, 100);
|
---|
679 |
|
---|
680 | if (i == 0) {
|
---|
681 | Demand[i] = 0;
|
---|
682 | DueTime[i] = Int16.MaxValue;
|
---|
683 | ReadyTime[i] = 0;
|
---|
684 | ServiceTime[i] = 0;
|
---|
685 | } else {
|
---|
686 | Demand[i] = rand.Next(10, 50);
|
---|
687 | DueTime[i] = rand.Next((int)Math.Ceiling(VRPUtilities.CalculateDistance(0, i, Coordinates)), 1200);
|
---|
688 | ReadyTime[i] = DueTime[i] - rand.Next(0, 100);
|
---|
689 | ServiceTime[i] = 90;
|
---|
690 | }
|
---|
691 | }
|
---|
692 | }
|
---|
693 | }
|
---|
694 | }
|
---|