1 package org.opentrafficsim.road.network.sampling;
2
3 import org.djunits.value.vdouble.scalar.Speed;
4 import org.opentrafficsim.core.gtu.GtuException;
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 public GtuDataRoad(final LaneBasedGtu gtu)
29 {
30 this.gtu = gtu;
31 }
32
33
34
35
36 public final LaneBasedGtu getGtu()
37 {
38 return this.gtu;
39 }
40
41
42 @Override
43 public final String getId()
44 {
45 return this.gtu.getId();
46 }
47
48
49 @Override
50 public final String getOriginId()
51 {
52 try
53 {
54 return this.gtu.getStrategicalPlanner().getRoute().originNode().getId();
55 }
56 catch (NetworkException exception)
57 {
58 throw new RuntimeException("Could not get origin node.", exception);
59 }
60 }
61
62
63 @Override
64 public final String getDestinationId()
65 {
66 try
67 {
68 return this.gtu.getStrategicalPlanner().getRoute().destinationNode().getId();
69 }
70 catch (NetworkException exception)
71 {
72 throw new RuntimeException("Could not get destination node.", exception);
73 }
74 }
75
76
77 @Override
78 public final String getGtuTypeId()
79 {
80 return this.gtu.getType().getId();
81 }
82
83
84 @Override
85 public final String getRouteId()
86 {
87 return this.gtu.getStrategicalPlanner().getRoute().getId();
88 }
89
90
91 @Override
92 public final Speed getReferenceSpeed()
93 {
94 try
95 {
96 double v1 = this.gtu.getReferencePosition().lane().getSpeedLimit(this.gtu.getType()).si;
97 double v2 = this.gtu.getMaximumSpeed().si;
98 return Speed.instantiateSI(v1 < v2 ? v1 : v2);
99 }
100 catch (GtuException exception)
101 {
102
103 return Speed.NaN;
104 }
105 catch (NetworkException exception)
106 {
107 throw new RuntimeException("Could not obtain reference speed from GTU " + this.gtu, exception);
108 }
109 }
110
111
112 @Override
113 public final String toString()
114 {
115 return "GtuData [gtu=" + this.gtu + "]";
116 }
117
118 }