1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.PDPSimulation.SimulationCore;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 | using HeuristicLab.Common;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Data;
|
---|
32 | using HeuristicLab.PDPSimulation.DomainModel;
|
---|
33 | using HeuristicLab.PDPSimulation.DistanceMeasures;
|
---|
34 | using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
|
---|
35 | using HeuristicLab.PDPSimulation.Operators;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.PDPSimulation {
|
---|
38 | [Item("PickupDeliveryScenario", "A pickup and delivery scenario.")]
|
---|
39 | [StorableClass]
|
---|
40 | public sealed class PickupDeliveryScenario: Scenario {
|
---|
41 | public event EventHandler ScenarioChanged;
|
---|
42 |
|
---|
43 | public ValueParameter<DistanceMeasure> DistanceMeasureParameter {
|
---|
44 | get { return (ValueParameter<DistanceMeasure>)Parameters["DistanceMeasure"]; }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public ValueParameter<BoolValue> AllowDiversionParameter {
|
---|
48 | get { return (ValueParameter<BoolValue>)Parameters["AllowDiversion"]; }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public ValueParameter<DoubleMatrix> DepotCoordinatesParameter {
|
---|
52 | get { return (ValueParameter<DoubleMatrix>)Parameters["DepotCoordinates"]; }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public ValueParameter<DoubleArray> VehicleCapacitiesParameter {
|
---|
56 | get { return (ValueParameter<DoubleArray>)Parameters["VehicleCapacities"]; }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public ValueParameter<DoubleArray> VehicleReadyTimesParameter {
|
---|
60 | get { return (ValueParameter<DoubleArray>)Parameters["VehicleReadyTimes"]; }
|
---|
61 | }
|
---|
62 |
|
---|
63 | public ValueParameter<DoubleArray> VehicleDueTimesParameter {
|
---|
64 | get { return (ValueParameter<DoubleArray>)Parameters["VehicleDueTimes"]; }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public OptionalValueParameter<PickupDeliveryOrderGenerator> OrderGeneratorParameter {
|
---|
68 | get { return (OptionalValueParameter<PickupDeliveryOrderGenerator>)Parameters["PickupDeliveryOrderGenerator"]; }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public ValueParameter<MDCVRPTWEvaluator> EvaluatorParameter {
|
---|
72 | get { return (ValueParameter<MDCVRPTWEvaluator>)Parameters["Evaluator"]; }
|
---|
73 | }
|
---|
74 |
|
---|
75 | public IValueParameter<DoubleValue> FleetUsageFactorParameter {
|
---|
76 | get { return (IValueParameter<DoubleValue>)Parameters["FleetUsageFactor"]; }
|
---|
77 | }
|
---|
78 |
|
---|
79 | public IValueParameter<DoubleValue> OverloadPenaltyParameter {
|
---|
80 | get { return (IValueParameter<DoubleValue>)Parameters["OverloadPenalty"]; }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public IValueParameter<DoubleValue> TardinessPenaltyParameter {
|
---|
84 | get { return (IValueParameter<DoubleValue>)Parameters["TardinessPenalty"]; }
|
---|
85 | }
|
---|
86 |
|
---|
87 | public IValueParameter<DoubleValue> PickupViolationPenaltyParameter {
|
---|
88 | get { return (IValueParameter<DoubleValue>)Parameters["PickupViolationPenalty"]; }
|
---|
89 | }
|
---|
90 |
|
---|
91 | public IValueParameter<BoolValue> RelocateBackToDepotParameter {
|
---|
92 | get { return (IValueParameter<BoolValue>)Parameters["RelocateBackToDepot"]; }
|
---|
93 | }
|
---|
94 |
|
---|
95 | public DistanceMeasure DistanceMeasure {
|
---|
96 | get {
|
---|
97 | return DistanceMeasureParameter.Value;
|
---|
98 | }
|
---|
99 | set {
|
---|
100 | DistanceMeasureParameter.Value = value;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | public PickupDeliveryOrderGenerator OrderGenerator {
|
---|
105 | get {
|
---|
106 | return OrderGeneratorParameter.Value;
|
---|
107 | }
|
---|
108 | set {
|
---|
109 | OrderGeneratorParameter.Value = value;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | public MDCVRPTWEvaluator Evaluator {
|
---|
114 | get {
|
---|
115 | return EvaluatorParameter.Value;
|
---|
116 | }
|
---|
117 |
|
---|
118 | set {
|
---|
119 | EvaluatorParameter.Value = value;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | public bool AllowDiversion {
|
---|
124 | get {
|
---|
125 | return AllowDiversionParameter.Value.Value &&
|
---|
126 | DistanceMeasure.DiversionSupported;
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | public bool RelocateBackToDepot {
|
---|
131 | get {
|
---|
132 | return RelocateBackToDepotParameter.Value.Value;
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | public PickupDeliveryScenario() : base() {
|
---|
137 | Parameters.Add(new ValueParameter<DistanceMeasure>("DistanceMeasure", new EuclideanDistanceMeasure()));
|
---|
138 | Parameters.Add(new ValueParameter<BoolValue>("AllowDiversion", new BoolValue(false)));
|
---|
139 | Parameters.Add(new ValueParameter<DoubleMatrix>("DepotCoordinates", new DoubleMatrix()));
|
---|
140 | Parameters.Add(new ValueParameter<BoolValue>("RelocateBackToDepot", new BoolValue(true)));
|
---|
141 | Parameters.Add(new ValueParameter<DoubleArray>("VehicleCapacities", new DoubleArray()));
|
---|
142 | Parameters.Add(new ValueParameter<DoubleArray>("VehicleReadyTimes", new DoubleArray()));
|
---|
143 | Parameters.Add(new ValueParameter<DoubleArray>("VehicleDueTimes", new DoubleArray()));
|
---|
144 | Parameters.Add(new ValueParameter<DoubleValue>("FleetUsageFactor", "The fleet usage factor considered in the evaluation.", new DoubleValue(3000)));
|
---|
145 | Parameters.Add(new ValueParameter<DoubleValue>("OverloadPenalty", "The overload penalty considered in the evaluation.", new DoubleValue(10000)));
|
---|
146 | Parameters.Add(new ValueParameter<DoubleValue>("TardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(10000)));
|
---|
147 | Parameters.Add(new ValueParameter<DoubleValue>("PickupViolationPenalty", "The pickup violation penalty considered in the evaluation.", new DoubleValue(1000000)));
|
---|
148 | Parameters.Add(new OptionalValueParameter<PickupDeliveryOrderGenerator>("PickupDeliveryOrderGenerator"));
|
---|
149 | Parameters.Add(new ValueParameter<MDCVRPTWEvaluator>("Evaluator", new DynPDPEvaluator()));
|
---|
150 |
|
---|
151 | DepotCoordinatesParameter.GetsCollected = false;
|
---|
152 | VehicleCapacitiesParameter.GetsCollected = false;
|
---|
153 | VehicleReadyTimesParameter.GetsCollected = false;
|
---|
154 | VehicleDueTimesParameter.GetsCollected = false;
|
---|
155 | OrderGeneratorParameter.GetsCollected = false;
|
---|
156 | DistanceMeasureParameter.GetsCollected = false;
|
---|
157 | }
|
---|
158 |
|
---|
159 | [StorableHook(HookType.AfterDeserialization)]
|
---|
160 | private void AfterDeserialization() {
|
---|
161 | if (!Parameters.ContainsKey("Evaluator")) {
|
---|
162 | Parameters.Add(new ValueParameter<MDCVRPTWEvaluator>("Evaluator", new DynPDPEvaluator()));
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | public IEnumerable<Order> GetOrders(double timeStart, double timeEnd) {
|
---|
167 | return OrderGeneratorParameter.Value.GetOrders(timeStart, timeEnd);
|
---|
168 | }
|
---|
169 |
|
---|
170 | public bool MoreOrders(double time) {
|
---|
171 | return OrderGeneratorParameter.Value.MoreOrders(time);
|
---|
172 | }
|
---|
173 |
|
---|
174 | public double OrderRangeX() {
|
---|
175 | return OrderGeneratorParameter.Value.RangeX();
|
---|
176 | }
|
---|
177 |
|
---|
178 | public double OrderRangeY() {
|
---|
179 | return OrderGeneratorParameter.Value.RangeY();
|
---|
180 | }
|
---|
181 |
|
---|
182 | private void OnScenarioChanged() {
|
---|
183 | if (ScenarioChanged != null)
|
---|
184 | ScenarioChanged(this, null);
|
---|
185 | }
|
---|
186 |
|
---|
187 | private void ImportFromDynPDP(DynPDPParser parser) {
|
---|
188 | parser.Parse();
|
---|
189 |
|
---|
190 | int vehicles = parser.Vehicles.Length;
|
---|
191 | DoubleMatrix depotCoordinates = new DoubleMatrix(vehicles, 2);
|
---|
192 | DoubleArray vehicleCapacities = new DoubleArray(vehicles);
|
---|
193 | DoubleArray vehicleReadyTimes = new DoubleArray(vehicles);
|
---|
194 | DoubleArray vehicleDueTimes = new DoubleArray(vehicles);
|
---|
195 |
|
---|
196 | for (int i = 0; i < vehicles; i++) {
|
---|
197 | DynPDPParser.Vehicle vehicle = parser.Vehicles[i];
|
---|
198 | depotCoordinates[i, 0] = vehicle.xCoord;
|
---|
199 | depotCoordinates[i, 1] = vehicle.yCoord;
|
---|
200 | vehicleCapacities[i] = vehicle.capacity;
|
---|
201 | vehicleReadyTimes[i] = vehicle.readyTime;
|
---|
202 | vehicleDueTimes[i] = vehicle.dueTime;
|
---|
203 | }
|
---|
204 | DepotCoordinatesParameter.Value = depotCoordinates;
|
---|
205 | VehicleCapacitiesParameter.Value = vehicleCapacities;
|
---|
206 | VehicleReadyTimesParameter.Value = vehicleReadyTimes;
|
---|
207 | VehicleDueTimesParameter.Value = vehicleDueTimes;
|
---|
208 |
|
---|
209 | PickupDeliveryPredefinedOrderGenerator orderGen = new PickupDeliveryPredefinedOrderGenerator();
|
---|
210 | int orders = parser.Orders.Length;
|
---|
211 |
|
---|
212 | DoubleMatrix orderMatrix = new DoubleMatrix(orders, 12,
|
---|
213 | new string[] { "Time revealed", "P X coordinate", "P Y coordinate", "D X coordinate", "D Y coordinate",
|
---|
214 | "Demand", "P service time", "P ready time", "P due time", "D service time", "D ready time", "D due time"});
|
---|
215 | for (int i = 0; i < orders; i++) {
|
---|
216 | DynPDPParser.Order order = parser.Orders[i];
|
---|
217 |
|
---|
218 | orderMatrix[i, 0] = order.revealedTime;
|
---|
219 | orderMatrix[i, 1] = order.pickupXCoord;
|
---|
220 | orderMatrix[i, 2] = order.pickupYCoord;
|
---|
221 | orderMatrix[i, 3] = order.deliveryXCoord;
|
---|
222 | orderMatrix[i, 4] = order.deliveryYCoord;
|
---|
223 | orderMatrix[i, 5] = order.demand;
|
---|
224 | orderMatrix[i, 6] = order.pickupServiceTime;
|
---|
225 | orderMatrix[i, 7] = order.pickupReadyTime;
|
---|
226 | orderMatrix[i, 8] = order.pickupDueTime;
|
---|
227 | orderMatrix[i, 9] = order.deliveryServiceTime;
|
---|
228 | orderMatrix[i, 10] = order.deliveryReadyTime;
|
---|
229 | orderMatrix[i, 11] = order.deliveryDueTime;
|
---|
230 | }
|
---|
231 | orderGen.OrdersParameter.Value = orderMatrix;
|
---|
232 | OrderGeneratorParameter.Value = orderGen;
|
---|
233 |
|
---|
234 | OnScenarioChanged();
|
---|
235 | }
|
---|
236 |
|
---|
237 | public void ImportFromDynPDP(string fileName) {
|
---|
238 | DefaultDynPDPParser parser = new DefaultDynPDPParser(fileName);
|
---|
239 | ImportFromDynPDP(parser);
|
---|
240 | }
|
---|
241 |
|
---|
242 | public void ImportFromDynTSPLib(string fileName) {
|
---|
243 | TSPLibDynPDPParser parser = new TSPLibDynPDPParser(fileName);
|
---|
244 | ImportFromDynPDP(parser);
|
---|
245 | }
|
---|
246 |
|
---|
247 | [StorableConstructor]
|
---|
248 | private PickupDeliveryScenario(bool deserializing) : base(deserializing) { }
|
---|
249 | private PickupDeliveryScenario(PickupDeliveryScenario original, Cloner cloner)
|
---|
250 | : base(original, cloner) {
|
---|
251 | }
|
---|
252 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
253 | return new PickupDeliveryScenario(this, cloner);
|
---|
254 | }
|
---|
255 | }
|
---|
256 | }
|
---|