/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 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;5051typedef std::vector<const MSEdge*> ConstMSEdgeVector;525354// ===========================================================================55// class definitions56// ===========================================================================57/**58* @class SUMOVehicle59* @brief Representation of a vehicle60*/61class SUMOVehicle : public SUMOTrafficObject {62public:6364/// @brief Constructor65SUMOVehicle(const std::string& id) : SUMOTrafficObject(id) {}6667/// @brief Destructor68virtual ~SUMOVehicle() {}6970/** @brief Get the vehicle's lateral position on the lane71* @return The lateral position of the vehicle (in m relative to the72* centerline of the lane)73*/74virtual double getLateralPositionOnLane() const = 0;7576/** @brief Get the vehicle's angle77* @return The angle of the vehicle (in degree)78*/79virtual double getAngle() const = 0;8081/// Returns the current route82virtual const MSRoute& getRoute() const = 0;8384/// Returns the current route85virtual ConstMSRoutePtr getRoutePtr() const = 0;8687/** @brief Returns the nSuccs'th successor of edge the vehicle is currently at88*89* If the rest of the route (counted from the current edge) than nSuccs,90* 0 is returned.91* @param[in] nSuccs The number of edge to look forward92* @return The nSuccs'th following edge in the vehicle's route93*/94virtual const MSEdge* succEdge(int nSuccs) const = 0;9596/** @brief Returns the starting point for reroutes (usually the current edge)97*98* This differs from myCurrEdge depending on braking distance and rail signals99* @return The rerouting start point100*/101virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const = 0;102103/** @brief Replaces the current route by the given edges104*105* It is possible that the new route is not accepted, if a) it does not106* contain the vehicle's current edge, or b) something fails on insertion107* into the routes container (see in-line comments).108*109* @param[in] edges The new list of edges to pass110* @param[in] onInit Whether the vehicle starts with this route111* @param[in] check Whether the route should be checked for validity112* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route113* @return Whether the new route was accepted114*/115virtual 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;116117/** @brief Performs a rerouting using the given router118*119* Tries to find a new route between the current edge and the destination edge, first.120* Tries to replace the current route by the new one using replaceRoute.121*122* @param[in] t The time for which the route is computed123* @param[in] router The router to use124* @return whether a valid route was found125* @see replaceRoute126*/127virtual 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;128129/** @brief Validates the current or given route130* @param[out] msg Description why the route is not valid (if it is the case)131* @param[in] route The route to check (or 0 if the current route shall be checked)132* @return Whether the vehicle's current route is valid133*/134virtual bool hasValidRoute(std::string& msg, ConstMSRoutePtr route = 0) const = 0;135/// @brief checks wether the vehicle can depart on the first edge136virtual bool hasValidRouteStart(std::string& msg) = 0;137138/// @brief computes validity attributes for the current route139virtual int getRouteValidity(bool update = true, bool silent = false, std::string* msgReturn = nullptr) = 0;140141/** @brief Returns an iterator pointing to the current edge in this vehicles route142* @return The current route pointer143*/144virtual const ConstMSEdgeVector::const_iterator& getCurrentRouteEdge() const = 0;145146/** @brief Returns the vehicle's emission model parameter147*148* @return The vehicle's emission parameters149*/150virtual EnergyParams* getEmissionParameters() const = 0;151152/** @brief Replaces the vehicle's parameter153*/154virtual void replaceParameter(const SUMOVehicleParameter* newParameter) = 0;155156/** @brief Called when the vehicle is inserted into the network157*158* Sets optional information about departure time, informs the vehicle159* control about a further running vehicle.160*/161virtual void onDepart() = 0;162163/** @brief Returns the information whether the vehicle is on a road (is simulated)164* @return Whether the vehicle is simulated165*/166virtual bool isOnRoad() const = 0;167168/** @brief Returns whether the vehicle is idling (waiting to re-enter the net169* @return true if the vehicle is waiting to enter the net (eg after parking)170*/171virtual bool isIdling() const = 0;172173/** @brief Returns the information whether the front of the vehhicle is on the given lane174* @return Whether the vehicle's front is on that lane175*/176virtual bool isFrontOnLane(const MSLane*) const = 0;177178/** @brief Returns the information whether the vehicle is parked179* @return Whether the vehicle is parked180*/181virtual bool isParking() const = 0;182183/** @brief Returns the information whether the vehicle is fully controlled184* via TraCI185* @return Whether the vehicle is remote-controlled186*/187virtual bool isRemoteControlled() const = 0;188189/** @brief Returns the information whether the vehicle is fully controlled190* via TraCI191* @return Whether the vehicle was remote-controlled within the given time range192*/193virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const = 0;194195/** @brief Returns this vehicle's real departure time196* @return This vehicle's real departure time197*/198virtual SUMOTime getDeparture() const = 0;199200/** @brief Returns this vehicle's real departure position201* @return This vehicle's real departure position202*/203virtual double getDepartPos() const = 0;204205/** @brief Returns this vehicle's desired arrivalPos for its current route206* (may change on reroute)207* @return This vehicle's real arrivalPos208*/209virtual double getArrivalPos() const = 0;210211/** @brief Sets this vehicle's desired arrivalPos for its current route212*/213virtual void setArrivalPos(double arrivalPos) = 0;214215/** @brief Returns whether this vehicle has departed216*/217virtual bool hasDeparted() const = 0;218219/** @brief Returns the edge on which this vehicle shall depart220*/221virtual int getDepartEdge() const = 0;222223/** @brief Returns the distance that was already driven by this vehicle224* @return the distance driven [m]225*/226virtual double getOdometer() const = 0;227228/** @brief Returns the number of new routes this vehicle got229* @return the number of new routes this vehicle got230*/231virtual int getNumberReroutes() const = 0;232233/// @brief whether the given transportable is allowed to board this vehicle234virtual bool allowsBoarding(const MSTransportable* t) const = 0;235236/** @brief Adds a person or container to this vehicle237*238* @param[in] transportable The person/container to add239*/240virtual void addTransportable(MSTransportable* transportable) = 0;241242/** @brief Returns the number of persons243* @return The number of passengers on-board244*/245virtual int getPersonNumber() const = 0;246247/** @brief Returns the list of persons248* @return The list of passengers on-board249*/250virtual std::vector<std::string> getPersonIDList() const = 0;251252/** @brief Returns the number of containers253* @return The number of contaiers on-board254*/255virtual int getContainerNumber() const = 0;256257/// @brief removes a person or container258virtual void removeTransportable(MSTransportable* t) = 0;259260/// @brief retrieve riding persons261virtual const std::vector<MSTransportable*>& getPersons() const = 0;262263/// @brief retrieve riding containers264virtual const std::vector<MSTransportable*>& getContainers() const = 0;265266/** @brief Adds a stop267*268* The stop is put into the sorted list.269* @param[in] stop The stop to add270* @return Whether the stop could be added271*/272virtual bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,273ConstMSEdgeVector::const_iterator* searchStart = 0) = 0;274275/// @brief return list of route indices and stop positions for the remaining stops276virtual std::vector<std::pair<int, double> > getStopIndices() const = 0;277278/// @brief returns whether the vehicle serves a public transport line that serves the given stop279virtual bool isLineStop(double position) const = 0;280281/// @brief deletes the next stop at the given index if it exists282virtual bool abortNextStop(int nextStopIndex = 0) = 0;283284285/**286* returns the next imminent stop in the stop queue287* @return the upcoming stop288*/289virtual MSParkingArea* getNextParkingArea() = 0;290291/** @brief Replaces a stop292*293* The stop replace the next stop into the sorted list.294* @param[in] stop The stop to add295* @return Whether the stop could be added296*/297virtual bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg) = 0;298299virtual const std::vector<std::string>& getParkingBadges() const = 0;300301/// @brief Returns the remaining stop duration for a stopped vehicle or 0302virtual SUMOTime remainingStopDuration() const = 0;303304/** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue305*/306virtual bool isStopped() const = 0;307/** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue308*/309virtual bool isStoppedTriggered() const = 0;310311/** @brief Returns whether the vehicle is at a stop and parking312*/313virtual bool isStoppedParking() const = 0;314315/** @brief Returns whether the vehicle is stopped in the range of the given position */316virtual bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const = 0;317318/** @brief Returns whether the vehicle stops at the given stopping place */319virtual bool stopsAt(MSStoppingPlace* stop) const = 0;320321/** @brief Returns whether the vehicle stops at the given edge */322virtual bool stopsAtEdge(const MSEdge* edge) const = 0;323324/** @brief Returns whether the vehicle has to stop somewhere325* @return Whether the vehicle has to stop somewhere326*/327virtual bool hasStops() const = 0;328329/**330* returns the list of stops not yet reached in the stop queue331* @return the list of upcoming stops332*/333virtual const std::list<MSStop>& getStops() const = 0;334335/**336* returns the next imminent stop in the stop queue337* @return the upcoming stop338*/339virtual const MSStop& getNextStop() const = 0;340341/**342* returns the next imminent stop in the stop queue343* @return the upcoming stop344*/345virtual MSStop& getNextStopMutable() = 0;346347/// @brief mark vehicle as active348virtual void unregisterWaiting() = 0;349350/** @brief Returns parameters of the next stop or nullptr **/351virtual const SUMOVehicleParameter::Stop* getNextStopParameter() const = 0;352353/// @brief get remaining stop duration or 0 if the vehicle isn't stopped354virtual SUMOTime getStopDuration() const = 0;355356/**357* schedule a new stop for the vehicle; each time a stop is reached, the vehicle358* will wait for the given duration before continuing on its route359* @param[in] stop Stop parameters360* @param[out] errorMsg returned error message361*/362virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg) = 0;363364virtual void setChosenSpeedFactor(const double factor) = 0;365366virtual SUMOTime getDepartDelay() const = 0;367368virtual SUMOTime getTimeLoss() const = 0;369370/// @brief get distance for coming to a stop (used for rerouting checks)371virtual double getBrakeGap(bool delayed = false) const = 0;372373/// @brief Returns this vehicles impatience374virtual double getImpatience() const = 0;375376/** @brief Returns this vehicle's devices377* @return This vehicle's devices378*/379virtual const std::vector<MSVehicleDevice*>& getDevices() const = 0;380381/// @brief Returns the vehicles's length382virtual double getLength() const = 0;383384/* @brief Return whether this vehicle must be treated like a railway vehicle385* either due to its vClass or the vClass of it's edge */386virtual bool isRail() const = 0;387388virtual SUMOTime getLastActionTime() const = 0;389390/// @brief get bounding rectangle391virtual PositionVector getBoundingBox(double offset = 0) const = 0;392393/// @name parking memory io394//@{395virtual void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local) = 0;396virtual SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const = 0;397virtual void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score) = 0;398virtual void resetParkingAreaScores() = 0;399virtual int getNumberParkingReroutes() const = 0;400virtual void setNumberParkingReroutes(int value) = 0;401402virtual void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local) = 0;403virtual SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const = 0;404virtual void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score) = 0;405virtual void resetChargingStationScores() = 0;406//@}407408/// @name state io409//@{410411/// Saves the states of a vehicle412virtual void saveState(OutputDevice& out) = 0;413414/** @brief Loads the state of this vehicle from the given description415*/416virtual void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset) = 0;417//@}418};419420421