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.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Encodings.PermutationEncoding;
|
---|
30 | using HeuristicLab.Optimization;
|
---|
31 | using HeuristicLab.Parameters;
|
---|
32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
33 | using HeuristicLab.PluginInfrastructure;
|
---|
34 | using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
|
---|
35 | using HeuristicLab.Problems.VehicleRouting.Encodings.General;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
38 | [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")]
|
---|
39 | [Creatable("Problems")]
|
---|
40 | [StorableClass]
|
---|
41 | public sealed class VehicleRoutingProblem : ParameterizedNamedItem, ISingleObjectiveProblem {
|
---|
42 | public override Image ItemImage {
|
---|
43 | get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | #region Parameter Properties
|
---|
47 | public ValueParameter<BoolValue> MaximizationParameter {
|
---|
48 | get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
49 | }
|
---|
50 | IParameter ISingleObjectiveProblem.MaximizationParameter {
|
---|
51 | get { return MaximizationParameter; }
|
---|
52 | }
|
---|
53 | public ValueParameter<DoubleMatrix> CoordinatesParameter {
|
---|
54 | get { return (ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
|
---|
55 | }
|
---|
56 | public OptionalValueParameter<DoubleMatrix> DistanceMatrixParameter {
|
---|
57 | get { return (OptionalValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; }
|
---|
58 | }
|
---|
59 | public ValueParameter<BoolValue> UseDistanceMatrixParameter {
|
---|
60 | get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
|
---|
61 | }
|
---|
62 | public ValueParameter<IntValue> VehiclesParameter {
|
---|
63 | get { return (ValueParameter<IntValue>)Parameters["Vehicles"]; }
|
---|
64 | }
|
---|
65 | public ValueParameter<DoubleValue> CapacityParameter {
|
---|
66 | get { return (ValueParameter<DoubleValue>)Parameters["Capacity"]; }
|
---|
67 | }
|
---|
68 | public ValueParameter<DoubleArray> DemandParameter {
|
---|
69 | get { return (ValueParameter<DoubleArray>)Parameters["Demand"]; }
|
---|
70 | }
|
---|
71 | public ValueParameter<DoubleArray> ReadyTimeParameter {
|
---|
72 | get { return (ValueParameter<DoubleArray>)Parameters["ReadyTime"]; }
|
---|
73 | }
|
---|
74 | public ValueParameter<DoubleArray> DueTimeParameter {
|
---|
75 | get { return (ValueParameter<DoubleArray>)Parameters["DueTime"]; }
|
---|
76 | }
|
---|
77 | public ValueParameter<DoubleArray> ServiceTimeParameter {
|
---|
78 | get { return (ValueParameter<DoubleArray>)Parameters["ServiceTime"]; }
|
---|
79 | }
|
---|
80 | ValueParameter<IVRPCreator> SolutionCreatorParameter {
|
---|
81 | get { return (ValueParameter<IVRPCreator>)Parameters["SolutionCreator"]; }
|
---|
82 | }
|
---|
83 | IParameter IProblem.SolutionCreatorParameter {
|
---|
84 | get { return SolutionCreatorParameter; }
|
---|
85 | }
|
---|
86 | ValueParameter<IVRPEvaluator> EvaluatorParameter {
|
---|
87 | get { return (ValueParameter<IVRPEvaluator>)Parameters["Evaluator"]; }
|
---|
88 | }
|
---|
89 | IParameter IProblem.EvaluatorParameter {
|
---|
90 | get { return EvaluatorParameter; }
|
---|
91 | }
|
---|
92 | public IValueParameter<DoubleValue> FleetUsageFactor {
|
---|
93 | get { return (IValueParameter<DoubleValue>)Parameters["EvalFleetUsageFactor"]; }
|
---|
94 | }
|
---|
95 | public IValueParameter<DoubleValue> TimeFactor {
|
---|
96 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
|
---|
97 | }
|
---|
98 | public IValueParameter<DoubleValue> DistanceFactor {
|
---|
99 | get { return (IValueParameter<DoubleValue>)Parameters["EvalDistanceFactor"]; }
|
---|
100 | }
|
---|
101 | public IValueParameter<DoubleValue> OverloadPenalty {
|
---|
102 | get { return (IValueParameter<DoubleValue>)Parameters["EvalOverloadPenalty"]; }
|
---|
103 | }
|
---|
104 | public IValueParameter<DoubleValue> TardinessPenalty {
|
---|
105 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
|
---|
106 | }
|
---|
107 | public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
|
---|
108 | get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
|
---|
109 | }
|
---|
110 | IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
|
---|
111 | get { return BestKnownQualityParameter; }
|
---|
112 | }
|
---|
113 | #endregion
|
---|
114 |
|
---|
115 | #region Properties
|
---|
116 | public DoubleMatrix Coordinates {
|
---|
117 | get { return CoordinatesParameter.Value; }
|
---|
118 | set { CoordinatesParameter.Value = value; }
|
---|
119 | }
|
---|
120 | public DoubleMatrix DistanceMatrix {
|
---|
121 | get { return DistanceMatrixParameter.Value; }
|
---|
122 | set { DistanceMatrixParameter.Value = value; }
|
---|
123 | }
|
---|
124 | public BoolValue UseDistanceMatrix {
|
---|
125 | get { return UseDistanceMatrixParameter.Value; }
|
---|
126 | set { UseDistanceMatrixParameter.Value = value; }
|
---|
127 | }
|
---|
128 | public IntValue Vehicles {
|
---|
129 | get { return VehiclesParameter.Value; }
|
---|
130 | set { VehiclesParameter.Value = value; }
|
---|
131 | }
|
---|
132 | public DoubleValue Capacity {
|
---|
133 | get { return CapacityParameter.Value; }
|
---|
134 | set { CapacityParameter.Value = value; }
|
---|
135 | }
|
---|
136 | public DoubleArray Demand {
|
---|
137 | get { return DemandParameter.Value; }
|
---|
138 | set { DemandParameter.Value = value; }
|
---|
139 | }
|
---|
140 | public DoubleArray ReadyTime {
|
---|
141 | get { return ReadyTimeParameter.Value; }
|
---|
142 | set { ReadyTimeParameter.Value = value; }
|
---|
143 | }
|
---|
144 | public DoubleArray DueTime {
|
---|
145 | get { return DueTimeParameter.Value; }
|
---|
146 | set { DueTimeParameter.Value = value; }
|
---|
147 | }
|
---|
148 | public DoubleArray ServiceTime {
|
---|
149 | get { return ServiceTimeParameter.Value; }
|
---|
150 | set { ServiceTimeParameter.Value = value; }
|
---|
151 | }
|
---|
152 | public DoubleValue BestKnownQuality {
|
---|
153 | get { return BestKnownQualityParameter.Value; }
|
---|
154 | set { BestKnownQualityParameter.Value = value; }
|
---|
155 | }
|
---|
156 | IVRPCreator SolutionCreator {
|
---|
157 | get { return SolutionCreatorParameter.Value; }
|
---|
158 | set { SolutionCreatorParameter.Value = value; }
|
---|
159 | }
|
---|
160 | ISolutionCreator IProblem.SolutionCreator {
|
---|
161 | get { return SolutionCreatorParameter.Value; }
|
---|
162 | }
|
---|
163 | IVRPEvaluator Evaluator {
|
---|
164 | get { return EvaluatorParameter.Value; }
|
---|
165 | set { EvaluatorParameter.Value = value; }
|
---|
166 | }
|
---|
167 | ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
|
---|
168 | get { return EvaluatorParameter.Value; }
|
---|
169 | }
|
---|
170 | IEvaluator IProblem.Evaluator {
|
---|
171 | get { return EvaluatorParameter.Value; }
|
---|
172 | }
|
---|
173 | public IEnumerable<IOperator> Operators {
|
---|
174 | get { return operators; }
|
---|
175 | }
|
---|
176 | private BestVRPSolutionAnalyzer BestVRPSolutionAnalyzer {
|
---|
177 | get { return operators.OfType<BestVRPSolutionAnalyzer>().FirstOrDefault(); }
|
---|
178 | }
|
---|
179 | #endregion
|
---|
180 |
|
---|
181 | [Storable]
|
---|
182 | private List<IOperator> operators;
|
---|
183 |
|
---|
184 | [StorableConstructor]
|
---|
185 | private VehicleRoutingProblem(bool deserializing) : base(deserializing) { }
|
---|
186 | public VehicleRoutingProblem()
|
---|
187 | : base() {
|
---|
188 | IVRPCreator creator = new RandomCreator();
|
---|
189 | IVRPEvaluator evaluator = new VRPEvaluator();
|
---|
190 |
|
---|
191 | Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the Vehicle Routing Problem is a minimization problem.", new BoolValue(false)));
|
---|
192 | Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrix()));
|
---|
193 | Parameters.Add(new OptionalValueParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
|
---|
194 | Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true)));
|
---|
195 | Parameters.Add(new ValueParameter<IntValue>("Vehicles", "The number of vehicles.", new IntValue(0)));
|
---|
196 | Parameters.Add(new ValueParameter<DoubleValue>("Capacity", "The capacity of each vehicle.", new DoubleValue(0)));
|
---|
197 | Parameters.Add(new ValueParameter<DoubleArray>("Demand", "The demand of each customer.", new DoubleArray()));
|
---|
198 | Parameters.Add(new ValueParameter<DoubleArray>("ReadyTime", "The ready time of each customer.", new DoubleArray()));
|
---|
199 | Parameters.Add(new ValueParameter<DoubleArray>("DueTime", "The due time of each customer.", new DoubleArray()));
|
---|
200 | Parameters.Add(new ValueParameter<DoubleArray>("ServiceTime", "The service time of each customer.", new DoubleArray()));
|
---|
201 | Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance."));
|
---|
202 | Parameters.Add(new ValueParameter<DoubleValue>("EvalFleetUsageFactor", "The fleet usage factor considered in the evaluation.", new DoubleValue(100)));
|
---|
203 | Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
|
---|
204 | Parameters.Add(new ValueParameter<DoubleValue>("EvalDistanceFactor", "The distance factor considered in the evaluation.", new DoubleValue(1)));
|
---|
205 | Parameters.Add(new ValueParameter<DoubleValue>("EvalOverloadPenalty", "The overload penalty considered in the evaluation.", new DoubleValue(100)));
|
---|
206 | Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
|
---|
207 |
|
---|
208 | Parameters.Add(new ValueParameter<IVRPCreator>("SolutionCreator", "The operator which should be used to create new VRP solutions.", creator));
|
---|
209 | Parameters.Add(new ValueParameter<IVRPEvaluator>("Evaluator", "The operator which should be used to evaluate VRP solutions.", evaluator));
|
---|
210 |
|
---|
211 | creator.VRPToursParameter.ActualName = "VRPTours";
|
---|
212 | evaluator.QualityParameter.ActualName = "VRPQuality";
|
---|
213 |
|
---|
214 | InitializeRandomVRPInstance();
|
---|
215 |
|
---|
216 | ParameterizeSolutionCreator();
|
---|
217 | ParameterizeEvaluator();
|
---|
218 |
|
---|
219 | InitializeOperators();
|
---|
220 | AttachEventHandlers();
|
---|
221 | }
|
---|
222 |
|
---|
223 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
224 | VehicleRoutingProblem clone = (VehicleRoutingProblem)base.Clone(cloner);
|
---|
225 | clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
|
---|
226 | clone.DistanceMatrixParameter.Value = DistanceMatrixParameter.Value;
|
---|
227 | clone.AttachEventHandlers();
|
---|
228 | return clone;
|
---|
229 | }
|
---|
230 |
|
---|
231 | #region Events
|
---|
232 | public event EventHandler SolutionCreatorChanged;
|
---|
233 | private void OnSolutionCreatorChanged() {
|
---|
234 | EventHandler handler = SolutionCreatorChanged;
|
---|
235 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
236 | }
|
---|
237 | public event EventHandler EvaluatorChanged;
|
---|
238 | private void OnEvaluatorChanged() {
|
---|
239 | EventHandler handler = EvaluatorChanged;
|
---|
240 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
241 | }
|
---|
242 | public event EventHandler OperatorsChanged;
|
---|
243 | private void OnOperatorsChanged() {
|
---|
244 | EventHandler handler = OperatorsChanged;
|
---|
245 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
246 | }
|
---|
247 | public event EventHandler Reset;
|
---|
248 | private void OnReset() {
|
---|
249 | EventHandler handler = Reset;
|
---|
250 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
251 | }
|
---|
252 | void VehiclesValue_ValueChanged(object sender, EventArgs e) {
|
---|
253 | ParameterizeSolutionCreator();
|
---|
254 | }
|
---|
255 | private void CoordinatesParameter_ValueChanged(object sender, EventArgs e) {
|
---|
256 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
257 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
258 | ParameterizeSolutionCreator();
|
---|
259 | ClearDistanceMatrix();
|
---|
260 | }
|
---|
261 | private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
262 | ClearDistanceMatrix();
|
---|
263 | }
|
---|
264 | private void Coordinates_Reset(object sender, EventArgs e) {
|
---|
265 | ParameterizeSolutionCreator();
|
---|
266 | ClearDistanceMatrix();
|
---|
267 | }
|
---|
268 | private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
269 | ParameterizeSolutionCreator();
|
---|
270 | ParameterizeEvaluator();
|
---|
271 | ParameterizeAnalyzer();
|
---|
272 | ParameterizeOperators();
|
---|
273 | OnSolutionCreatorChanged();
|
---|
274 | }
|
---|
275 | private void SolutionCreator_PermutationParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
276 | ParameterizeEvaluator();
|
---|
277 | ParameterizeAnalyzer();
|
---|
278 | ParameterizeOperators();
|
---|
279 | }
|
---|
280 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
281 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
282 | ParameterizeEvaluator();
|
---|
283 | UpdateMoveEvaluators();
|
---|
284 | ParameterizeAnalyzer();
|
---|
285 | OnEvaluatorChanged();
|
---|
286 | }
|
---|
287 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
288 | ParameterizeAnalyzer();
|
---|
289 | }
|
---|
290 | private void TranslocationMoveParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
291 | string name = ((ILookupParameter<TranslocationMove>)sender).ActualName;
|
---|
292 | foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) {
|
---|
293 | op.TranslocationMoveParameter.ActualName = name;
|
---|
294 | }
|
---|
295 | }
|
---|
296 | #endregion
|
---|
297 |
|
---|
298 | #region Helpers
|
---|
299 | [StorableHook(HookType.AfterDeserialization)]
|
---|
300 | private void AfterDeserializationHook() {
|
---|
301 | AttachEventHandlers();
|
---|
302 | }
|
---|
303 |
|
---|
304 | private void AttachEventHandlers() {
|
---|
305 | CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
|
---|
306 | Vehicles.ValueChanged += new EventHandler(VehiclesValue_ValueChanged);
|
---|
307 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
308 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
309 | SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
|
---|
310 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
311 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
312 | }
|
---|
313 | private void InitializeOperators() {
|
---|
314 | operators = new List<IOperator>();
|
---|
315 | operators.Add(new BestVRPSolutionAnalyzer());
|
---|
316 | ParameterizeAnalyzer();
|
---|
317 | operators.AddRange(ApplicationManager.Manager.GetInstances<IVRPOperator>().Cast<IOperator>());
|
---|
318 | ParameterizeOperators();
|
---|
319 | UpdateMoveEvaluators();
|
---|
320 | InitializeMoveGenerators();
|
---|
321 | }
|
---|
322 | private void InitializeMoveGenerators() {
|
---|
323 | foreach (IAlbaTranslocationMoveOperator op in Operators.OfType<IAlbaTranslocationMoveOperator>()) {
|
---|
324 | if (op is IMoveGenerator) {
|
---|
325 | op.TranslocationMoveParameter.ActualNameChanged += new EventHandler(TranslocationMoveParameter_ActualNameChanged);
|
---|
326 | }
|
---|
327 | }
|
---|
328 |
|
---|
329 | }
|
---|
330 | private void UpdateMoveEvaluators() {
|
---|
331 | ParameterizeOperators();
|
---|
332 | OnOperatorsChanged();
|
---|
333 | }
|
---|
334 | private void ParameterizeSolutionCreator() {
|
---|
335 | SolutionCreator.CitiesParameter.Value = new IntValue(Coordinates.Rows - 1);
|
---|
336 | SolutionCreator.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
337 | SolutionCreator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
338 | Evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
339 | Evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
340 | SolutionCreator.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
341 | SolutionCreator.DemandParameter.ActualName = DemandParameter.Name;
|
---|
342 | SolutionCreator.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
343 | SolutionCreator.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
344 | SolutionCreator.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
345 | }
|
---|
346 | private void ParameterizeEvaluator() {
|
---|
347 | Evaluator.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
348 | Evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
349 | Evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
350 | Evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
351 | Evaluator.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
352 | Evaluator.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
353 | Evaluator.DemandParameter.ActualName = DemandParameter.Name;
|
---|
354 | Evaluator.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
355 | Evaluator.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
356 | Evaluator.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
357 | Evaluator.FleetUsageFactor.ActualName = FleetUsageFactor.Name;
|
---|
358 | Evaluator.TimeFactor.ActualName = TimeFactor.Name;
|
---|
359 | Evaluator.DistanceFactor.ActualName = DistanceFactor.Name;
|
---|
360 | Evaluator.OverloadPenalty.ActualName = OverloadPenalty.Name;
|
---|
361 | Evaluator.TardinessPenalty.ActualName = TardinessPenalty.Name;
|
---|
362 | }
|
---|
363 | private void ParameterizeAnalyzer() {
|
---|
364 | BestVRPSolutionAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
365 | BestVRPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
366 | BestVRPSolutionAnalyzer.DistanceParameter.ActualName = Evaluator.DistanceParameter.ActualName;
|
---|
367 | BestVRPSolutionAnalyzer.OverloadParameter.ActualName = Evaluator.OverloadParameter.ActualName;
|
---|
368 | BestVRPSolutionAnalyzer.TardinessParameter.ActualName = Evaluator.TardinessParameter.ActualName;
|
---|
369 | BestVRPSolutionAnalyzer.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
370 | BestVRPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
371 | }
|
---|
372 | private void ParameterizeOperators() {
|
---|
373 | foreach (IVRPOperator op in Operators.OfType<IVRPOperator>()) {
|
---|
374 | if(op.CoordinatesParameter != null) op.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
375 | if(op.DistanceMatrixParameter != null) op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
376 | if(op.UseDistanceMatrixParameter != null) op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
377 | if(op.VehiclesParameter != null) op.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
378 | if(op.CapacityParameter != null) op.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
379 | if(op.DemandParameter != null) op.DemandParameter.ActualName = DemandParameter.Name;
|
---|
380 | if(op.ReadyTimeParameter != null) op.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
381 | if(op.DueTimeParameter != null) op.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
382 | if(op.ServiceTimeParameter != null) op.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
383 | }
|
---|
384 |
|
---|
385 | foreach (IVRPMoveOperator op in Operators.OfType<IVRPMoveOperator>()) {
|
---|
386 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
387 | }
|
---|
388 |
|
---|
389 | foreach (IVRPMoveEvaluator op in Operators.OfType<IVRPMoveEvaluator>()) {
|
---|
390 | op.FleetUsageFactor.ActualName = FleetUsageFactor.Name;
|
---|
391 | op.TimeFactor.ActualName = TimeFactor.Name;
|
---|
392 | op.DistanceFactor.ActualName = DistanceFactor.Name;
|
---|
393 | op.OverloadPenalty.ActualName = OverloadPenalty.Name;
|
---|
394 | op.TardinessPenalty.ActualName = TardinessPenalty.Name;
|
---|
395 | op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
396 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
397 | }
|
---|
398 | string translocationMove = Operators.OfType<IMoveGenerator>().OfType<IAlbaTranslocationMoveOperator>().First().TranslocationMoveParameter.ActualName;
|
---|
399 | foreach (IAlbaTranslocationMoveOperator op in Operators.OfType<IAlbaTranslocationMoveOperator>())
|
---|
400 | op.TranslocationMoveParameter.ActualName = translocationMove;
|
---|
401 |
|
---|
402 | foreach (IVRPCrossover op in Operators.OfType<IVRPCrossover>()) {
|
---|
403 | op.ParentsParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
404 | op.ChildParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
405 | }
|
---|
406 |
|
---|
407 | foreach (IVRPManipulator op in Operators.OfType<IVRPManipulator>()) {
|
---|
408 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
409 | }
|
---|
410 | }
|
---|
411 | private void ClearDistanceMatrix() {
|
---|
412 | DistanceMatrixParameter.Value = null;
|
---|
413 | }
|
---|
414 | #endregion
|
---|
415 |
|
---|
416 | public void ImportFromSolomon(string solomonFileName) {
|
---|
417 | SolomonParser parser = new SolomonParser(solomonFileName);
|
---|
418 | parser.Parse();
|
---|
419 |
|
---|
420 | this.Name = parser.ProblemName;
|
---|
421 |
|
---|
422 | Coordinates = new DoubleMatrix(parser.Coordinates);
|
---|
423 | Vehicles.Value = parser.Vehicles;
|
---|
424 | Capacity.Value = parser.Capacity;
|
---|
425 | Demand = new DoubleArray(parser.Demands);
|
---|
426 | ReadyTime = new DoubleArray(parser.Readytimes);
|
---|
427 | DueTime = new DoubleArray(parser.Duetimes);
|
---|
428 | ServiceTime = new DoubleArray(parser.Servicetimes);
|
---|
429 |
|
---|
430 | OnReset();
|
---|
431 | }
|
---|
432 |
|
---|
433 | private void InitializeRandomVRPInstance() {
|
---|
434 | System.Random rand = new System.Random();
|
---|
435 |
|
---|
436 | int cities = 100;
|
---|
437 |
|
---|
438 | Coordinates = new DoubleMatrix(cities + 1, 2);
|
---|
439 | Demand = new DoubleArray(cities + 1);
|
---|
440 | DueTime = new DoubleArray(cities + 1);
|
---|
441 | ReadyTime = new DoubleArray(cities + 1);
|
---|
442 | ServiceTime = new DoubleArray(cities + 1);
|
---|
443 |
|
---|
444 | Vehicles.Value = 100;
|
---|
445 | Capacity.Value = 200;
|
---|
446 |
|
---|
447 | for (int i = 0; i <= cities; i++) {
|
---|
448 | Coordinates[i, 0] = rand.Next(0, 100);
|
---|
449 | Coordinates[i, 1] = rand.Next(0, 100);
|
---|
450 |
|
---|
451 | if (i == 0) {
|
---|
452 | Demand[i] = 0;
|
---|
453 | DueTime[i] = Int16.MaxValue;
|
---|
454 | ReadyTime[i] = 0;
|
---|
455 | ServiceTime[i] = 0;
|
---|
456 | } else {
|
---|
457 | Demand[i] = rand.Next(10, 50);
|
---|
458 | DueTime[i] = rand.Next((int)Math.Ceiling(VRPUtilities.CalculateDistance(0, i, Coordinates)), 1200);
|
---|
459 | ReadyTime[i] = DueTime[i] - rand.Next(0, 100);
|
---|
460 | ServiceTime[i] = 90;
|
---|
461 | }
|
---|
462 | }
|
---|
463 | }
|
---|
464 | }
|
---|
465 | }
|
---|