[3938] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3938] | 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;
|
---|
[4068] | 25 | using HeuristicLab.Common;
|
---|
[3938] | 26 | using HeuristicLab.Core;
|
---|
[4068] | 27 | using HeuristicLab.Data;
|
---|
[3938] | 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
[4068] | 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 | using HeuristicLab.PluginInfrastructure;
|
---|
[3938] | 32 | using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
|
---|
[4179] | 33 | using HeuristicLab.Problems.VehicleRouting.Encodings.General;
|
---|
[4352] | 34 | using HeuristicLab.Problems.VehicleRouting.Encodings.Prins;
|
---|
[3938] | 35 |
|
---|
| 36 | namespace HeuristicLab.Problems.VehicleRouting {
|
---|
| 37 | [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")]
|
---|
| 38 | [Creatable("Problems")]
|
---|
| 39 | [StorableClass]
|
---|
[6938] | 40 | public sealed class VehicleRoutingProblem : SingleObjectiveHeuristicOptimizationProblem<IVRPEvaluator, IVRPCreator>, IStorableContent {
|
---|
[4419] | 41 | public string Filename { get; set; }
|
---|
| 42 |
|
---|
[3938] | 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 | }
|
---|
[4619] | 71 | public IValueParameter<DoubleValue> FleetUsageFactorParameter {
|
---|
[4179] | 72 | get { return (IValueParameter<DoubleValue>)Parameters["EvalFleetUsageFactor"]; }
|
---|
[3947] | 73 | }
|
---|
[4619] | 74 | public IValueParameter<DoubleValue> TimeFactorParameter {
|
---|
[4179] | 75 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
|
---|
[3947] | 76 | }
|
---|
[4619] | 77 | public IValueParameter<DoubleValue> DistanceFactorParameter {
|
---|
[4179] | 78 | get { return (IValueParameter<DoubleValue>)Parameters["EvalDistanceFactor"]; }
|
---|
[3947] | 79 | }
|
---|
[4619] | 80 | public IValueParameter<DoubleValue> OverloadPenaltyParameter {
|
---|
[4179] | 81 | get { return (IValueParameter<DoubleValue>)Parameters["EvalOverloadPenalty"]; }
|
---|
[3947] | 82 | }
|
---|
[4619] | 83 | public IValueParameter<DoubleValue> TardinessPenaltyParameter {
|
---|
[4179] | 84 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
|
---|
[3947] | 85 | }
|
---|
[4852] | 86 | public OptionalValueParameter<IVRPEncoding> BestKnownSolutionParameter {
|
---|
| 87 | get { return (OptionalValueParameter<IVRPEncoding>)Parameters["BestKnownSolution"]; }
|
---|
[4619] | 88 | }
|
---|
[3938] | 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 | }
|
---|
[4852] | 128 | public IVRPEncoding BestKnownSolution {
|
---|
[4619] | 129 | get { return BestKnownSolutionParameter.Value; }
|
---|
| 130 | set { BestKnownSolutionParameter.Value = value; }
|
---|
| 131 | }
|
---|
[3938] | 132 | private BestVRPSolutionAnalyzer BestVRPSolutionAnalyzer {
|
---|
[6938] | 133 | get { return Operators.OfType<BestVRPSolutionAnalyzer>().FirstOrDefault(); }
|
---|
[3938] | 134 | }
|
---|
[4352] | 135 | private BestAverageWorstVRPToursAnalyzer BestAverageWorstVRPToursAnalyzer {
|
---|
[6938] | 136 | get { return Operators.OfType<BestAverageWorstVRPToursAnalyzer>().FirstOrDefault(); }
|
---|
[4352] | 137 | }
|
---|
[3938] | 138 | #endregion
|
---|
| 139 |
|
---|
[6938] | 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
|
---|
[4098] | 152 |
|
---|
| 153 | [StorableConstructor]
|
---|
[4118] | 154 | private VehicleRoutingProblem(bool deserializing) : base(deserializing) { }
|
---|
[4722] | 155 | private VehicleRoutingProblem(VehicleRoutingProblem original, Cloner cloner)
|
---|
| 156 | : base(original, cloner) {
|
---|
[7351] | 157 | RegisterEventHandlers();
|
---|
[4722] | 158 | }
|
---|
[3938] | 159 | public VehicleRoutingProblem()
|
---|
[6938] | 160 | : base(new VRPEvaluator(), new RandomCreator()) {
|
---|
[3938] | 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()));
|
---|
[4857] | 170 | Parameters.Add(new OptionalValueParameter<IVRPEncoding>("BestKnownSolution", "The best known solution of this VRP instance."));
|
---|
[4179] | 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)));
|
---|
[3938] | 176 |
|
---|
[6939] | 177 | Maximization.Value = false;
|
---|
| 178 | MaximizationParameter.Hidden = true;
|
---|
| 179 |
|
---|
[6938] | 180 | SolutionCreator.VRPToursParameter.ActualName = "VRPTours";
|
---|
| 181 | Evaluator.QualityParameter.ActualName = "VRPQuality";
|
---|
[3938] | 182 |
|
---|
[4138] | 183 | InitializeRandomVRPInstance();
|
---|
| 184 |
|
---|
[3938] | 185 | ParameterizeSolutionCreator();
|
---|
| 186 | ParameterizeEvaluator();
|
---|
| 187 |
|
---|
[4098] | 188 | InitializeOperators();
|
---|
[7351] | 189 | RegisterEventHandlers();
|
---|
[3938] | 190 | }
|
---|
| 191 |
|
---|
| 192 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 193 | return new VehicleRoutingProblem(this, cloner);
|
---|
[3938] | 194 | }
|
---|
| 195 |
|
---|
| 196 | #region Events
|
---|
[6938] | 197 | protected override void OnSolutionCreatorChanged() {
|
---|
| 198 | base.OnSolutionCreatorChanged();
|
---|
| 199 | ParameterizeSolutionCreator();
|
---|
| 200 | ParameterizeEvaluator();
|
---|
| 201 | ParameterizeAnalyzer();
|
---|
| 202 | ParameterizeOperators();
|
---|
[3938] | 203 | }
|
---|
[6938] | 204 | protected override void OnEvaluatorChanged() {
|
---|
| 205 | base.OnEvaluatorChanged();
|
---|
| 206 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
| 207 | ParameterizeEvaluator();
|
---|
| 208 | UpdateMoveEvaluators();
|
---|
| 209 | ParameterizeAnalyzer();
|
---|
[3938] | 210 | }
|
---|
[6938] | 211 | private void VehiclesValue_ValueChanged(object sender, EventArgs e) {
|
---|
[3938] | 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();
|
---|
[4619] | 219 |
|
---|
| 220 | BestKnownSolution = null;
|
---|
[3938] | 221 | }
|
---|
| 222 | private void Coordinates_ItemChanged(object sender, EventArgs<int, int> e) {
|
---|
| 223 | ClearDistanceMatrix();
|
---|
[4619] | 224 |
|
---|
| 225 | BestKnownSolution = null;
|
---|
[3938] | 226 | }
|
---|
| 227 | private void Coordinates_Reset(object sender, EventArgs e) {
|
---|
| 228 | ParameterizeSolutionCreator();
|
---|
| 229 | ClearDistanceMatrix();
|
---|
[4619] | 230 |
|
---|
| 231 | BestKnownSolution = null;
|
---|
[3938] | 232 | }
|
---|
| 233 | private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 234 | ParameterizeAnalyzer();
|
---|
| 235 | }
|
---|
[4619] | 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) {
|
---|
[4626] | 273 | if (DistanceMatrix != null) {
|
---|
| 274 | DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged);
|
---|
| 275 | DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset);
|
---|
| 276 | }
|
---|
[4619] | 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 | }
|
---|
[4620] | 350 | void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 351 | EvalBestKnownSolution();
|
---|
| 352 | }
|
---|
[3938] | 353 | #endregion
|
---|
| 354 |
|
---|
| 355 | #region Helpers
|
---|
| 356 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[7351] | 357 | private void AfterDeserialization() {
|
---|
| 358 | // BackwardsCompatibility3.3
|
---|
| 359 | #region Backwards compatible code, remove with 3.4
|
---|
[4625] | 360 | if (!Parameters.ContainsKey("BestKnownSolution")) {
|
---|
[4852] | 361 | Parameters.Add(new OptionalValueParameter<IVRPEncoding>("BestKnownSolution", "The best known solution of this TSP instance."));
|
---|
[4625] | 362 | }
|
---|
| 363 | #endregion
|
---|
| 364 |
|
---|
[7351] | 365 | RegisterEventHandlers();
|
---|
[4118] | 366 | }
|
---|
| 367 |
|
---|
[7351] | 368 | private void RegisterEventHandlers() {
|
---|
[3938] | 369 | CoordinatesParameter.ValueChanged += new EventHandler(CoordinatesParameter_ValueChanged);
|
---|
| 370 | Coordinates.ItemChanged += new EventHandler<EventArgs<int, int>>(Coordinates_ItemChanged);
|
---|
| 371 | Coordinates.Reset += new EventHandler(Coordinates_Reset);
|
---|
[4619] | 372 |
|
---|
| 373 | Vehicles.ValueChanged += new EventHandler(VehiclesValue_ValueChanged);
|
---|
| 374 |
|
---|
[3938] | 375 | Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
|
---|
[4619] | 376 |
|
---|
| 377 | DistanceFactorParameter.ValueChanged += new EventHandler(DistanceFactor_ValueChanged);
|
---|
| 378 | DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactorValue_ValueChanged);
|
---|
| 379 | FleetUsageFactorParameter.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged);
|
---|
| 380 | FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactorValue_ValueChanged);
|
---|
| 381 | OverloadPenaltyParameter.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged);
|
---|
| 382 | OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenaltyValue_ValueChanged);
|
---|
| 383 | TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
|
---|
| 384 | TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenaltyValue_ValueChanged);
|
---|
| 385 | TimeFactorParameter.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
|
---|
| 386 | TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactorValue_ValueChanged);
|
---|
| 387 |
|
---|
| 388 | DistanceMatrixParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged);
|
---|
| 389 | UseDistanceMatrixParameter.ValueChanged += new EventHandler(UseDistanceMatrixParameter_ValueChanged);
|
---|
| 390 | UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged);
|
---|
| 391 |
|
---|
| 392 | CapacityParameter.ValueChanged += new EventHandler(CapacityParameter_ValueChanged);
|
---|
| 393 | Capacity.ValueChanged += new EventHandler(Capacity_ValueChanged);
|
---|
| 394 | DemandParameter.ValueChanged += new EventHandler(DemandParameter_ValueChanged);
|
---|
| 395 | Demand.ItemChanged += new EventHandler<EventArgs<int>>(Demand_ItemChanged);
|
---|
| 396 | Demand.Reset += new EventHandler(Demand_Reset);
|
---|
| 397 | DueTimeParameter.ValueChanged += new EventHandler(DueTimeParameter_ValueChanged);
|
---|
| 398 | DueTime.ItemChanged += new EventHandler<EventArgs<int>>(DueTime_ItemChanged);
|
---|
| 399 | DueTime.Reset += new EventHandler(DueTime_Reset);
|
---|
| 400 | ReadyTimeParameter.ValueChanged += new EventHandler(ReadyTimeParameter_ValueChanged);
|
---|
| 401 | ReadyTime.ItemChanged += new EventHandler<EventArgs<int>>(ReadyTime_ItemChanged);
|
---|
| 402 | ReadyTime.Reset += new EventHandler(ReadyTime_Reset);
|
---|
| 403 | ServiceTimeParameter.ValueChanged += new EventHandler(ServiceTimeParameter_ValueChanged);
|
---|
| 404 | ServiceTime.ItemChanged += new EventHandler<EventArgs<int>>(ServiceTime_ItemChanged);
|
---|
| 405 | ServiceTime.Reset += new EventHandler(ServiceTime_Reset);
|
---|
| 406 | VehiclesParameter.ValueChanged += new EventHandler(VehiclesParameter_ValueChanged);
|
---|
| 407 | Vehicles.ValueChanged += new EventHandler(Vehicles_ValueChanged);
|
---|
[4620] | 408 |
|
---|
| 409 | BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);
|
---|
[3938] | 410 | }
|
---|
[4619] | 411 |
|
---|
[3938] | 412 | private void InitializeOperators() {
|
---|
[6938] | 413 | Operators.Add(new BestVRPSolutionAnalyzer());
|
---|
| 414 | Operators.Add(new BestAverageWorstVRPToursAnalyzer());
|
---|
[3938] | 415 | ParameterizeAnalyzer();
|
---|
[6938] | 416 | Operators.AddRange(ApplicationManager.Manager.GetInstances<IVRPOperator>().Cast<IOperator>().OrderBy(op => op.Name));
|
---|
[3938] | 417 | ParameterizeOperators();
|
---|
| 418 | UpdateMoveEvaluators();
|
---|
| 419 | }
|
---|
| 420 | private void UpdateMoveEvaluators() {
|
---|
| 421 | ParameterizeOperators();
|
---|
| 422 | OnOperatorsChanged();
|
---|
| 423 | }
|
---|
| 424 | private void ParameterizeSolutionCreator() {
|
---|
| 425 | SolutionCreator.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
| 426 | SolutionCreator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
| 427 | Evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
| 428 | Evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
| 429 | SolutionCreator.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
| 430 | SolutionCreator.DemandParameter.ActualName = DemandParameter.Name;
|
---|
| 431 | SolutionCreator.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
| 432 | SolutionCreator.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
| 433 | SolutionCreator.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
| 434 | }
|
---|
| 435 | private void ParameterizeEvaluator() {
|
---|
[4179] | 436 | Evaluator.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
[3938] | 437 | Evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
| 438 | Evaluator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
| 439 | Evaluator.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
| 440 | Evaluator.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
| 441 | Evaluator.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
| 442 | Evaluator.DemandParameter.ActualName = DemandParameter.Name;
|
---|
| 443 | Evaluator.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
| 444 | Evaluator.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
| 445 | Evaluator.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
[4619] | 446 | Evaluator.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
|
---|
| 447 | Evaluator.TimeFactor.ActualName = TimeFactorParameter.Name;
|
---|
| 448 | Evaluator.DistanceFactor.ActualName = DistanceFactorParameter.Name;
|
---|
| 449 | Evaluator.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
|
---|
| 450 | Evaluator.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
|
---|
[3938] | 451 | }
|
---|
| 452 | private void ParameterizeAnalyzer() {
|
---|
| 453 | BestVRPSolutionAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
| 454 | BestVRPSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
| 455 | BestVRPSolutionAnalyzer.DistanceParameter.ActualName = Evaluator.DistanceParameter.ActualName;
|
---|
| 456 | BestVRPSolutionAnalyzer.OverloadParameter.ActualName = Evaluator.OverloadParameter.ActualName;
|
---|
| 457 | BestVRPSolutionAnalyzer.TardinessParameter.ActualName = Evaluator.TardinessParameter.ActualName;
|
---|
[4352] | 458 | BestVRPSolutionAnalyzer.TravelTimeParameter.ActualName = Evaluator.TravelTimeParameter.ActualName;
|
---|
| 459 | BestVRPSolutionAnalyzer.VehiclesUtilizedParameter.ActualName = Evaluator.VehcilesUtilizedParameter.ActualName;
|
---|
[4179] | 460 | BestVRPSolutionAnalyzer.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
[3938] | 461 | BestVRPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
[4352] | 462 |
|
---|
| 463 | BestAverageWorstVRPToursAnalyzer.DistanceParameter.ActualName = Evaluator.DistanceParameter.ActualName;
|
---|
| 464 | BestAverageWorstVRPToursAnalyzer.OverloadParameter.ActualName = Evaluator.OverloadParameter.ActualName;
|
---|
| 465 | BestAverageWorstVRPToursAnalyzer.TardinessParameter.ActualName = Evaluator.TardinessParameter.ActualName;
|
---|
| 466 | BestAverageWorstVRPToursAnalyzer.TravelTimeParameter.ActualName = Evaluator.TravelTimeParameter.ActualName;
|
---|
| 467 | BestAverageWorstVRPToursAnalyzer.VehiclesUtilizedParameter.ActualName = Evaluator.VehcilesUtilizedParameter.ActualName;
|
---|
| 468 | BestAverageWorstVRPToursAnalyzer.ResultsParameter.ActualName = "Results";
|
---|
[3938] | 469 | }
|
---|
| 470 | private void ParameterizeOperators() {
|
---|
[4154] | 471 | foreach (IVRPOperator op in Operators.OfType<IVRPOperator>()) {
|
---|
[4722] | 472 | if (op.CoordinatesParameter != null) op.CoordinatesParameter.ActualName = CoordinatesParameter.Name;
|
---|
| 473 | if (op.DistanceMatrixParameter != null) op.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name;
|
---|
| 474 | if (op.UseDistanceMatrixParameter != null) op.UseDistanceMatrixParameter.ActualName = UseDistanceMatrixParameter.Name;
|
---|
| 475 | if (op.VehiclesParameter != null) op.VehiclesParameter.ActualName = VehiclesParameter.Name;
|
---|
| 476 | if (op.CapacityParameter != null) op.CapacityParameter.ActualName = CapacityParameter.Name;
|
---|
| 477 | if (op.DemandParameter != null) op.DemandParameter.ActualName = DemandParameter.Name;
|
---|
| 478 | if (op.ReadyTimeParameter != null) op.ReadyTimeParameter.ActualName = ReadyTimeParameter.Name;
|
---|
| 479 | if (op.DueTimeParameter != null) op.DueTimeParameter.ActualName = DueTimeParameter.Name;
|
---|
| 480 | if (op.ServiceTimeParameter != null) op.ServiceTimeParameter.ActualName = ServiceTimeParameter.Name;
|
---|
[4154] | 481 | }
|
---|
[4722] | 482 |
|
---|
[4154] | 483 | foreach (IVRPMoveOperator op in Operators.OfType<IVRPMoveOperator>()) {
|
---|
[4179] | 484 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
[4154] | 485 | }
|
---|
| 486 |
|
---|
[4352] | 487 | foreach (IPrinsOperator op in Operators.OfType<IPrinsOperator>()) {
|
---|
[4619] | 488 | op.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
|
---|
| 489 | op.TimeFactor.ActualName = TimeFactorParameter.Name;
|
---|
| 490 | op.DistanceFactor.ActualName = DistanceFactorParameter.Name;
|
---|
| 491 | op.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
|
---|
| 492 | op.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
|
---|
[4352] | 493 | }
|
---|
| 494 |
|
---|
[4154] | 495 | foreach (IVRPMoveEvaluator op in Operators.OfType<IVRPMoveEvaluator>()) {
|
---|
[4619] | 496 | op.FleetUsageFactor.ActualName = FleetUsageFactorParameter.Name;
|
---|
| 497 | op.TimeFactor.ActualName = TimeFactorParameter.Name;
|
---|
| 498 | op.DistanceFactor.ActualName = DistanceFactorParameter.Name;
|
---|
| 499 | op.OverloadPenalty.ActualName = OverloadPenaltyParameter.Name;
|
---|
| 500 | op.TardinessPenalty.ActualName = TardinessPenaltyParameter.Name;
|
---|
[4154] | 501 | op.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
|
---|
[4179] | 502 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
[3938] | 503 | }
|
---|
[4047] | 504 | string translocationMove = Operators.OfType<IMoveGenerator>().OfType<IAlbaTranslocationMoveOperator>().First().TranslocationMoveParameter.ActualName;
|
---|
| 505 | foreach (IAlbaTranslocationMoveOperator op in Operators.OfType<IAlbaTranslocationMoveOperator>())
|
---|
[3938] | 506 | op.TranslocationMoveParameter.ActualName = translocationMove;
|
---|
| 507 |
|
---|
| 508 | foreach (IVRPCrossover op in Operators.OfType<IVRPCrossover>()) {
|
---|
[4179] | 509 | op.ParentsParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
| 510 | op.ChildParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
[3938] | 511 | }
|
---|
[4150] | 512 |
|
---|
[3938] | 513 | foreach (IVRPManipulator op in Operators.OfType<IVRPManipulator>()) {
|
---|
[4179] | 514 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
[3938] | 515 | }
|
---|
[6042] | 516 |
|
---|
| 517 | foreach (var op in Operators.OfType<IVRPMultiNeighborhoodShakingOperator>()) {
|
---|
| 518 | op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
|
---|
| 519 | }
|
---|
[3938] | 520 | }
|
---|
| 521 | private void ClearDistanceMatrix() {
|
---|
| 522 | DistanceMatrixParameter.Value = null;
|
---|
| 523 | }
|
---|
| 524 | #endregion
|
---|
[4098] | 525 |
|
---|
| 526 | public void ImportFromSolomon(string solomonFileName) {
|
---|
| 527 | SolomonParser parser = new SolomonParser(solomonFileName);
|
---|
| 528 | parser.Parse();
|
---|
| 529 |
|
---|
| 530 | this.Name = parser.ProblemName;
|
---|
| 531 |
|
---|
[4847] | 532 | BestKnownSolution = null;
|
---|
[4098] | 533 | Coordinates = new DoubleMatrix(parser.Coordinates);
|
---|
| 534 | Vehicles.Value = parser.Vehicles;
|
---|
| 535 | Capacity.Value = parser.Capacity;
|
---|
| 536 | Demand = new DoubleArray(parser.Demands);
|
---|
| 537 | ReadyTime = new DoubleArray(parser.Readytimes);
|
---|
| 538 | DueTime = new DoubleArray(parser.Duetimes);
|
---|
| 539 | ServiceTime = new DoubleArray(parser.Servicetimes);
|
---|
| 540 |
|
---|
| 541 | OnReset();
|
---|
| 542 | }
|
---|
[4138] | 543 |
|
---|
[4352] | 544 | public void ImportFromTSPLib(string tspFileName) {
|
---|
| 545 | TSPLIBParser parser = new TSPLIBParser(tspFileName);
|
---|
| 546 | parser.Parse();
|
---|
| 547 |
|
---|
| 548 | this.Name = parser.Name;
|
---|
| 549 | int problemSize = parser.Demands.Length;
|
---|
| 550 |
|
---|
[4847] | 551 | BestKnownSolution = null;
|
---|
[4352] | 552 | Coordinates = new DoubleMatrix(parser.Vertices);
|
---|
| 553 | if (parser.Vehicles != -1)
|
---|
| 554 | Vehicles.Value = parser.Vehicles;
|
---|
[4722] | 555 | else
|
---|
[4352] | 556 | Vehicles.Value = problemSize - 1;
|
---|
| 557 | Capacity.Value = parser.Capacity;
|
---|
| 558 | Demand = new DoubleArray(parser.Demands);
|
---|
| 559 | ReadyTime = new DoubleArray(problemSize);
|
---|
| 560 | DueTime = new DoubleArray(problemSize);
|
---|
| 561 | ServiceTime = new DoubleArray(problemSize);
|
---|
| 562 |
|
---|
| 563 | for (int i = 0; i < problemSize; i++) {
|
---|
| 564 | ReadyTime[i] = 0;
|
---|
| 565 | DueTime[i] = int.MaxValue;
|
---|
| 566 | ServiceTime[i] = 0;
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | if (parser.Distance != -1) {
|
---|
| 570 | DueTime[0] = parser.Distance;
|
---|
| 571 | }
|
---|
| 572 |
|
---|
| 573 | if (parser.Depot != 1)
|
---|
[4847] | 574 | ErrorHandling.ShowErrorDialog(new Exception("Invalid depot specification"));
|
---|
[4352] | 575 |
|
---|
| 576 | if (parser.WeightType != TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D)
|
---|
[4847] | 577 | ErrorHandling.ShowErrorDialog(new Exception("Invalid weight type"));
|
---|
[4352] | 578 |
|
---|
| 579 | OnReset();
|
---|
| 580 | }
|
---|
| 581 |
|
---|
[4619] | 582 | private void EvalBestKnownSolution() {
|
---|
| 583 | if (BestKnownSolution != null) {
|
---|
| 584 | //call evaluator
|
---|
[4852] | 585 | IValueParameter<DoubleMatrix> distMatrix = new ValueLookupParameter<DoubleMatrix>("DistMatrix",
|
---|
[4619] | 586 | DistanceMatrix);
|
---|
| 587 |
|
---|
| 588 | TourEvaluation eval = VRPEvaluator.Evaluate(
|
---|
[4852] | 589 | BestKnownSolution,
|
---|
[4619] | 590 | Vehicles,
|
---|
| 591 | DueTime,
|
---|
| 592 | ServiceTime,
|
---|
| 593 | ReadyTime,
|
---|
| 594 | Demand,
|
---|
| 595 | Capacity,
|
---|
| 596 | FleetUsageFactorParameter.Value,
|
---|
| 597 | TimeFactorParameter.Value,
|
---|
| 598 | DistanceFactorParameter.Value,
|
---|
| 599 | OverloadPenaltyParameter.Value,
|
---|
| 600 | TardinessPenaltyParameter.Value,
|
---|
| 601 | Coordinates,
|
---|
| 602 | distMatrix,
|
---|
| 603 | UseDistanceMatrix);
|
---|
| 604 |
|
---|
| 605 | DistanceMatrix = distMatrix.Value;
|
---|
| 606 |
|
---|
| 607 | BestKnownQuality = new DoubleValue(eval.Quality);
|
---|
| 608 | } else {
|
---|
| 609 | BestKnownQuality = null;
|
---|
| 610 | }
|
---|
| 611 | }
|
---|
| 612 |
|
---|
| 613 | public void ImportSolution(string solutionFileName) {
|
---|
| 614 | SolutionParser parser = new SolutionParser(solutionFileName);
|
---|
| 615 | parser.Parse();
|
---|
| 616 |
|
---|
| 617 | HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding encoding = new Encodings.Potvin.PotvinEncoding();
|
---|
| 618 |
|
---|
| 619 | int cities = 0;
|
---|
| 620 | foreach (List<int> route in parser.Routes) {
|
---|
| 621 | Encodings.Tour tour = new Encodings.Tour();
|
---|
| 622 | tour.Cities.AddRange(route);
|
---|
| 623 | cities += tour.Cities.Count;
|
---|
| 624 |
|
---|
| 625 | encoding.Tours.Add(tour);
|
---|
| 626 | }
|
---|
| 627 |
|
---|
| 628 | if (cities != Coordinates.Rows - 1)
|
---|
[4857] | 629 | ErrorHandling.ShowErrorDialog(new Exception("The optimal solution does not seem to correspond with the problem data."));
|
---|
[4852] | 630 | else
|
---|
| 631 | BestKnownSolutionParameter.Value = encoding;
|
---|
[4619] | 632 | }
|
---|
| 633 |
|
---|
[4352] | 634 | public void ImportFromORLib(string orFileName) {
|
---|
| 635 | ORLIBParser parser = new ORLIBParser(orFileName);
|
---|
| 636 | parser.Parse();
|
---|
| 637 |
|
---|
| 638 | this.Name = parser.Name;
|
---|
| 639 | int problemSize = parser.Demands.Length;
|
---|
| 640 |
|
---|
[4847] | 641 | BestKnownSolution = null;
|
---|
[4352] | 642 | Coordinates = new DoubleMatrix(parser.Vertices);
|
---|
| 643 | Vehicles.Value = problemSize - 1;
|
---|
| 644 | Capacity.Value = parser.Capacity;
|
---|
| 645 | Demand = new DoubleArray(parser.Demands);
|
---|
| 646 | ReadyTime = new DoubleArray(problemSize);
|
---|
| 647 | DueTime = new DoubleArray(problemSize);
|
---|
| 648 | ServiceTime = new DoubleArray(problemSize);
|
---|
| 649 |
|
---|
| 650 | ReadyTime[0] = 0;
|
---|
| 651 | DueTime[0] = parser.MaxRouteTime;
|
---|
| 652 | ServiceTime[0] = 0;
|
---|
| 653 |
|
---|
| 654 | for (int i = 1; i < problemSize; i++) {
|
---|
| 655 | ReadyTime[i] = 0;
|
---|
| 656 | DueTime[i] = int.MaxValue;
|
---|
| 657 | ServiceTime[i] = parser.ServiceTime;
|
---|
| 658 | }
|
---|
| 659 |
|
---|
| 660 | OnReset();
|
---|
| 661 | }
|
---|
| 662 |
|
---|
[4138] | 663 | private void InitializeRandomVRPInstance() {
|
---|
| 664 | System.Random rand = new System.Random();
|
---|
| 665 |
|
---|
| 666 | int cities = 100;
|
---|
| 667 |
|
---|
| 668 | Coordinates = new DoubleMatrix(cities + 1, 2);
|
---|
| 669 | Demand = new DoubleArray(cities + 1);
|
---|
| 670 | DueTime = new DoubleArray(cities + 1);
|
---|
| 671 | ReadyTime = new DoubleArray(cities + 1);
|
---|
| 672 | ServiceTime = new DoubleArray(cities + 1);
|
---|
| 673 |
|
---|
| 674 | Vehicles.Value = 100;
|
---|
| 675 | Capacity.Value = 200;
|
---|
| 676 |
|
---|
| 677 | for (int i = 0; i <= cities; i++) {
|
---|
| 678 | Coordinates[i, 0] = rand.Next(0, 100);
|
---|
| 679 | Coordinates[i, 1] = rand.Next(0, 100);
|
---|
| 680 |
|
---|
| 681 | if (i == 0) {
|
---|
| 682 | Demand[i] = 0;
|
---|
| 683 | DueTime[i] = Int16.MaxValue;
|
---|
| 684 | ReadyTime[i] = 0;
|
---|
| 685 | ServiceTime[i] = 0;
|
---|
| 686 | } else {
|
---|
| 687 | Demand[i] = rand.Next(10, 50);
|
---|
[4154] | 688 | DueTime[i] = rand.Next((int)Math.Ceiling(VRPUtilities.CalculateDistance(0, i, Coordinates)), 1200);
|
---|
[4138] | 689 | ReadyTime[i] = DueTime[i] - rand.Next(0, 100);
|
---|
| 690 | ServiceTime[i] = 90;
|
---|
| 691 | }
|
---|
| 692 | }
|
---|
| 693 | }
|
---|
[3938] | 694 | }
|
---|
| 695 | }
|
---|