/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2010-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 MSBaseVehicle.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Jakob Erdmann17/// @date Mon, 8 Nov 201018///19// A base class for vehicle implementations20/****************************************************************************/21#pragma once22#include <config.h>2324#include <iostream>25#include <vector>26#include <set>27#include <utils/common/StdDefs.h>28#include <utils/emissions/EnergyParams.h>29#include <utils/emissions/PollutantsInterface.h>30#include <utils/vehicle/SUMOVehicle.h>31#include "MSRoute.h"32#include "MSMoveReminder.h"33#include "MSVehicleType.h"343536// ===========================================================================37// class declarations38// ===========================================================================39class MSLane;40class MSStop;41class MSDevice_Transportable;42class MSDevice_Emissions;43class MSVehicleDevice;44class MSEdgeWeightsStorage;45class MSChargingStation;46class StoppingPlaceMemory;474849// ===========================================================================50// class definitions51// ===========================================================================52/**53* @class MSBaseVehicle54* @brief The base class for microscopic and mesoscopic vehicles55*/56class MSBaseVehicle : public SUMOVehicle {57public:58// XXX: This definition was introduced to make the MSVehicle's previousSpeed59// available in the context of MSMoveReminder::notifyMove(). Another solution60// would be to modify notifyMove()'s interface to work with MSVehicle instead61// of SUMOVehicle (it is only called with MSVehicles!). Refs. #257962/** @brief Returns the vehicle's previous speed63* @return The vehicle's speed64*/65double getPreviousSpeed() const;6667friend class GUIBaseVehicle;6869/** @enum RouteValidity70*/71enum RouteValidity {72ROUTE_VALID = 0,73ROUTE_UNCHECKED = 1 << 0,74/// route was checked and is valid75ROUTE_INVALID = 1 << 1,76// starting edge permissions invalid (could change)77ROUTE_START_INVALID_PERMISSIONS = 1 << 2,78// insertion lane does not exist79ROUTE_START_INVALID_LANE = 1 << 380};8182/** @brief Constructor83* @param[in] pars The vehicle description84* @param[in] route The vehicle's route85* @param[in] type The vehicle's type86* @param[in] speedFactor The factor for driven lane's speed limits87* @exception ProcessError If a value is wrong88*/89MSBaseVehicle(SUMOVehicleParameter* pars, ConstMSRoutePtr route,90MSVehicleType* type, const double speedFactor);919293/// @brief Destructor94virtual ~MSBaseVehicle();9596virtual void initDevices();9798bool isVehicle() const {99return true;100}101102/// @brief set the id (inherited from Named but forbidden for vehicles)103void setID(const std::string& newID);104105/** @brief Returns the vehicle's parameter (including departure definition)106*107* @return The vehicle's parameter108*/109const SUMOVehicleParameter& getParameter() const;110111/// @brief retrieve parameters of devices, models and the vehicle itself112std::string getPrefixedParameter(const std::string& key, std::string& error) const;113114/// @brief replace the vehicle parameter (deleting the old one)115void replaceParameter(const SUMOVehicleParameter* newParameter);116117/// @brief check whether the vehicle is equiped with a device of the given name118bool hasDevice(const std::string& deviceName) const;119120/// @brief create device of the given type121void createDevice(const std::string& deviceName);122123/// @brief try to retrieve the given parameter from any of the vehicles devices, raise InvalidArgument if no device parameter by that name exists124std::string getDeviceParameter(const std::string& deviceName, const std::string& key) const;125126/// @brief try to set the given parameter from any of the vehicles devices, raise InvalidArgument if no device parameter by that name exists127void setDeviceParameter(const std::string& deviceName, const std::string& key, const std::string& value);128129/// @brief set individual junction model paramete (not type related)130void setJunctionModelParameter(const std::string& key, const std::string& value);131132/// @brief set individual carFollow model parameters (not type related)133void setCarFollowModelParameter(const std::string& key, const std::string& value);134135/** @brief Returns the current route136* @return The route the vehicle uses137*/138inline const MSRoute& getRoute() const {139return *myRoute;140}141142/** @brief Returns the current route143* @return The route the vehicle uses144*/145inline ConstMSRoutePtr getRoutePtr() const {146return myRoute;147}148149/** @brief Returns the vehicle's type definition150* @return The vehicle's type definition151*/152inline const MSVehicleType& getVehicleType() const {153return *myType;154}155156/** @brief Returns the vehicle's type parameter157* @return The vehicle's type parameter158*/159inline const SUMOVTypeParameter& getVTypeParameter() const {160return myType->getParameter();161}162163/** @brief Returns the vehicle's access class164* @return The vehicle's access class165*/166inline SUMOVehicleClass getVClass() const {167return myType->getParameter().vehicleClass;168}169170/** @brief Returns whether this object is ignoring transient permission171* changes (during routing)172*/173bool ignoreTransientPermissions() const;174175/// @brief whether instant stopping is permitted176virtual bool instantStopping() const {177return false;178}179180/** @brief Returns the maximum speed (the minimum of desired and technical maximum speed)181* @return The vehicle's maximum speed182*/183double getMaxSpeed() const;184185/** @brief Returns the nSuccs'th successor of edge the vehicle is currently at186*187* If the rest of the route (counted from the current edge) has less than nSuccs edges,188* 0 is returned.189* @param[in] nSuccs The number of edge to look forward190* @return The nSuccs'th following edge in the vehicle's route191*/192const MSEdge* succEdge(int nSuccs) const;193194/** @brief Returns the edge the vehicle is currently at195*196* @return The current edge in the vehicle's route197*/198const MSEdge* getEdge() const;199200/** @brief Returns the edge the vehicle is currently at (possibly an201* internal edge)202*/203virtual const MSEdge* getCurrentEdge() const {204return getEdge();205}206207/// @brief returns the numerical ids of edges to travel208const std::set<SUMOTrafficObject::NumericalID> getUpcomingEdgeIDs() const;209210/** @brief Returns whether the vehicle stops at the given stopping place */211bool stopsAt(MSStoppingPlace* stop) const;212213/** @brief Returns whether the vehicle stops at the given edge */214bool stopsAtEdge(const MSEdge* edge) const;215216/// @brief returns the next edge (possibly an internal edge)217virtual const MSEdge* getNextEdgePtr() const {218return nullptr;219}220221/** @brief Returns the information whether the vehicle is on a road (is simulated)222* @return Whether the vehicle is simulated223*/224virtual bool isOnRoad() const {225return true;226}227228/** @brief Returns the information whether the vehicle is fully controlled229* via TraCI230* @return Whether the vehicle is remote-controlled231*/232virtual bool isRemoteControlled() const {233return false;234}235236virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const {237UNUSED_PARAMETER(lookBack);238return false;239}240241/** @brief Returns the information whether the front of the vehhicle is on the given lane242* @return Whether the vehicle's front is on that lane243*/244virtual bool isFrontOnLane(const MSLane*) const {245return true;246}247248/** @brief Get the vehicle's lateral position on the lane249* @return The lateral position of the vehicle (in m relative to the250* centerline of the lane)251*/252virtual double getLateralPositionOnLane() const {253return 0;254}255256/** @brief Get the vehicle's lateral position on the edge of the given lane257* (or its current edge if lane == 0)258* @return The lateral position of the vehicle (in m distance between right259* side of vehicle and ride side of edge260*/261virtual double getRightSideOnEdge(const MSLane* lane = 0) const {262UNUSED_PARAMETER(lane);263return 0;264}265266/** @brief Returns the starting point for reroutes (usually the current edge)267*268* This differs from *myCurrEdge only if the vehicle is on an internal edge269* @return The rerouting start point270*/271virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const {272return myCurrEdge;273}274275/** @brief Returns the end point for reroutes (usually the last edge of the route)276*277* @return The rerouting end point278*/279virtual const MSEdge* getRerouteDestination() const {280return myRoute->getLastEdge();281}282283/** @brief Returns the time loss in seconds284*/285virtual double getTimeLossSeconds() const {286// better timeLoss for meso?287return 0;288}289290/** @brief Returns the number of seconds waited (speed was lesser than 0.1m/s)291*292* The value is reset if the vehicle moves faster than 0.1m/s293* Intentional stopping does not count towards this time.294* @return The time the vehicle is standing295*/296double getWaitingSeconds() const {297return STEPS2TIME(getWaitingTime());298}299300301302/** @brief Returns an iterator pointing to the current edge in this vehicles route303* @return The current route pointer304*/305const MSRouteIterator& getCurrentRouteEdge() const {306return myCurrEdge;307}308309310/** @brief Performs a rerouting using the given router311*312* Tries to find a new route between the current edge and the destination edge, first.313* Tries to replace the current route by the new one using replaceRoute.314*315* @param[in] t The time for which the route is computed316* @param[in] router The router to use317* @param[in] sink (optionally) a new destination edge318* @see replaceRoute319*/320bool 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);321322323/** @brief Replaces the current route by the given edges324*325* It is possible that the new route is not accepted, if a) it does not326* contain the vehicle's current edge, or b) something fails on insertion327* into the routes container (see in-line comments).328*329* @param[in] edges The new list of edges to pass330* @param[in] onInit Whether the vehicle starts with this route331* @param[in] check Whether the route should be checked for validity332* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route333* @return Whether the new route was accepted334*/335bool replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true,336std::string* msgReturn = nullptr);337338/** @brief Replaces the current route by the given one339*340* It is possible that the new route is not accepted, if it does not341* contain the vehicle's current edge.342*343* @param[in] route The new route to pass344* @param[in] info Information regarding the replacement345* @param[in] addRouteStops Whether stops from the replacement route should be added346* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route347* @return Whether the new route was accepted348*/349virtual bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true,350std::string* msgReturn = nullptr);351352/** @brief Returns the vehicle's acceleration353*354* This default implementation returns always 0.355* @return The acceleration356*/357virtual double getAcceleration() const;358359/** @brief Called when the vehicle is inserted into the network360*361* Sets optional information about departure time, informs the vehicle362* control about a further running vehicle.363*/364void onDepart();365366/** @brief Returns this vehicle's real departure time367* @return This vehicle's real departure time368*/369inline SUMOTime getDeparture() const {370return myDeparture;371}372373/** @brief Returns the depart delay */374SUMOTime getDepartDelay() const;375376/** @brief Returns the estimated public transport stop (departure) delay in seconds377*/378virtual double getStopDelay() const {379/// @todo implement for meso380return -1;381}382383/** @brief Returns the estimated public transport stop arrival delay in seconds384*/385virtual double getStopArrivalDelay() const {386/// @todo implement for meso387return INVALID_DOUBLE;388}389390/// @brief return time (s) and distance to the next stop391virtual std::pair<double, double> estimateTimeToNextStop() const {392return std::make_pair(-1, -1);393}394395/** @brief Returns this vehicle's real departure position396* @return This vehicle's real departure position397*/398inline double getDepartPos() const {399return myDepartPos;400}401402/** @brief Returns this vehicle's desired arrivalPos for its current route403* (may change on reroute)404* @return This vehicle's real arrivalPos405*/406virtual double getArrivalPos() const {407return myArrivalPos;408}409410virtual int getArrivalLane() const {411return myArrivalLane;412}413414/** @brief Sets this vehicle's desired arrivalPos for its current route415*/416virtual void setArrivalPos(double arrivalPos) {417myArrivalPos = arrivalPos;418}419420/** @brief Called when the vehicle is removed from the network.421*422* Moves along work reminders and423* informs all devices about quitting. Calls "leaveLane" then.424*425* @param[in] reason why the vehicle leaves (reached its destination, parking, teleport)426*/427virtual void onRemovalFromNet(const MSMoveReminder::Notification /*reason*/) {}428429/** @brief Returns whether this vehicle has already departed430*/431inline bool hasDeparted() const {432return myDeparture != NOT_YET_DEPARTED;433}434435/** @brief Returns whether this vehicle has already arived436* (by default this is true if the vehicle has reached its final edge)437*/438virtual bool hasArrived() const;439440/// @brief return index of edge within route441int getRoutePosition() const;442443/// @brief return the number of edges remaining in the route (include the current)444int getNumRemainingEdges() const;445446int getArrivalIndex() const {447return myParameter->arrivalEdge;448}449450/// @brief reset index of edge within route451void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure);452453/** @brief Returns the distance that was already driven by this vehicle454* @return the distance driven [m]455*/456double getOdometer() const;457458/// @brief Manipulate the odometer459void addToOdometer(double value) {460myOdometer += value;461}462463/** @brief Returns the number of new routes this vehicle got464* @return the number of new routes this vehicle got465*/466inline int getNumberReroutes() const {467return myNumberReroutes;468}469470/// @brief Returns this vehicles impatience471double getImpatience() const;472473/** @brief Returns the number of persons474* @return The number of passengers on-board475*/476int getPersonNumber() const;477478/** @brief Returns the number of leaving persons479* @return The number of leaving passengers480*/481int getLeavingPersonNumber() const;482483/** @brief Returns the list of persons484* @return The list of passengers on-board485*/486std::vector<std::string> getPersonIDList() const;487488/** @brief Returns the number of containers489* @return The number of contaiers on-board490*/491int getContainerNumber() const;492493494/** @brief Returns this vehicle's devices495* @return This vehicle's devices496*/497inline const std::vector<MSVehicleDevice*>& getDevices() const {498return myDevices;499}500501/// @brief whether the given transportable is allowed to board this vehicle502bool allowsBoarding(const MSTransportable* t) const;503504/** @brief Adds a person or container to this vehicle505*506* @param[in] transportable The person/container to add507*/508virtual void addTransportable(MSTransportable* transportable);509510/// @brief removes a person or container511void removeTransportable(MSTransportable* t);512513/// @brief removes a person or containers mass514void removeTransportableMass(MSTransportable* t);515516/// @brief retrieve riding persons517const std::vector<MSTransportable*>& getPersons() const;518519/// @brief retrieve riding containers520const std::vector<MSTransportable*>& getContainers() const;521522/// @brief returns whether the vehicle serves a public transport line that serves the given stop523bool isLineStop(double position) const;524525/// @brief check wether the vehicle has jump at the given part of its route526bool hasJump(const MSRouteIterator& it) const;527528/** @brief Validates the current or given route529* @param[out] msg Description why the route is not valid (if it is the case)530* @param[in] route The route to check (or 0 if the current route shall be checked)531* @return Whether the vehicle's current route is valid532*/533bool hasValidRoute(std::string& msg, ConstMSRoutePtr route = 0) const;534535bool hasValidRoute(std::string& msg, MSRouteIterator start, MSRouteIterator last, bool checkJumps) const;536537/// @brief checks wether the vehicle can depart on the first edge538virtual bool hasValidRouteStart(std::string& msg);539540/// @brief check for route validity at first insertion attempt541int getRouteValidity(bool update = true, bool silent = false, std::string* msgReturn = nullptr);542543/// @brief Checks whether the vehilce has the given MoveReminder544bool hasReminder(MSMoveReminder* rem) const;545546/** @brief Adds a MoveReminder dynamically547*548* @param[in] rem the reminder to add549* @see MSMoveReminder550*/551void addReminder(MSMoveReminder* rem, double pos = 0);552553/** @brief Removes a MoveReminder dynamically554*555* @param[in] rem the reminder to remove556* @see MSMoveReminder557*/558void removeReminder(MSMoveReminder* rem);559560/** @brief "Activates" all current move reminder561*562* For all move reminder stored in "myMoveReminders", their method563* "MSMoveReminder::notifyEnter" is called.564*565* @param[in] reason The reason for changing the reminders' states566* @param[in] enteredLane The lane, which is entered (if applicable)567* @see MSMoveReminder568* @see MSMoveReminder::notifyEnter569* @see MSMoveReminder::Notification570*/571virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);572573574/** @brief Returns the vehicle's length575* @return vehicle's length576*/577inline double getLength() const {578return myType->getLength();579}580581/* @brief Return whether this vehicle must be treated like a railway vehicle582* either due to its vClass or the vClass of it's edge */583bool isRail() const;584585/** @brief Returns the vehicle's width586* @return vehicle's width587*/588inline double getWidth() const {589return myType->getWidth();590}591592593/** @brief Returns the precomputed factor by which the driver wants to be faster than the speed limit594* @return Speed limit factor595*/596inline double getChosenSpeedFactor() const {597return myChosenSpeedFactor;598}599600inline double getDesiredMaxSpeed() const {601return myType->getDesiredMaxSpeed() * myChosenSpeedFactor;602}603604/** @brief Returns the precomputed factor by which the driver wants to be faster than the speed limit605* @return Speed limit factor606*/607inline void setChosenSpeedFactor(const double factor) {608myChosenSpeedFactor = factor;609}610611/// @brief Returns a device of the given type if it exists, nullptr otherwise612MSDevice* getDevice(const std::type_info& type) const;613614615/** @brief Replaces the current vehicle type by the one given616*617* If the currently used vehicle type is marked as being used by this vehicle618* only, it is deleted, first. The new, given type is then assigned to619* "myType".620* @param[in] type The new vehicle type621* @see MSBaseVehicle::myType622*/623virtual void replaceVehicleType(const MSVehicleType* type);624625626/** @brief Replaces the current vehicle type with a new one used by this vehicle only627*628* If the currently used vehicle type is already marked as being used by this vehicle629* only, no new type is created.630* @return The new modifiable vehicle type631* @see MSBaseVehicle::myType632*/633MSVehicleType& getSingularType();634635/// @name state io636//@{637638/// Saves the (common) state of a vehicle639virtual void saveState(OutputDevice& out);640641//@}642643virtual bool handleCollisionStop(MSStop& stop, const double distToStop);644645/** @brief Returns whether the vehicle is at a stop646* @return Whether the vehicle has stopped647*/648bool isStopped() const;649650/** @brief Returns whether the vehicle is parking651* @return whether the vehicle is parking652*/653bool isParking() const;654655/** @brief Returns whether the vehicle is perform a jump656* @return whether the vehicle is starting to jump657*/658bool isJumping() const;659660/** @brief Returns whether the logical state of the vehicle is reversed - for drawing661* @return whether the logical state of the vehicle is reversed662*/663inline bool isReversed() const {664return myAmReversed;665}666667/** @brief Returns whether the vehicle is on a triggered stop668* @return whether the vehicle is on a triggered stop669*/670bool isStoppedTriggered() const;671672/** @brief Returns whether the vehicle is on a parking stop673* @return whether the vehicle is on a parking stop674*/675bool isStoppedParking() const;676677/** @brief return whether the given position is within range of the current stop678*/679bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const;680681/** @brief Returns whether the vehicle has to stop somewhere682* @return Whether the vehicle has to stop somewhere683*/684bool hasStops() const {685return !myStops.empty();686}687688/** @brief replace the current parking area stop with a new stop with merge duration689*/690bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg);691692/** @brief get the upcoming parking area stop or nullptr693*/694MSParkingArea* getNextParkingArea();695696/** @brief get the current parking area stop or nullptr */697MSParkingArea* getCurrentParkingArea();698699/// @brief get the valid parking access rights (vehicle settings override vehicle type settings)700const std::vector<std::string>& getParkingBadges() const;701702/// @brief departure position where the vehicle fits fully onto the edge (if possible)703double basePos(const MSEdge* edge) const;704705/** @brief Adds a stop706*707* The stop is put into the sorted list.708* @param[in] stop The stop to add709* @return Whether the stop could be added710*/711bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,712MSRouteIterator* searchStart = nullptr);713714/** @brief Adds stops to the built vehicle715*716* This code needs to be separated from the MSBaseVehicle constructor717* since it is not allowed to call virtual functions from a constructor718*719* @param[in] ignoreStopErrors whether invalid stops trigger a warning only720*/721void addStops(const bool ignoreStopErrors, MSRouteIterator* searchStart = nullptr, bool addRouteStops = true);722723/// @brief check whether all stop.edge MSRouteIterators are valid and in order724bool haveValidStopEdges(bool silent = false) const;725726/// @brief return list of route indices for the remaining stops727std::vector<std::pair<int, double> > getStopIndices() const;728729/**730* returns the list of stops not yet reached in the stop queue731* @return the list of upcoming stops732*/733inline const std::list<MSStop>& getStops() const {734return myStops;735}736737inline const StopParVector& getPastStops() const {738return myPastStops;739}740741/**742* returns the next imminent stop in the stop queue743* @return the upcoming stop744*/745const MSStop& getNextStop() const;746747/**748* returns the next imminent stop in the stop queue749* @return the upcoming stop750*/751MSStop& getNextStopMutable();752753/// @brief get remaining stop duration or 0 if the vehicle isn't stopped754SUMOTime getStopDuration() const;755756/**757* returns the upcoming stop with the given index in the stop queue758* @return an upcoming stop759*/760MSStop& getStop(int nextStopIndex);761762/// @brief return parameters for the next stop (SUMOVehicle Interface)763const SUMOVehicleParameter::Stop* getNextStopParameter() const;764765/**766* schedule a new stop for the vehicle; each time a stop is reached, the vehicle767* will wait for the given duration before continuing on its route768* @param[in] stop Stop parameters769* @param[out] errorMsg returned error message770*/771virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg);772773/**774* resumes a vehicle from stopping775* @return true on success, the resuming fails if the vehicle wasn't parking in the first place776*/777virtual bool resumeFromStopping() = 0;778779/// @brief mark vehicle as active780void unregisterWaiting();781782/// @brief deletes the next stop at the given index if it exists783bool abortNextStop(int nextStopIndex = 0);784785/**786* replace the next stop at the given index with the given stop parameters787* will wait for the given duration before continuing on its route788* The route between start other stops and destination will be kept unchanged and789* only the part around the replacement index will be adapted according to the new stop location790* @param[in] nextStopIndex The replacement index791* @param[in] stop Stop parameters792* @param[in] info The rerouting info793* @param[in] teleport Whether to cover the route to the replacement stop via teleporting794* @param[out] errorMsg returned error message795*/796bool replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg);797798/**799* reroute between stops nextStopIndex - 1 and nextStopIndex (defaults to current position / final edge) if the respective stops do not exist800* @param[in] nextStopIndex The replacement index801* @param[in] info The rerouting info802* @param[in] teleport Whether to cover the route between stops via teleporting803* @param[out] errorMsg returned error message804*/805bool rerouteBetweenStops(int nextStopIndex, const std::string& info, bool teleport, std::string& errorMsg);806807/**808* insert stop at the given index with the given stop parameters809* will wait for the given duration before continuing on its route810* The route will be adapted to pass the new stop edge but only from the previous stop (or start) to the new stop and only up to the next stop (or end).811* @param[in] nextStopIndex The replacement index812* @param[in] stop Stop parameters813* @param[in] info The rerouting info814* @param[in] teleport Whether to cover the route to the new stop via teleporting815* @param[out] errorMsg returned error message816*/817bool insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string& info, bool teleport, std::string& errorMsg);818819820/// @brief whether this vehicle is selected in the GUI821virtual bool isSelected() const {822return false;823}824825/// @brief @return The index of the vehicle's associated RNG826int getRNGIndex() const;827828/// @brief @return The vehicle's associated RNG829SumoRNG* getRNG() const;830831inline NumericalID getNumericalID() const {832return myNumericalID;833}834835/// @brief return vehicle-specific random number836long long int getRandomSeed() const {837return myRandomSeed;838}839840const MSDevice_Transportable* getPersonDevice() const {841return myPersonDevice;842}843844const MSDevice_Transportable* getContainerDevice() const {845return myContainerDevice;846}847848/// @brief retrieve parameters for the energy consumption model849EnergyParams* getEmissionParameters() const;850851/// @name Emission retrieval852//@{853854/** @brief Returns emissions of the current state855* The value is always per 1s, so multiply by step length if necessary.856* @return The current emission857*/858template<PollutantsInterface::EmissionType ET>859double getEmissions() const {860if (isOnRoad() || isIdling()) {861return PollutantsInterface::compute(myType->getEmissionClass(), ET, getSpeed(), getAcceleration(), getSlope(), getEmissionParameters());862}863return 0.;864}865866/** @brief Returns actual state of charge of battery (Wh)867* RICE_CHECK: This may be a misnomer, SOC is typically percentage of the maximum battery capacity.868* @return The actual battery state of charge869*/870double getStateOfCharge() const;871872/** @brief Returns actual relative state of charge of battery (-)873* @return The actual relative battery state of charge, normalised to the maximum battery capacity.874*/875double getRelativeStateOfCharge() const;876877/** @brief Returns the energy charged to the battery in the current time step (Wh)878* @return The energy charged to the battery in the current time step.879*/880double getChargedEnergy() const;881882/** @brief Returns the maximum charge rate allowed by the battery in the current time step (W)883* @return The maximum charge rate in the current time step.884*/885double getMaxChargeRate() const;886887/** @brief Returns actual current (A) of ElecHybrid device888* RICE_CHECK: Is this the current consumed from the overhead wire or the current driving the powertrain of the vehicle?889* RICE_REV_JS: It is the current drawn from the overhead wire (value if the vehicle is not connected to overhead wire?)890* @return The current of ElecHybrid device891*/892double getElecHybridCurrent() const;893894/** @brief Returns noise emissions of the current state895* @return The noise produced896*/897double getHarmonoise_NoiseEmissions() const;898//@}899900/** @class Influencer901* @brief Changes the wished vehicle speed / lanes902*903* The class is used for passing velocities or velocity profiles obtained via TraCI to the vehicle.904* The speed adaptation is controlled by the stored speedTimeLine905* Additionally, the variables myConsiderSafeVelocity, myConsiderMaxAcceleration, and myConsiderMaxDeceleration906* control whether the safe velocity, the maximum acceleration, and the maximum deceleration907* have to be regarded.908*909* Furthermore this class is used to affect lane changing decisions according to910* LaneChangeMode and any given laneTimeLine911*/912class BaseInfluencer {913public:914/// @brief Constructor915BaseInfluencer();916917/// @brief Destructor918virtual ~BaseInfluencer() {}919920/// @brief Static initalization921static void init();922/// @brief Static cleanup923static void cleanup();924925926/// @brief return the current routing mode927double getExtraImpatience() const {928return myExtraImpatience;929}930931/** @brief Sets routing behavior932* @param[in] value an enum value controlling the different modes933*/934void setExtraImpatience(double value) {935myExtraImpatience = value;936}937938protected:939/// @brief dynamic impatience offset940double myExtraImpatience = 0;941942};943944945946/** @brief Returns the velocity/lane influencer947*948* If no influencer was existing before, one is built, first949* @return Reference to this vehicle's speed influencer950*/951virtual BaseInfluencer& getBaseInfluencer() = 0;952953virtual const BaseInfluencer* getBaseInfluencer() const = 0;954955virtual bool hasInfluencer() const = 0;956957/// @brief return routing mode (configures router choice but also handling of transient permission changes)958int getRoutingMode() const {959return myRoutingMode;960}961962/** @brief Sets routing behavior963* @param[in] value an enum value controlling the different modes964*/965void setRoutingMode(int value) {966myRoutingMode = value;967}968969970SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterTT() const;971972/** @brief Returns the vehicle's internal edge travel times/efforts container973*974* If the vehicle does not have such a container, it is built.975* @return The vehicle's knowledge about edge weights976*/977const MSEdgeWeightsStorage& getWeightsStorage() const;978MSEdgeWeightsStorage& getWeightsStorage();979980/** @brief Returns the leader of the vehicle looking for a fixed distance.981*982* If the distance is not given it is calculated from the brake gap.983* The gap returned does not include the minGap.984* @param dist up to which distance to look at least for a leader985* @param considerCrossingFoes Whether vehicles on crossing foe links should be considered986* @return The leading vehicle together with the gap; (0, -1) if no leader was found.987*/988virtual std::pair<const MSVehicle* const, double> getLeader(double dist = 0, bool considerCrossingFoes = true) const {989UNUSED_PARAMETER(dist);990UNUSED_PARAMETER(considerCrossingFoes);991WRITE_WARNING(TL("getLeader not yet implemented for meso"));992return std::make_pair(nullptr, -1);993}994995/** @brief Returns the follower of the vehicle looking for a fixed distance.996*997* If the distance is not given it is set to the value of MSCFModel::brakeGap(2*roadSpeed, 4.5, 0)998* The gap returned does not include the minGap.999* If there are multiple followers, the one that maximizes the term (getSecureGap - gap) is returned.1000* @param dist up to which distance to look at least for a leader1001* @return The leading vehicle together with the gap; (0, -1) if no leader was found.1002*/1003virtual std::pair<const MSVehicle* const, double> getFollower(double dist = 0) const {1004UNUSED_PARAMETER(dist);1005WRITE_WARNING(TL("getFollower not yet implemented for meso"));1006return std::make_pair(nullptr, -1);1007}10081009/** @brief (Re-)Calculates the arrival position and lane from the vehicle parameters1010*/1011void calculateArrivalParams(bool onInit);10121013/// @brief apply departEdge and arrivalEdge attributes1014void setDepartAndArrivalEdge();10151016int getDepartEdge() const;10171018int getInsertionChecks() const;10191020/// @brief interpret stop lane on opposite side of the road1021static MSLane* interpretOppositeStop(SUMOVehicleParameter::Stop& stop);10221023/// @name state io1024//@{1025void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local);1026SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const;1027void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local);1028SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const;10291030/// @brief score only needed when running with gui1031void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score);1032void resetParkingAreaScores();1033void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score);1034void resetChargingStationScores();10351036int getNumberParkingReroutes() const {1037return myNumberParkingReroutes;1038}1039void setNumberParkingReroutes(int value) {1040myNumberParkingReroutes = value;1041}10421043const StoppingPlaceMemory* getParkingMemory() const {1044return myParkingMemory;1045}10461047const StoppingPlaceMemory* getChargingMemory() const {1048return myChargingMemory;1049}1050//@}10511052struct StopEdgeInfo {10531054StopEdgeInfo(const MSEdge* _edge, double _priority, SUMOTime _arrival, double _pos, bool _isSink = false):1055edge(_edge), pos(_pos),1056priority(_priority),1057arrival(_arrival),1058isSink(_isSink) {}10591060const MSEdge* edge;1061double pos;1062double priority;1063SUMOTime arrival;1064bool isSink;1065const SUMOVehicleParameter::Stop* stopPar = nullptr;1066/// @brief values set during routing and used during optimization1067int routeIndex = -1;1068bool skipped = false;1069bool backtracked = false;1070SUMOTime delay = 0;1071/// @brief optional info about stopping place1072std::pair<std::string, SumoXMLTag> nameTag;1073/// @brief set when replacing stop with an alternative1074const MSEdge* origEdge = nullptr;10751076bool operator==(const StopEdgeInfo& o) const {1077return edge == o.edge;1078}1079bool operator!=(const StopEdgeInfo& o) const {1080return !(*this == o);1081}1082};10831084protected:1085/// @brief reset rail signal approach information1086virtual void resetApproachOnReroute() {};10871088/** @brief Returns the list of still pending stop edges1089* also returns the first and last stop position1090*/1091std::vector<StopEdgeInfo> getStopEdges(double& firstPos, double& lastPos, std::set<int>& jumps) const;10921093static double addStopPriority(double p1, double p2);10941095/// @brief replace stop with a same-name alternative that is on the route and return success1096bool replaceWithAlternative(std::list<MSStop>::iterator iter, const MSRouteIterator searchStart, const MSRouteIterator end);10971098protected:1099/// @brief This vehicle's parameter.1100const SUMOVehicleParameter* myParameter;11011102/// @brief This vehicle's route.1103ConstMSRoutePtr myRoute;11041105/// @brief This vehicle's type.1106const MSVehicleType* myType;11071108/// @brief Iterator to current route-edge1109MSRouteIterator myCurrEdge;11101111/// @brief A precomputed factor by which the driver wants to be faster than the speed limit1112double myChosenSpeedFactor;11131114/// @brief The vehicle's list of stops1115std::list<MSStop> myStops;11161117/// @brief The list of stops that the vehicle has already reached1118StopParVector myPastStops;11191120/// @name Move reminder structures1121/// @{11221123/// @brief Definition of a move reminder container1124// The double value holds the relative position offset, i.e.,1125// offset + vehicle-position - moveReminder-position = distance,1126// i.e. the offset is counted up when the vehicle continues to a1127// succeeding lane.1128typedef std::vector< std::pair<MSMoveReminder*, double> > MoveReminderCont;11291130/// @brief Currently relevant move reminders1131MoveReminderCont myMoveReminders;1132/// @}11331134/// @brief The devices this vehicle has1135std::vector<MSVehicleDevice*> myDevices;11361137/// @brief The passengers this vehicle may have1138MSDevice_Transportable* myPersonDevice;11391140/// @brief The containers this vehicle may have1141MSDevice_Transportable* myContainerDevice;11421143/// @brief The emission parameters this vehicle may have1144mutable EnergyParams* myEnergyParams;11451146/// @brief The real departure time1147SUMOTime myDeparture;11481149/// @brief The real depart position1150double myDepartPos;11511152/// @brief The position on the destination lane where the vehicle stops1153double myArrivalPos;11541155/// @brief The destination lane where the vehicle stops1156int myArrivalLane;11571158/// @brief The number of reroutings1159int myNumberReroutes;11601161/// @brief The offset when adding route stops with 'until' on route replacement1162SUMOTime myStopUntilOffset;11631164/// @brief A simple odometer to keep track of the length of the route already driven1165double myOdometer;11661167/// @brief status of the current vehicle route1168int myRouteValidity;11691170/// memory for parking search1171StoppingPlaceMemory* myParkingMemory = nullptr;1172StoppingPlaceMemory* myChargingMemory = nullptr;1173int myNumberParkingReroutes = 0;11741175/// @brief Whether this vehicle is registered as waiting for a person or container (for deadlock-recognition)1176bool myAmRegisteredAsWaiting = false;11771178/* @brief magic value for undeparted vehicles1179* @note: in previous versions this was -11180*/1181static const SUMOTime NOT_YET_DEPARTED;11821183static std::vector<MSTransportable*> myEmptyTransportableVector;11841185/* @brief The logical 'reversed' state of the vehicle - intended to be used by drawing functions1186* @note: only set by vClass rail reversing at the moment1187*/1188bool myAmReversed = false;11891190///@brief routing mode (see TraCIConstants.h)1191int myRoutingMode;11921193private:1194const NumericalID myNumericalID;11951196const long long int myRandomSeed;11971198/* @brief The vehicle's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage1199* @note member is initialized on first access */1200mutable MSEdgeWeightsStorage* myEdgeWeights;12011202MSEdgeWeightsStorage& _getWeightsStorage() const;12031204static NumericalID myCurrentNumericalIndex;12051206/// @brief init model parameters from generic params1207void initTransientModelParams();12081209/// @brief reconstruct flow id from vehicle id1210std::string getFlowID() const;12111212/// @brief remove route at the end of the simulation1213void checkRouteRemoval();12141215/// @brief helper function1216bool insertJump(int nextStopIndex, MSRouteIterator itStart, std::string& errorMsg);12171218/// @brief patch stop.pars.index to record the number of skipped candidate edges before stop.edge (in a looped route)1219void setSkips(MSStop& stop, int prevActiveStops);12201221/// @brief remove outdated driveways on reroute1222SUMOTime activateRemindersOnReroute(SUMOTime currentTime);12231224private:1225/// invalidated assignment operator1226MSBaseVehicle& operator=(const MSBaseVehicle& s) = delete;12271228#ifdef _DEBUG1229public:1230static void initMoveReminderOutput(const OptionsCont& oc);12311232protected:1233/// @brief optionally generate movereminder-output for this vehicle1234void traceMoveReminder(const std::string& type, MSMoveReminder* rem, double pos, bool keep) const;12351236/// @brief whether this vehicle shall trace its moveReminders1237const bool myTraceMoveReminders;1238private:1239/// @brief vehicles which shall trace their move reminders1240static std::set<std::string> myShallTraceMoveReminders;1241#endif124212431244};124512461247