1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.PDPSimulation.DomainModel;
|
---|
8 | using HeuristicLab.PDPSimulation.DistanceMeasures;
|
---|
9 |
|
---|
10 | namespace 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)) {
|
---|
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 | }
|
---|