View Javadoc
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   * Gtu representation in road sampler.
11   * <p>
12   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * </p>
15   * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
17   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18   */
19  public class GtuDataRoad implements GtuData
20  {
21  
22      /** Gtu. */
23      private final LaneBasedGtu gtu;
24  
25      /**
26       * @param gtu gtu
27       */
28      public GtuDataRoad(final LaneBasedGtu gtu)
29      {
30          this.gtu = gtu;
31      }
32  
33      /**
34       * @return gtu.
35       */
36      public final LaneBasedGtu getGtu()
37      {
38          return this.gtu;
39      }
40  
41      @Override
42      public final String getId()
43      {
44          return this.gtu.getId();
45      }
46  
47      @Override
48      public final String getOriginId()
49      {
50          try
51          {
52              return this.gtu.getStrategicalPlanner().getRoute().originNode().getId();
53          }
54          catch (NetworkException exception)
55          {
56              throw new RuntimeException("Could not get origin node.", exception);
57          }
58      }
59  
60      @Override
61      public final String getDestinationId()
62      {
63          try
64          {
65              return this.gtu.getStrategicalPlanner().getRoute().destinationNode().getId();
66          }
67          catch (NetworkException exception)
68          {
69              throw new RuntimeException("Could not get destination node.", exception);
70          }
71      }
72  
73      @Override
74      public final String getGtuTypeId()
75      {
76          return this.gtu.getType().getId();
77      }
78  
79      @Override
80      public final String getRouteId()
81      {
82          return this.gtu.getStrategicalPlanner().getRoute().getId();
83      }
84  
85      @Override
86      public final Speed getReferenceSpeed()
87      {
88          try
89          {
90              double v1 = this.gtu.getReferencePosition().lane().getSpeedLimit(this.gtu.getType()).si;
91              double v2 = this.gtu.getMaximumSpeed().si;
92              return Speed.instantiateSI(v1 < v2 ? v1 : v2);
93          }
94          catch (GtuException exception)
95          {
96              // GTU was destroyed and is without a reference location
97              return Speed.NaN;
98          }
99          catch (NetworkException exception)
100         {
101             throw new RuntimeException("Could not obtain reference speed from GTU " + this.gtu, exception);
102         }
103     }
104 
105     @Override
106     public final String toString()
107     {
108         return "GtuData [gtu=" + this.gtu + "]";
109     }
110 
111 }