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