View Javadoc
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.LaneBasedGtu;
8   import org.opentrafficsim.road.gtu.tactical.util.SpeedLimitUtil;
9   
10  /**
11   * GTU representation in road sampler.
12   * <p>
13   * Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15   * </p>
16   * @author Alexander Verbraeck
17   * @author Peter Knoppers
18   * @author Wouter Schakel
19   */
20  public class GtuDataRoad implements GtuData
21  {
22  
23      /** GTU. */
24      private final LaneBasedGtu gtu;
25  
26      /**
27       * Constructor.
28       * @param gtu GTU
29       */
30      public GtuDataRoad(final LaneBasedGtu gtu)
31      {
32          this.gtu = gtu;
33      }
34  
35      /**
36       * Get GTU.
37       * @return GTU.
38       */
39      public LaneBasedGtu getGtu()
40      {
41          return this.gtu;
42      }
43  
44      @Override
45      public String getId()
46      {
47          return this.gtu.getId();
48      }
49  
50      @Override
51      public String getOriginId()
52      {
53          try
54          {
55              return this.gtu.getStrategicalPlanner().getRoute().get().originNode().getId();
56          }
57          catch (NetworkException | NullPointerException exception)
58          {
59              throw new OtsRuntimeException("Could not get origin node.", exception);
60          }
61      }
62  
63      @Override
64      public String getDestinationId()
65      {
66          try
67          {
68              return this.gtu.getStrategicalPlanner().getRoute().get().destinationNode().getId();
69          }
70          catch (NetworkException | NullPointerException exception)
71          {
72              throw new OtsRuntimeException("Could not get destination node.", exception);
73          }
74      }
75  
76      @Override
77      public String getGtuTypeId()
78      {
79          return this.gtu.getType().getId();
80      }
81  
82      @Override
83      public String getRouteId()
84      {
85          return this.gtu.getStrategicalPlanner().getRoute()
86                  .orElseThrow(() -> new OtsRuntimeException("Could not get id of route.")).getId();
87      }
88  
89      @Override
90      public Speed getReferenceSpeed()
91      {
92          return SpeedLimitUtil.getDesiredSpeedProxy(this.gtu.getPosition().lane().getSpeedLimits(this.gtu.getType()),
93                  this.gtu.getMaximumSpeed());
94      }
95  
96      @Override
97      public String toString()
98      {
99          return "GtuData [gtu=" + this.gtu + "]";
100     }
101 
102 }