using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.PDPSimulation.DomainModel; using HeuristicLab.PDPSimulation.DistanceMeasures; namespace HeuristicLab.PDPSimulation { [StorableClass] public class WaitAction: PDAction { [Storable] double waitingTime; public WaitAction(Guid vehicleId, double waitingTime) : base(vehicleId) { this.waitingTime = waitingTime; } [StorableConstructor] protected WaitAction(bool deserializing) : base(deserializing) { } protected WaitAction(WaitAction original, Cloner cloner) : base(original, cloner) { this.waitingTime = original.waitingTime; } public override IDeepCloneable Clone(Cloner cloner) { return new WaitAction(this, cloner); } protected override bool ActionInterruptable() { return true; } public override bool ActionCompleted() { return waitingTime <= double.Epsilon; } protected override double Perform(BaseObject baseObject, double simulationTime, double tickTime, List changes) { double time = Math.Min(tickTime, waitingTime); waitingTime -= time; simulationTime += time; Vehicle vehicle = baseObject as Vehicle; lock (vehicle) { if ((time > 0) && (vehicle.VehicleState != VehicleState.Waiting) && (vehicle.VehicleState != VehicleState.Parked)) { vehicle.ReadyTime = 0; vehicle.VehicleState = VehicleState.Waiting; changes.Add(new PDChange() { ChangeType = SimulationStateChange.VehicleState, BaseObject = baseObject }); } } return simulationTime; } } }