1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file SUMOVehicle.h 11 /// @author Michael Behrisch 12 /// @author Daniel Krajzewicz 13 /// @author Jakob Erdmann 14 /// @date Tue, 17 Feb 2009 15 /// @version $Id$ 16 /// 17 // Abstract base class for vehicle representations 18 /****************************************************************************/ 19 #ifndef SUMOVehicle_h 20 #define SUMOVehicle_h 21 22 23 // =========================================================================== 24 // included modules 25 // =========================================================================== 26 #include <config.h> 27 28 #include <vector> 29 #include <typeinfo> 30 #include <utils/common/SUMOTime.h> 31 #include <utils/common/Named.h> 32 #include <utils/router/SUMOAbstractRouter.h> 33 #include <utils/vehicle/SUMOVehicleParameter.h> 34 #include <utils/vehicle/SUMOTrafficObject.h> 35 #include <utils/iodevices/OutputDevice.h> 36 37 38 // =========================================================================== 39 // class declarations 40 // =========================================================================== 41 class MSRoute; 42 class MSEdge; 43 class MSLane; 44 class MSPerson; 45 class MSTransportable; 46 class MSParkingArea; 47 class MSStoppingPlace; 48 class MSVehicleDevice; 49 class SUMOSAXAttributes; 50 51 typedef std::vector<const MSEdge*> ConstMSEdgeVector; 52 53 54 // =========================================================================== 55 // class definitions 56 // =========================================================================== 57 /** 58 * @class SUMOVehicle 59 * @brief Representation of a vehicle 60 */ 61 class SUMOVehicle : public SUMOTrafficObject { 62 public: 63 typedef long long int NumericalID; 64 65 /// @brief Destructor ~SUMOVehicle()66 virtual ~SUMOVehicle() {} 67 68 /** @brief Get the vehicle's lateral position on the lane 69 * @return The lateral position of the vehicle (in m relative to the 70 * centerline of the lane) 71 */ 72 virtual double getLateralPositionOnLane() const = 0; 73 74 /** @brief Get the vehicle's angle 75 * @return The angle of the vehicle (in degree) 76 */ 77 virtual double getAngle() const = 0; 78 79 /** @brief Returns the lane the vehicle is on 80 * @return The vehicle's current lane 81 */ 82 virtual MSLane* getLane() const = 0; 83 84 85 /// Returns the current route 86 virtual const MSRoute& getRoute() const = 0; 87 88 /** @brief Returns the nSuccs'th successor of edge the vehicle is currently at 89 * 90 * If the rest of the route (counted from the current edge) than nSuccs, 91 * 0 is returned. 92 * @param[in] nSuccs The number of edge to look forward 93 * @return The nSuccs'th following edge in the vehicle's route 94 */ 95 virtual const MSEdge* succEdge(int nSuccs) const = 0; 96 97 /** @brief Replaces the current route by the given edges 98 * 99 * It is possible that the new route is not accepted, if a) it does not 100 * contain the vehicle's current edge, or b) something fails on insertion 101 * into the routes container (see in-line comments). 102 * 103 * @param[in] edges The new list of edges to pass 104 * @param[in] onInit Whether the vehicle starts with this route 105 * @param[in] check Whether the route should be checked for validity 106 * @param[in] removeStops Whether stops should be removed if they do not fit onto the new route 107 * @return Whether the new route was accepted 108 */ 109 virtual bool replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true) = 0; 110 111 /// Replaces the current route by the given one 112 virtual bool replaceRoute(const MSRoute* route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true) = 0; 113 114 /** @brief Performs a rerouting using the given router 115 * 116 * Tries to find a new route between the current edge and the destination edge, first. 117 * Tries to replace the current route by the new one using replaceRoute. 118 * 119 * @param[in] t The time for which the route is computed 120 * @param[in] router The router to use 121 * @see replaceRoute 122 */ 123 virtual void reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false) = 0; 124 125 /** @brief Validates the current or given route 126 * @param[out] msg Description why the route is not valid (if it is the case) 127 * @param[in] route The route to check (or 0 if the current route shall be checked) 128 * @return Whether the vehicle's current route is valid 129 */ 130 virtual bool hasValidRoute(std::string& msg, const MSRoute* route = 0) const = 0; 131 132 133 /** @brief Returns an iterator pointing to the current edge in this vehicles route 134 * @return The current route pointer 135 */ 136 virtual const ConstMSEdgeVector::const_iterator& getCurrentRouteEdge() const = 0; 137 138 /** @brief Returns the vehicle's parameter (including departure definition) 139 * 140 * @return The vehicle's parameter 141 */ 142 virtual const SUMOVehicleParameter& getParameter() const = 0; 143 144 /** @brief Replaces the vehicle's parameter 145 */ 146 virtual void replaceParameter(const SUMOVehicleParameter* newParameter) = 0; 147 148 /** @brief Called when the vehicle is inserted into the network 149 * 150 * Sets optional information about departure time, informs the vehicle 151 * control about a further running vehicle. 152 */ 153 virtual void onDepart() = 0; 154 155 /** @brief Returns the information whether the vehicle is on a road (is simulated) 156 * @return Whether the vehicle is simulated 157 */ 158 virtual bool isOnRoad() const = 0; 159 160 /** @brief Returns the information whether the front of the vehhicle is on the given lane 161 * @return Whether the vehicle's front is on that lane 162 */ 163 virtual bool isFrontOnLane(const MSLane*) const = 0; 164 165 /** @brief Returns the information whether the vehicle is parked 166 * @return Whether the vehicle is parked 167 */ 168 virtual bool isParking() const = 0; 169 170 /** @brief Returns the information whether the vehicle is fully controlled 171 * via TraCI 172 * @return Whether the vehicle is remote-controlled 173 */ 174 virtual bool isRemoteControlled() const = 0; 175 176 /** @brief Returns the information whether the vehicle is fully controlled 177 * via TraCI 178 * @return Whether the vehicle was remote-controlled within the given time range 179 */ 180 virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const = 0; 181 182 /** @brief Returns this vehicle's real departure time 183 * @return This vehicle's real departure time 184 */ 185 virtual SUMOTime getDeparture() const = 0; 186 187 /** @brief Returns this vehicle's real departure position 188 * @return This vehicle's real departure position 189 */ 190 virtual double getDepartPos() const = 0; 191 192 /** @brief Returns this vehicle's desired arrivalPos for its current route 193 * (may change on reroute) 194 * @return This vehicle's real arrivalPos 195 */ 196 virtual double getArrivalPos() const = 0; 197 198 /** @brief Sets this vehicle's desired arrivalPos for its current route 199 */ 200 virtual void setArrivalPos(double arrivalPos) = 0; 201 202 /** @brief Returns whether this vehicle has departed 203 */ 204 virtual bool hasDeparted() const = 0; 205 206 /** @brief Returns the number of new routes this vehicle got 207 * @return the number of new routes this vehicle got 208 */ 209 virtual int getNumberReroutes() const = 0; 210 211 /** @brief Adds a person to this vehicle 212 * 213 * May do nothing since persons are not supported by default 214 * 215 * @param[in] person The person to add 216 */ 217 virtual void addPerson(MSTransportable* person) = 0; 218 219 /** @brief Adds a container to this vehicle 220 * 221 * May do nothing since containers are not supported by default 222 * 223 * @param[in] container The container to add 224 */ 225 virtual void addContainer(MSTransportable* container) = 0; 226 227 /** @brief Returns the number of persons 228 * @return The number of passengers on-board 229 */ 230 virtual int getPersonNumber() const = 0; 231 232 /** @brief Returns the list of persons 233 * @return The list of passengers on-board 234 */ 235 virtual std::vector<std::string> getPersonIDList() const = 0; 236 237 /** @brief Returns the number of containers 238 * @return The number of contaiers on-board 239 */ 240 virtual int getContainerNumber() const = 0; 241 242 /// @brief removes a person or container 243 virtual void removeTransportable(MSTransportable* t) = 0; 244 245 /// @brief retrieve riding persons 246 virtual const std::vector<MSTransportable*>& getPersons() const = 0; 247 248 /// @brief retrieve riding containers 249 virtual const std::vector<MSTransportable*>& getContainers() const = 0; 250 251 /** @brief Adds a stop 252 * 253 * The stop is put into the sorted list. 254 * @param[in] stop The stop to add 255 * @return Whether the stop could be added 256 */ 257 virtual bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0, bool collision = false, 258 ConstMSEdgeVector::const_iterator* searchStart = 0) = 0; 259 260 /// @brief return list of route indices and stop positions for the remaining stops 261 virtual std::vector<std::pair<int, double> > getStopIndices() const = 0; 262 263 264 /** 265 * returns the next imminent stop in the stop queue 266 * @return the upcoming stop 267 */ 268 virtual MSParkingArea* getNextParkingArea() = 0; 269 270 /** @brief Replaces a stop 271 * 272 * The stop replace the next stop into the sorted list. 273 * @param[in] stop The stop to add 274 * @return Whether the stop could be added 275 */ 276 virtual bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg) = 0; 277 278 /// @brief Returns the remaining stop duration for a stopped vehicle or 0 279 virtual SUMOTime remainingStopDuration() const = 0; 280 281 /** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue 282 */ 283 virtual bool isStoppedTriggered() const = 0; 284 285 /** @brief Returns whether the vehicle is stoped in range of the given position */ 286 virtual bool isStoppedInRange(double pos) const = 0; 287 288 /** @brief Returns whether the vehicle stops at the given stopping place */ 289 virtual bool stopsAt(MSStoppingPlace* stop) const = 0; 290 291 virtual void setChosenSpeedFactor(const double factor) = 0; 292 293 virtual SUMOTime getAccumulatedWaitingTime() const = 0; 294 295 virtual SUMOTime getDepartDelay() const = 0; 296 297 /// @brief get distance for coming to a stop (used for rerouting checks) 298 virtual double getBrakeGap() const = 0; 299 300 /// @brief Returns this vehicles impatience 301 virtual double getImpatience() const = 0; 302 303 /** @brief Returns this vehicle's devices 304 * @return This vehicle's devices 305 */ 306 virtual const std::vector<MSVehicleDevice*>& getDevices() const = 0; 307 308 /// @brief Returns a device of the given type if it exists or 0 309 virtual MSVehicleDevice* getDevice(const std::type_info& type) const = 0; 310 311 /// @brief whether this vehicle is selected in the GUI 312 virtual bool isSelected() const = 0; 313 314 /** @brief Returns the associated RNG for this vehicle 315 * @return The vehicle's associated RNG 316 */ 317 virtual std::mt19937* getRNG() const = 0; 318 319 /// @brief return the numerical ID which is only for internal usage 320 // (especially fast comparison in maps which need vehicles as keys) 321 virtual NumericalID getNumericalID() const = 0; 322 323 /// @name state io 324 //@{ 325 326 /// Saves the states of a vehicle 327 virtual void saveState(OutputDevice& out) = 0; 328 329 /** @brief Loads the state of this vehicle from the given description 330 */ 331 virtual void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset) = 0; 332 //@} 333 }; 334 335 336 #endif 337 338 /****************************************************************************/ 339