[8670] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
| 6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 7 | using HeuristicLab.Common;
|
---|
| 8 | using HeuristicLab.PDPSimulation.Operators;
|
---|
| 9 | using HeuristicLab.Problems.VehicleRouting;
|
---|
| 10 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
| 11 | using HeuristicLab.Parameters;
|
---|
| 12 | using HeuristicLab.Data;
|
---|
| 13 |
|
---|
| 14 | namespace HeuristicLab.PDPSimulation {
|
---|
| 15 | [Item("DriveFirstWaitingStrategy", "A pickup and delivery waiting strategy.")]
|
---|
| 16 | [StorableClass]
|
---|
| 17 | public class DriveFirstWaitingStrategy : WaitingStrategy {
|
---|
| 18 | public ValueParameter<BoolValue> WaitAtSourceParameter {
|
---|
| 19 | get { return (ValueParameter<BoolValue>)Parameters["WaitAtSource"]; }
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | public DriveFirstWaitingStrategy()
|
---|
| 23 | : base() {
|
---|
| 24 | Parameters.Add(new ValueParameter<BoolValue>("WaitAtSource", "Indicates, if waiting should only occur at the source and not the target.", new BoolValue(true)));
|
---|
| 25 | }
|
---|
| 26 | [StorableConstructor]
|
---|
| 27 | protected DriveFirstWaitingStrategy(bool deserializing) : base(deserializing) { }
|
---|
| 28 | protected DriveFirstWaitingStrategy(DriveFirstWaitingStrategy original, Cloner cloner)
|
---|
| 29 | : base(original, cloner) {
|
---|
| 30 | }
|
---|
| 31 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 32 | return new DriveFirstWaitingStrategy(this, cloner);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | public override double GetWaitingTime(double time, DynPDPProblemInstance instance, IVRPEncoding solution, Tour tour, int stop) {
|
---|
| 36 | bool waitAtSource = WaitAtSourceParameter.Value.Value;
|
---|
| 37 |
|
---|
| 38 | if (waitAtSource) {
|
---|
| 39 | double waitTime = 0;
|
---|
| 40 |
|
---|
| 41 | int vehicle = solution.GetVehicleAssignment(solution.GetTourIndex(tour));
|
---|
| 42 | bool moving = instance.VehicleStates[vehicle] == DomainModel.VehicleState.Moving;
|
---|
| 43 | if (!moving || stop != 0) {
|
---|
| 44 | int customer = 0;
|
---|
| 45 | if (stop < tour.Stops.Count)
|
---|
| 46 | customer = tour.Stops[stop];
|
---|
| 47 | int prev = 0;
|
---|
| 48 | if (stop > 0)
|
---|
| 49 | prev = tour.Stops[stop - 1];
|
---|
| 50 |
|
---|
| 51 | if (customer > 0) {
|
---|
| 52 | time += instance.GetDistance(prev, customer, solution);
|
---|
| 53 | double readyTime = instance.ReadyTime[customer + instance.Depots.Value - 1];
|
---|
| 54 | if (time < readyTime) {
|
---|
| 55 | waitTime = readyTime - time;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | return waitTime;
|
---|
| 61 | } else {
|
---|
| 62 | return 0;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | }
|
---|