Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1955_DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/SimulationModel/WaitAction.cs @ 17578

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

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

File size: 1.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6using HeuristicLab.Common;
7using HeuristicLab.PDPSimulation.DomainModel;
8using HeuristicLab.PDPSimulation.DistanceMeasures;
9
10namespace HeuristicLab.PDPSimulation { 
11  [StorableClass]
12  public class WaitAction: PDAction {   
13    [Storable]
14    double waitingTime;
15
16    public WaitAction(Guid vehicleId, double waitingTime)
17      : base(vehicleId) {
18        this.waitingTime = waitingTime;
19    }
20    [StorableConstructor]
21    protected WaitAction(bool deserializing) : base(deserializing) {
22    }
23    protected WaitAction(WaitAction original, Cloner cloner)
24      : base(original, cloner) {
25        this.waitingTime = original.waitingTime;
26    }
27    public override IDeepCloneable Clone(Cloner cloner) {
28      return new WaitAction(this, cloner);
29    }
30
31    protected override bool ActionInterruptable() {
32      return true;
33    }
34
35    public override bool ActionCompleted() {
36      return waitingTime <= double.Epsilon;
37    }
38
39    protected override double Perform(BaseObject baseObject, double simulationTime, double tickTime, List<PDChange> changes) {
40      double time = Math.Min(tickTime, waitingTime);
41      waitingTime -= time;
42
43      simulationTime += time;
44
45      Vehicle vehicle = baseObject as Vehicle;
46      lock (vehicle) {
47        if ((time > 0) && (vehicle.VehicleState != VehicleState.Waiting) && (vehicle.VehicleState != VehicleState.Parked)) {
48          vehicle.ReadyTime = 0;
49          vehicle.VehicleState = VehicleState.Waiting;
50          changes.Add(new PDChange() { ChangeType = SimulationStateChange.VehicleState, BaseObject = baseObject });
51        }
52      }
53
54      return simulationTime;
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.