View Javadoc
1   package org.opentrafficsim.core.gtu;
2   
3   import java.awt.Color;
4   import java.io.Serializable;
5   import java.util.Set;
6   
7   import org.djunits.value.vdouble.scalar.Acceleration;
8   import org.djunits.value.vdouble.scalar.Length;
9   import org.djunits.value.vdouble.scalar.Speed;
10  import org.djunits.value.vdouble.scalar.Time;
11  import org.opentrafficsim.base.Identifiable;
12  import org.opentrafficsim.base.parameters.Parameters;
13  import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
14  import org.opentrafficsim.core.gtu.plan.strategical.StrategicalPlanner;
15  import org.opentrafficsim.core.gtu.plan.tactical.TacticalPlanner;
16  
17  import nl.tudelft.simulation.dsol.animation.Locatable;
18  import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
19  import nl.tudelft.simulation.event.EventProducerInterface;
20  import nl.tudelft.simulation.event.EventType;
21  import nl.tudelft.simulation.immutablecollections.ImmutableMap;
22  import nl.tudelft.simulation.immutablecollections.ImmutableSet;
23  
24  /**
25   * Generalized Travel Unit. <br>
26   * A GTU is an object (person, car, ship) that can travel over the infrastructure. It has a (directed) location, dimensions, and
27   * some properties that all GTUs share. The GTU is not bound to any infrastructure and can travel freely in the world. <br>
28   * For its movement, a GTU uses an OperationalPlan, which indicates a shape in the world with a speed profile that the GTU will
29   * use to move. The OperationalPlan can be updated or replaced, for which a tactical planner is responsible. A tactical plan can
30   * for instance be for a car to change two lanes to the left during the next 200 m to be able to make a left turn in 200 m. The
31   * operational plans are then the implementation of segments of the movement (time, location, speed, acceleration) that the car
32   * will make to drive on the road and (safely) make the lane changes. On the highest level, a StrategicPlan puts boundary
33   * conditions on the tactical plans. The strategic plan contains for instance the destination we want to reach and possibly some
34   * constraints on solutions that the tactical plans have to comply with.
35   * <p>
36   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
37   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
38   * <p>
39   * @version $Revision: 4006 $, $LastChangedDate: 2018-09-19 13:55:45 +0200 (Wed, 19 Sep 2018) $, by $Author: averbraeck $,
40   *          initial version May 15, 2014 <br>
41   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
42   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
43   */
44  public interface GTU extends Locatable, Serializable, EventProducerInterface, Identifiable
45  {
46      /** @return the id of the GTU */
47      @Override
48      String getId();
49  
50      /** @return the maximum length of the GTU (parallel with driving direction). */
51      Length getLength();
52  
53      /** @return the maximum width of the GTU (perpendicular to driving direction). */
54      Length getWidth();
55  
56      /** @return the maximum speed of the GTU, in the direction of movement. */
57      Speed getMaximumSpeed();
58  
59      /** @return the maximum acceleration of the GTU, in the linear direction. */
60      Acceleration getMaximumAcceleration();
61  
62      /** @return the maximum deceleration of the GTU, in the linear direction, stored as a negative number. */
63      Acceleration getMaximumDeceleration();
64  
65      /** @return the type of GTU, e.g. TruckType, CarType, BusType. */
66      GTUType getGTUType();
67  
68      /** @return the simulator of the GTU. */
69      DEVSSimulatorInterface.TimeDoubleUnit getSimulator();
70  
71      /** @return the reference position of the GTU, by definition (0, 0, 0). */
72      RelativePosition getReference();
73  
74      /** @return the front position of the GTU, relative to its reference point. */
75      RelativePosition getFront();
76  
77      /** @return the rear position of the GTU, relative to its reference point. */
78      RelativePosition getRear();
79  
80      /** @return the center position of the GTU, relative to its reference point. */
81      RelativePosition getCenter();
82  
83      /** @return the contour points of the GTU. */
84      ImmutableSet<RelativePosition> getContourPoints();
85  
86      /** @return the positions for this GTU, but not the contour points. */
87      ImmutableMap<RelativePosition.TYPE, RelativePosition> getRelativePositions();
88  
89      /** @return the current speed of the GTU, along the direction of movement. */
90      Speed getSpeed();
91  
92      /**
93       * @param time Time; time at which to obtain the speed
94       * @return the current speed of the GTU, along the direction of movement.
95       */
96      Speed getSpeed(Time time);
97  
98      /** @return the current acceleration of the GTU, along the direction of movement. */
99      Acceleration getAcceleration();
100 
101     /**
102      * @param time Time; time at which to obtain the acceleration
103      * @return the current acceleration of the GTU, along the direction of movement.
104      */
105     Acceleration getAcceleration(Time time);
106 
107     /**
108      * @return Length; the current odometer value.
109      */
110     Length getOdometer();
111 
112     /**
113      * @param time Time; time to obtain the odometer at
114      * @return Length; the odometer value at given time.
115      */
116     Length getOdometer(Time time);
117 
118     /** @return Parameters. */
119     Parameters getParameters();
120 
121     /** @param parameters Parameters; parameters */
122     void setParameters(Parameters parameters);
123 
124     /**
125      * @return StrategicalPlanner; the planner responsible for the overall 'mission' of the GTU, usually indicating where it
126      *         needs to go. It operates by instantiating tactical planners to do the work.
127      */
128     StrategicalPlanner getStrategicalPlanner();
129 
130     /**
131      * @param time Time; time to obtain the strategical planner at
132      * @return StrategicalPlanner; the planner responsible for the overall 'mission' of the GTU, usually indicating where it
133      *         needs to go. It operates by instantiating tactical planners to do the work.
134      */
135     StrategicalPlanner getStrategicalPlanner(Time time);
136 
137     /** @return TacticalPlanner; the current tactical planner that can generate an operational plan */
138     default TacticalPlanner<?, ?> getTacticalPlanner()
139     {
140         return getStrategicalPlanner().getTacticalPlanner();
141     }
142 
143     /**
144      * @param time Time; time to obtain the tactical planner at
145      * @return TacticalPlanner; the tactical planner that can generate an operational plan at the given time
146      */
147     default TacticalPlanner<?, ?> getTacticalPlanner(Time time)
148     {
149         return getStrategicalPlanner(time).getTacticalPlanner(time);
150     }
151 
152     /** @return the current operational plan for the GTU */
153     OperationalPlan getOperationalPlan();
154 
155     /**
156      * @param time Time; time to obtain the operational plan at
157      * @return the operational plan for the GTU at the given time.
158      */
159     OperationalPlan getOperationalPlan(Time time);
160 
161     /** Destroy the GTU from the simulation and animation. */
162     void destroy();
163 
164     /**
165      * Returns whether the GTU is destroyed.
166      * @return whether the GTU is destroyed
167      */
168     boolean isDestroyed();
169 
170     /**
171      * Return the base color of the GTU (not the state-based color).
172      * @return Color; the base color of the GTU (not the state-based color)
173      */
174     Color getBaseColor();
175 
176     /**
177      * Adds the provided GTU to this GTU, meaning it moves with this GTU.
178      * @param gtu GTU; gtu to enter this GTU
179      * @throws GTUException if the gtu already has a parent
180      */
181     void addGtu(GTU gtu) throws GTUException;
182 
183     /**
184      * Removes the provided GTU from this GTU, meaning it no longer moves with this GTU.
185      * @param gtu GTU; gtu to exit this GTU
186      */
187     void removeGtu(GTU gtu);
188 
189     /**
190      * Set the parent GTU.
191      * @param gtu GTU; parent GTU, may be {@code null}
192      * @throws GTUException if the gtu already has a parent
193      */
194     void setParent(GTU gtu) throws GTUException;
195 
196     /**
197      * Returns the parent GTU, or {@code null} if this GTU has no parent.
198      * @return GTU; parent GTU, or {@code null} if this GTU has no parent
199      */
200     GTU getParent();
201 
202     /**
203      * Returns the children GTU's.
204      * @return Set&lt;GTU&gt;; children GTU's
205      */
206     Set<GTU> getChildren();
207 
208     /**
209      * The event type for pub/sub indicating the initialization of a new GTU. <br>
210      * Payload: [String id, DirectedPoint initialPosition, Length length, Length width, Color gtuBaseColor]
211      */
212     EventType INIT_EVENT = new EventType("GTU.INIT");
213 
214     /**
215      * The event type for pub/sub indicating a move. <br>
216      * Payload: [String id, DirectedPoint position, Speed speed, Acceleration acceleration, Length odometer]
217      */
218     EventType MOVE_EVENT = new EventType("GTU.MOVE");
219 
220     /**
221      * The event type for pub/sub indicating destruction of the GTU. <br>
222      * Payload: [String id, DirectedPoint lastPosition, Length odometer]
223      */
224     EventType DESTROY_EVENT = new EventType("GTU.DESTROY");
225 
226 }