1 package org.opentrafficsim.road.network.sampling;
2
3 import org.djunits.value.vdouble.scalar.Speed;
4 import org.opentrafficsim.base.OtsRuntimeException;
5 import org.opentrafficsim.core.network.NetworkException;
6 import org.opentrafficsim.kpi.interfaces.GtuData;
7 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
8
9
10
11
12
13
14
15
16
17
18
19 public class GtuDataRoad implements GtuData
20 {
21
22
23 private final LaneBasedGtu gtu;
24
25
26
27
28
29 public GtuDataRoad(final LaneBasedGtu gtu)
30 {
31 this.gtu = gtu;
32 }
33
34
35
36
37
38 public final LaneBasedGtu getGtu()
39 {
40 return this.gtu;
41 }
42
43 @Override
44 public final String getId()
45 {
46 return this.gtu.getId();
47 }
48
49 @Override
50 public final String getOriginId()
51 {
52 try
53 {
54 return this.gtu.getStrategicalPlanner().getRoute().get().originNode().getId();
55 }
56 catch (NetworkException | NullPointerException exception)
57 {
58 throw new OtsRuntimeException("Could not get origin node.", exception);
59 }
60 }
61
62 @Override
63 public final String getDestinationId()
64 {
65 try
66 {
67 return this.gtu.getStrategicalPlanner().getRoute().get().destinationNode().getId();
68 }
69 catch (NetworkException | NullPointerException exception)
70 {
71 throw new OtsRuntimeException("Could not get destination node.", exception);
72 }
73 }
74
75 @Override
76 public final String getGtuTypeId()
77 {
78 return this.gtu.getType().getId();
79 }
80
81 @Override
82 public final String getRouteId()
83 {
84 return this.gtu.getStrategicalPlanner().getRoute()
85 .orElseThrow(() -> new OtsRuntimeException("Could not get id of route.")).getId();
86 }
87
88 @Override
89 public final Speed getReferenceSpeed()
90 {
91 try
92 {
93 double v1 = this.gtu.getPosition().lane().getSpeedLimit(this.gtu.getType()).si;
94 double v2 = this.gtu.getMaximumSpeed().si;
95 return Speed.ofSI(v1 < v2 ? v1 : v2);
96 }
97 catch (NetworkException exception)
98 {
99 throw new OtsRuntimeException("Could not obtain reference speed from GTU " + this.gtu, exception);
100 }
101 }
102
103 @Override
104 public final String toString()
105 {
106 return "GtuData [gtu=" + this.gtu + "]";
107 }
108
109 }