Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/Operators/DynPDPProblemInstance.cs @ 8858

Last change on this file since 8858 was 8714, checked in by svonolfe, 12 years ago

Added support for dynamic dial a ride

File size: 7.0 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Problems.VehicleRouting.Interfaces;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Core;
29using HeuristicLab.Parameters;
30using HeuristicLab.Data;
31using HeuristicLab.Optimization;
32using HeuristicLab.PluginInfrastructure;
33using HeuristicLab.Problems.VehicleRouting.Variants;
34using HeuristicLab.Common;
35using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
36using HeuristicLab.PDPSimulation.DistanceMeasures;
37using HeuristicLab.PDPSimulation.DomainModel;
38using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin;
39using System.Threading;
40
41namespace HeuristicLab.PDPSimulation.Operators {
42  [Item("DynPDPProblemInstance", "Represents a dynamic multi depot CVRPPDTW instance.")]
43  [StorableClass]
44  public class DynPDPProblemInstance: MDCVRPPDTWProblemInstance {
45    protected ValueParameter<DoubleMatrix> DepotCoordinatesParameter {
46      get { return (ValueParameter<DoubleMatrix>)Parameters["DepotCoordinates"]; }
47    }
48
49    protected ValueParameter<BoolArray> VehicleUsedParameter {
50      get { return (ValueParameter<BoolArray>)Parameters["VehicleUsed"]; }
51    }
52
53    [Storable]
54    public List<VehicleState> VehicleStates {
55      get;
56      set;
57    }
58
59    [Storable]
60    public PotvinEncoding CurrentPlan {
61      get;
62      set;
63    }
64
65    public BoolArray VehicleUsed {
66      get { return VehicleUsedParameter.Value; }
67      set { VehicleUsedParameter.Value = value; }
68    }
69
70    public DoubleMatrix DepotCoordinates {
71      get { return DepotCoordinatesParameter.Value; }
72      set { DepotCoordinatesParameter.Value = value; }
73    }
74
75    protected override IVRPCreator Creator {
76      get {
77        return new DynPushForwardInsertionCreator();
78      }
79    }
80   
81    protected override IVRPEvaluator Evaluator {
82      get {
83        return new DynPDPEvaluator();
84      }
85    }
86
87    public Barrier AlgorithmSyncObject {
88      get;
89      set;
90    }
91
92    public Barrier AnalyzerSyncObject {
93      get;
94      set;
95    }
96
97    [Storable]
98    private ResultCollection results;
99
100    public ResultCollection Results {
101      get {
102        return results;
103      }
104    }
105
106    [Storable]
107    private PickupDeliveryScenario scenario;
108
109    public bool RelocateBackToDepot {
110      get {
111        return scenario.RelocateBackToDepot;
112      }
113    }
114
115    public double Horizon {
116      get {
117        return scenario.VehicleDueTimesParameter.Value.Max();
118      }
119    }
120
121    [Storable]
122    protected WaitingStrategy waitingStrategy;
123
124    public WaitingStrategy WaitingStrategy {
125      get {
126        return waitingStrategy;
127      }
128
129      set {
130        waitingStrategy = value;
131      }
132    }
133   
134    [StorableConstructor]
135    protected DynPDPProblemInstance(bool deserializing) : base(deserializing) { }
136   
137    public DynPDPProblemInstance(PickupDeliveryScenario scenario, ResultCollection results)
138      : base() {
139      Parameters.Add(new ValueParameter<DoubleMatrix>("DepotCoordinates", "The x- and y-Coordinates of the depots.", new DoubleMatrix()));
140      Parameters.Add(new ValueParameter<BoolArray>("VehicleUsed", "Indicates, if a vehicle has been used.", new BoolArray()));
141
142      this.scenario = scenario;
143      this.results = results;
144      VehicleStates = new List<VehicleState>();
145
146      if (scenario != null) {
147        SolutionEvaluator = scenario.Evaluator;
148      }
149    }
150
151    public override IDeepCloneable Clone(Cloner cloner) {
152      return new DynPDPProblemInstance(this, cloner);
153    }
154
155    protected DynPDPProblemInstance(DynPDPProblemInstance original, Cloner cloner)
156      : base(original, cloner) {
157        this.scenario = cloner.Clone<PickupDeliveryScenario>(original.scenario);
158        this.SolutionEvaluator = cloner.Clone<IVRPEvaluator>(original.SolutionEvaluator);
159        this.results = cloner.Clone<ResultCollection>(original.results);
160        this.waitingStrategy = cloner.Clone<WaitingStrategy>(original.waitingStrategy);
161        this.VehicleStates = new List<VehicleState>(original.VehicleStates);
162        this.CurrentPlan = cloner.Clone<PotvinEncoding>(CurrentPlan);
163    }
164
165    public DynPDPProblemInstance ShallowClone() {
166      Cloner cloner = new Cloner();
167      return new DynPDPProblemInstance(this, cloner, true);
168    }
169
170    protected DynPDPProblemInstance(DynPDPProblemInstance original, Cloner cloner, bool shallow)
171      : base(original, cloner) {
172      this.scenario = original.scenario;
173      this.SolutionEvaluator = cloner.Clone<IVRPEvaluator>(original.SolutionEvaluator);
174      this.results = original.results;
175      this.waitingStrategy = original.waitingStrategy;
176      this.VehicleStates = original.VehicleStates;
177      this.CurrentPlan =  cloner.Clone<PotvinEncoding>(CurrentPlan);
178    }
179
180    protected override double CalculateDistance(int start, int end) {
181      double distance = 0.0;
182
183      if (end < Depots.Value) {
184        distance =
185          scenario.DistanceMeasure.GetDistance(Coordinates[start, 0], Coordinates[start, 1], DepotCoordinates[end, 0], DepotCoordinates[end, 1]);
186      } else {
187        distance =
188          scenario.DistanceMeasure.GetDistance(Coordinates[start, 0], Coordinates[start, 1], Coordinates[end, 0], Coordinates[end, 1]);
189      }
190
191      return distance;
192    }
193
194    public double GetDistance(int start, int end) {
195      return CalculateDistance(start, end);
196    }
197
198    public double GetDistanceToDepot(int vehicle) {
199      return CalculateDistance(vehicle, vehicle);
200    }
201
202    public void ResetDistanceMatrix() {
203      UseDistanceMatrixParameter.Value = new BoolValue(false);
204      DistanceMatrixParameter.Value = null;
205
206      UseDistanceMatrixParameter.Value = new BoolValue(true);
207    }
208
209    public void Initialize() {
210      PickupViolationPenalty.Value = scenario.PickupViolationPenaltyParameter.Value.Value;
211      OverloadPenalty.Value = scenario.OverloadPenaltyParameter.Value.Value;
212      TardinessPenalty.Value = scenario.TardinessPenaltyParameter.Value.Value;
213      FleetUsageFactor.Value = scenario.FleetUsageFactorParameter.Value.Value;
214      DistanceFactor.Value = scenario.DistanceFactorParameter.Value.Value;
215    }
216  }
217}
Note: See TracBrowser for help on using the repository browser.