using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.PDPSimulation.Operators; using HeuristicLab.Problems.VehicleRouting; using HeuristicLab.Problems.VehicleRouting.Interfaces; using HeuristicLab.Parameters; using HeuristicLab.Data; namespace HeuristicLab.PDPSimulation { [Item("DriveFirstWaitingStrategy", "A pickup and delivery waiting strategy.")] [StorableClass] public class DriveFirstWaitingStrategy : WaitingStrategy { public ValueParameter WaitAtSourceParameter { get { return (ValueParameter)Parameters["WaitAtSource"]; } } public DriveFirstWaitingStrategy() : base() { Parameters.Add(new ValueParameter("WaitAtSource", "Indicates, if waiting should only occur at the source and not the target.", new BoolValue(true))); } [StorableConstructor] protected DriveFirstWaitingStrategy(bool deserializing) : base(deserializing) { } protected DriveFirstWaitingStrategy(DriveFirstWaitingStrategy original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new DriveFirstWaitingStrategy(this, cloner); } public override double GetWaitingTime(double time, DynPDPProblemInstance instance, IVRPEncoding solution, Tour tour, int stop) { bool waitAtSource = WaitAtSourceParameter.Value.Value; if (waitAtSource) { double waitTime = 0; int vehicle = solution.GetVehicleAssignment(solution.GetTourIndex(tour)); bool moving = instance.VehicleStates[vehicle] == DomainModel.VehicleState.Moving; if (!moving || stop != 0) { int customer = 0; if (stop < tour.Stops.Count) customer = tour.Stops[stop]; int prev = 0; if (stop > 0) prev = tour.Stops[stop - 1]; if (customer > 0) { time += instance.GetDistance(prev, customer, solution); double readyTime = instance.ReadyTime[customer + instance.Depots.Value - 1]; if (time < readyTime) { waitTime = readyTime - time; } } } return waitTime; } else { return 0; } } } }