1 package org.opentrafficsim.road.network.sampling.data;
2
3 import org.djunits.unit.SpeedUnit;
4 import org.djunits.value.vfloat.scalar.FloatSpeed;
5 import org.opentrafficsim.core.gtu.GtuException;
6 import org.opentrafficsim.core.network.NetworkException;
7 import org.opentrafficsim.kpi.sampling.data.ExtendedDataSpeed;
8 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
9 import org.opentrafficsim.road.network.sampling.GtuDataRoad;
10
11
12
13
14
15
16
17
18
19
20
21 public class ReferenceSpeed extends ExtendedDataSpeed<GtuDataRoad>
22 {
23
24
25 public static final ReferenceSpeed INSTANCE = new ReferenceSpeed();
26
27
28
29
30 public ReferenceSpeed()
31 {
32 super("referenceSpeed", "Reference speed (minimum of speed limit and maximum vehicle speed)");
33 }
34
35
36 @Override
37 public final FloatSpeed getValue(final GtuDataRoad gtu)
38 {
39 LaneBasedGtu gtuObj = gtu.getGtu();
40 try
41 {
42 double v1 = gtuObj.getReferencePosition().getLane().getSpeedLimit(gtuObj.getType()).si;
43 double v2 = gtuObj.getMaximumSpeed().si;
44 return new FloatSpeed(v1 < v2 ? v1 : v2, SpeedUnit.SI);
45 }
46 catch (GtuException exception)
47 {
48
49 return new FloatSpeed(Double.NaN, SpeedUnit.SI);
50 }
51 catch (NetworkException exception)
52 {
53 throw new RuntimeException("Could not obtain reference speed from GTU " + gtuObj, exception);
54 }
55 }
56
57
58 @Override
59 public final String toString()
60 {
61 return "Reference Speed";
62 }
63
64 }