Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/WaitingStrategies/DriveFirstWaitingStrategy.cs @ 13533

Last change on this file since 13533 was 8670, checked in by svonolfe, 12 years ago

Added first version of the dynamic vehicle routing addon (#1955)

File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using HeuristicLab.Common;
8using HeuristicLab.PDPSimulation.Operators;
9using HeuristicLab.Problems.VehicleRouting;
10using HeuristicLab.Problems.VehicleRouting.Interfaces;
11using HeuristicLab.Parameters;
12using HeuristicLab.Data;
13
14namespace 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}
Note: See TracBrowser for help on using the repository browser.