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