/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file SUMOVehicle.h14/// @author Michael Behrisch15/// @author Daniel Krajzewicz16/// @author Jakob Erdmann17/// @date Tue, 17 Feb 200918///19// Abstract base class for vehicle representations20/****************************************************************************/21#pragma once22#include <config.h>2324#include <vector>25#include <typeinfo>26#include <utils/common/SUMOTime.h>27#include <utils/common/Named.h>28#include <utils/router/SUMOAbstractRouter.h>29#include <utils/vehicle/SUMOVehicleParameter.h>30#include <utils/vehicle/SUMOTrafficObject.h>31#include <utils/iodevices/OutputDevice.h>323334// ===========================================================================35// class declarations36// ===========================================================================37class MSRoute;38class MSEdge;39class MSLane;40class MSPerson;41class MSStop;42class MSTransportable;43class MSParkingArea;44class MSChargingStation;45class MSStoppingPlace;46class MSVehicleDevice;47class SUMOSAXAttributes;48class EnergyParams;49class PositionVector;50class MFXOptionalLock;5152typedef std::vector<const MSEdge*> ConstMSEdgeVector;535455// ===========================================================================56// class definitions57// ===========================================================================58/**59* @class SUMOVehicle60* @brief Representation of a vehicle61*/62class SUMOVehicle : public SUMOTrafficObject {63public:6465/// @brief Constructor66SUMOVehicle(const std::string& id) : SUMOTrafficObject(id) {}6768/// @brief Destructor69virtual ~SUMOVehicle() {}7071/** @brief Get the vehicle's lateral position on the lane72* @return The lateral position of the vehicle (in m relative to the73* centerline of the lane)74*/75virtual double getLateralPositionOnLane() const = 0;7677/** @brief Get the vehicle's angle78* @return The angle of the vehicle (in degree)79*/80virtual double getAngle() const = 0;8182/// Returns the current route83virtual const MSRoute& getRoute() const = 0;8485/// Returns the current route86virtual ConstMSRoutePtr getRoutePtr() const = 0;8788/** @brief Returns the nSuccs'th successor of edge the vehicle is currently at89*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 forward93* @return The nSuccs'th following edge in the vehicle's route94*/95virtual const MSEdge* succEdge(int nSuccs) const = 0;9697/** @brief Returns the starting point for reroutes (usually the current edge)98*99* This differs from myCurrEdge depending on braking distance and rail signals100* @return The rerouting start point101*/102virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const = 0;103104/** @brief Replaces the current route by the given edges105*106* It is possible that the new route is not accepted, if a) it does not107* contain the vehicle's current edge, or b) something fails on insertion108* into the routes container (see in-line comments).109*110* @param[in] edges The new list of edges to pass111* @param[in] onInit Whether the vehicle starts with this route112* @param[in] check Whether the route should be checked for validity113* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route114* @return Whether the new route was accepted115*/116virtual bool replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true, std::string* msgReturn = nullptr) = 0;117118/** @brief Performs a rerouting using the given router119*120* Tries to find a new route between the current edge and the destination edge, first.121* Tries to replace the current route by the new one using replaceRoute.122*123* @param[in] t The time for which the route is computed124* @param[in] router The router to use125* @return whether a valid route was found126* @see replaceRoute127*/128virtual bool reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false, const MSEdge* sink = nullptr) = 0;129130/** @brief Validates the current or given route131* @param[out] msg Description why the route is not valid (if it is the case)132* @param[in] route The route to check (or 0 if the current route shall be checked)133* @return Whether the vehicle's current route is valid134*/135virtual bool hasValidRoute(std::string& msg, ConstMSRoutePtr route = 0) const = 0;136/// @brief checks wether the vehicle can depart on the first edge137virtual bool hasValidRouteStart(std::string& msg) = 0;138139/// @brief computes validity attributes for the current route140virtual int getRouteValidity(bool update = true, bool silent = false, std::string* msgReturn = nullptr) = 0;141142/** @brief Returns an iterator pointing to the current edge in this vehicles route143* @return The current route pointer144*/145virtual const ConstMSEdgeVector::const_iterator& getCurrentRouteEdge() const = 0;146147/** @brief Returns the vehicle's emission model parameter148*149* @return The vehicle's emission parameters150*/151virtual EnergyParams* getEmissionParameters() const = 0;152153/** @brief Replaces the vehicle's parameter154*/155virtual void replaceParameter(const SUMOVehicleParameter* newParameter) = 0;156157/** @brief Called when the vehicle is inserted into the network158*159* Sets optional information about departure time, informs the vehicle160* control about a further running vehicle.161*/162virtual void onDepart() = 0;163164/** @brief Returns the information whether the vehicle is on a road (is simulated)165* @return Whether the vehicle is simulated166*/167virtual bool isOnRoad() const = 0;168169/** @brief Returns whether the vehicle is idling (waiting to re-enter the net170* @return true if the vehicle is waiting to enter the net (eg after parking)171*/172virtual bool isIdling() const = 0;173174/** @brief Returns the information whether the front of the vehhicle is on the given lane175* @return Whether the vehicle's front is on that lane176*/177virtual bool isFrontOnLane(const MSLane*) const = 0;178179/** @brief Returns the information whether the vehicle is parked180* @return Whether the vehicle is parked181*/182virtual bool isParking() const = 0;183184/** @brief Returns the information whether the vehicle is fully controlled185* via TraCI186* @return Whether the vehicle is remote-controlled187*/188virtual bool isRemoteControlled() const = 0;189190/** @brief Returns the information whether the vehicle is fully controlled191* via TraCI192* @return Whether the vehicle was remote-controlled within the given time range193*/194virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const = 0;195196/** @brief Returns this vehicle's real departure time197* @return This vehicle's real departure time198*/199virtual SUMOTime getDeparture() const = 0;200201/** @brief Returns this vehicle's real departure position202* @return This vehicle's real departure position203*/204virtual double getDepartPos() const = 0;205206/** @brief Returns this vehicle's desired arrivalPos for its current route207* (may change on reroute)208* @return This vehicle's real arrivalPos209*/210virtual double getArrivalPos() const = 0;211212/** @brief Sets this vehicle's desired arrivalPos for its current route213*/214virtual void setArrivalPos(double arrivalPos) = 0;215216/** @brief Returns whether this vehicle has departed217*/218virtual bool hasDeparted() const = 0;219220/** @brief Returns the edge on which this vehicle shall depart221*/222virtual int getDepartEdge() const = 0;223224/** @brief Returns the distance that was already driven by this vehicle225* @return the distance driven [m]226*/227virtual double getOdometer() const = 0;228229/** @brief Returns the number of new routes this vehicle got230* @return the number of new routes this vehicle got231*/232virtual int getNumberReroutes() const = 0;233234/// @brief whether the given transportable is allowed to board this vehicle235virtual bool allowsBoarding(const MSTransportable* t) const = 0;236237/** @brief Adds a person or container to this vehicle238*239* @param[in] transportable The person/container to add240*/241virtual void addTransportable(MSTransportable* transportable) = 0;242243/** @brief Returns the number of persons244* @return The number of passengers on-board245*/246virtual int getPersonNumber() const = 0;247248/** @brief Returns the list of persons249* @return The list of passengers on-board250*/251virtual std::vector<std::string> getPersonIDList() const = 0;252253/** @brief Returns the number of containers254* @return The number of contaiers on-board255*/256virtual int getContainerNumber() const = 0;257258/// @brief removes a person or container259virtual void removeTransportable(MSTransportable* t) = 0;260261/// @brief removes a person or containers mass262virtual void removeTransportableMass(MSTransportable* t) = 0;263264/// @brief retrieve riding persons265virtual const std::vector<MSTransportable*>& getPersons() const = 0;266267/// @brief retrieve riding containers268virtual const std::vector<MSTransportable*>& getContainers() const = 0;269270/** @brief Adds a stop271*272* The stop is put into the sorted list.273* @param[in] stop The stop to add274* @return Whether the stop could be added275*/276virtual bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,277ConstMSEdgeVector::const_iterator* searchStart = 0) = 0;278279/// @brief return list of route indices and stop positions for the remaining stops280virtual std::vector<std::pair<int, double> > getStopIndices() const = 0;281282/// @brief returns whether the vehicle serves a public transport line that serves the given stop283virtual bool isLineStop(double position) const = 0;284285/// @brief deletes the next stop at the given index if it exists286virtual bool abortNextStop(int nextStopIndex = 0) = 0;287288289/**290* returns the next imminent stop in the stop queue291* @return the upcoming stop292*/293virtual MSParkingArea* getNextParkingArea() = 0;294295/** @brief Replaces a stop296*297* The stop replace the next stop into the sorted list.298* @param[in] stop The stop to add299* @return Whether the stop could be added300*/301virtual bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg) = 0;302303virtual const std::vector<std::string>& getParkingBadges() const = 0;304305/// @brief Returns the remaining stop duration for a stopped vehicle or 0306virtual SUMOTime remainingStopDuration() const = 0;307308/** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue309*/310virtual bool isStopped() const = 0;311/** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue312*/313virtual bool isStoppedTriggered() const = 0;314315/** @brief Returns whether the vehicle is at a stop and parking316*/317virtual bool isStoppedParking() const = 0;318319/** @brief Returns whether the vehicle is stopped in the range of the given position */320virtual bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const = 0;321322/** @brief Returns whether the vehicle stops at the given stopping place */323virtual bool stopsAt(MSStoppingPlace* stop) const = 0;324325/** @brief Returns whether the vehicle stops at the given edge */326virtual bool stopsAtEdge(const MSEdge* edge) const = 0;327328/** @brief Returns whether the vehicle has to stop somewhere329* @return Whether the vehicle has to stop somewhere330*/331virtual bool hasStops() const = 0;332333/**334* returns the list of stops not yet reached in the stop queue335* @return the list of upcoming stops336*/337virtual const std::list<MSStop>& getStops() const = 0;338339/**340* returns the next imminent stop in the stop queue341* @return the upcoming stop342*/343virtual const MSStop& getNextStop() const = 0;344345/**346* returns the next imminent stop in the stop queue347* @return the upcoming stop348*/349virtual MSStop& getNextStopMutable() = 0;350351/// @brief mark vehicle as active352virtual void unregisterWaiting() = 0;353354/** @brief Returns parameters of the next stop or nullptr **/355virtual const SUMOVehicleParameter::Stop* getNextStopParameter() const = 0;356357/// @brief get remaining stop duration or 0 if the vehicle isn't stopped358virtual SUMOTime getStopDuration() const = 0;359360/**361* schedule a new stop for the vehicle; each time a stop is reached, the vehicle362* will wait for the given duration before continuing on its route363* @param[in] stop Stop parameters364* @param[out] errorMsg returned error message365*/366virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg) = 0;367368virtual void setChosenSpeedFactor(const double factor) = 0;369370virtual SUMOTime getDepartDelay() const = 0;371372virtual SUMOTime getTimeLoss() const = 0;373374/// @brief get distance for coming to a stop (used for rerouting checks)375virtual double getBrakeGap(bool delayed = false) const = 0;376377/// @brief Returns this vehicles impatience378virtual double getImpatience() const = 0;379380/** @brief Returns this vehicle's devices381* @return This vehicle's devices382*/383virtual const std::vector<MSVehicleDevice*>& getDevices() const = 0;384385/// @brief Returns the vehicles's length386virtual double getLength() const = 0;387388/* @brief Return whether this vehicle must be treated like a railway vehicle389* either due to its vClass or the vClass of it's edge */390virtual bool isRail() const = 0;391392virtual SUMOTime getLastActionTime() const = 0;393394/// @brief get bounding rectangle395virtual PositionVector getBoundingBox(double offset = 0) const = 0;396397virtual std::unique_ptr<MFXOptionalLock> getScopeLock() = 0;398399/// @name parking memory io400//@{401virtual void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local) = 0;402virtual SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const = 0;403virtual void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score) = 0;404virtual void resetParkingAreaScores() = 0;405virtual int getNumberParkingReroutes() const = 0;406virtual void setNumberParkingReroutes(int value) = 0;407408virtual void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local) = 0;409virtual SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const = 0;410virtual void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score) = 0;411virtual void resetChargingStationScores() = 0;412//@}413414/// @name state io415//@{416417/// Saves the states of a vehicle418virtual void saveState(OutputDevice& out) = 0;419420/** @brief Loads the state of this vehicle from the given description421*/422virtual void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset) = 0;423//@}424};425426427