1 package org.opentrafficsim.core.gtu;
2
3 import java.io.Serializable;
4 import java.util.Set;
5
6 import org.djunits.value.vdouble.scalar.Acceleration;
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.djunits.value.vdouble.scalar.Time;
10 import org.djutils.immutablecollections.ImmutableMap;
11 import org.djutils.immutablecollections.ImmutableSet;
12 import org.opentrafficsim.base.Identifiable;
13 import org.opentrafficsim.base.parameters.Parameters;
14 import org.opentrafficsim.core.animation.Drawable;
15 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
16 import org.opentrafficsim.core.gtu.plan.operational.OperationalPlan;
17 import org.opentrafficsim.core.gtu.plan.strategical.StrategicalPlanner;
18 import org.opentrafficsim.core.gtu.plan.tactical.TacticalPlanner;
19
20 import nl.tudelft.simulation.dsol.animation.Locatable;
21 import nl.tudelft.simulation.event.EventProducerInterface;
22 import nl.tudelft.simulation.event.EventType;
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-2019 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: 4831 $, $LastChangedDate: 2019-01-06 01:35:05 +0100 (Sun, 06 Jan 2019) $, 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, Drawable
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 OTSSimulatorInterface 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 * Adds the provided GTU to this GTU, meaning it moves with this GTU.
172 * @param gtu GTU; gtu to enter this GTU
173 * @throws GTUException if the gtu already has a parent
174 */
175 void addGtu(GTU gtu) throws GTUException;
176
177 /**
178 * Removes the provided GTU from this GTU, meaning it no longer moves with this GTU.
179 * @param gtu GTU; gtu to exit this GTU
180 */
181 void removeGtu(GTU gtu);
182
183 /**
184 * Set the parent GTU.
185 * @param gtu GTU; parent GTU, may be {@code null}
186 * @throws GTUException if the gtu already has a parent
187 */
188 void setParent(GTU gtu) throws GTUException;
189
190 /**
191 * Returns the parent GTU, or {@code null} if this GTU has no parent.
192 * @return GTU; parent GTU, or {@code null} if this GTU has no parent
193 */
194 GTU getParent();
195
196 /**
197 * Returns the children GTU's.
198 * @return Set<GTU>; children GTU's
199 */
200 Set<GTU> getChildren();
201
202 /**
203 * The event type for pub/sub indicating the initialization of a new GTU. <br>
204 * Payload: [String id, DirectedPoint initialPosition, Length length, Length width]
205 */
206 EventType INIT_EVENT = new EventType("GTU.INIT");
207
208 /**
209 * The event type for pub/sub indicating a move. <br>
210 * Payload: [String id, DirectedPoint position, Speed speed, Acceleration acceleration, Length odometer]
211 */
212 EventType MOVE_EVENT = new EventType("GTU.MOVE");
213
214 /**
215 * The event type for pub/sub indicating destruction of the GTU. <br>
216 * Payload: [String id, DirectedPoint lastPosition, Length odometer]
217 */
218 EventType DESTROY_EVENT = new EventType("GTU.DESTROY");
219
220 }