LCOV - code coverage report
Current view: top level - src/utils/vehicle - SUMOVehicle.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 0.0 % 1 0
Test Date: 2026-04-16 16:39:47 Functions: - 0 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    SUMOVehicle.h
      15              : /// @author  Michael Behrisch
      16              : /// @author  Daniel Krajzewicz
      17              : /// @author  Jakob Erdmann
      18              : /// @date    Tue, 17 Feb 2009
      19              : ///
      20              : // Abstract base class for vehicle representations
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <vector>
      26              : #include <typeinfo>
      27              : #include <utils/common/SUMOTime.h>
      28              : #include <utils/common/Named.h>
      29              : #include <utils/router/SUMOAbstractRouter.h>
      30              : #include <utils/vehicle/SUMOVehicleParameter.h>
      31              : #include <utils/vehicle/SUMOTrafficObject.h>
      32              : #include <utils/iodevices/OutputDevice.h>
      33              : 
      34              : 
      35              : // ===========================================================================
      36              : // class declarations
      37              : // ===========================================================================
      38              : class MSRoute;
      39              : class MSEdge;
      40              : class MSLane;
      41              : class MSPerson;
      42              : class MSStop;
      43              : class MSTransportable;
      44              : class MSParkingArea;
      45              : class MSChargingStation;
      46              : class MSStoppingPlace;
      47              : class MSVehicleDevice;
      48              : class SUMOSAXAttributes;
      49              : class EnergyParams;
      50              : class PositionVector;
      51              : class MFXOptionalLock;
      52              : 
      53              : typedef std::vector<const MSEdge*> ConstMSEdgeVector;
      54              : 
      55              : 
      56              : // ===========================================================================
      57              : // class definitions
      58              : // ===========================================================================
      59              : /**
      60              :  * @class SUMOVehicle
      61              :  * @brief Representation of a vehicle
      62              :  */
      63              : class SUMOVehicle : public SUMOTrafficObject {
      64              : public:
      65              : 
      66              :     /// @brief Constructor
      67              :     SUMOVehicle(const std::string& id) : SUMOTrafficObject(id) {}
      68              : 
      69              :     /// @brief Destructor
      70            0 :     virtual ~SUMOVehicle() {}
      71              : 
      72              :     /** @brief Get the vehicle's lateral position on the lane
      73              :      * @return The lateral position of the vehicle (in m relative to the
      74              :      * centerline of the lane)
      75              :      */
      76              :     virtual double getLateralPositionOnLane() const = 0;
      77              : 
      78              :     /** @brief Get the vehicle's angle
      79              :      * @return The angle of the vehicle (in degree)
      80              :      */
      81              :     virtual double getAngle() const = 0;
      82              : 
      83              :     /// Returns the current route
      84              :     virtual const MSRoute& getRoute() const = 0;
      85              : 
      86              :     /// Returns the current route
      87              :     virtual ConstMSRoutePtr getRoutePtr() const = 0;
      88              : 
      89              :     /** @brief Returns the nSuccs'th successor of edge the vehicle is currently at
      90              :      *
      91              :      * If the rest of the route (counted from the current edge) than nSuccs,
      92              :      *  0 is returned.
      93              :      * @param[in] nSuccs The number of edge to look forward
      94              :      * @return The nSuccs'th following edge in the vehicle's route
      95              :      */
      96              :     virtual const MSEdge* succEdge(int nSuccs) const = 0;
      97              : 
      98              :     /** @brief Returns the starting point for reroutes (usually the current edge)
      99              :      *
     100              :      * This differs from myCurrEdge depending on braking distance and rail signals
     101              :      * @return The rerouting start point
     102              :      */
     103              :     virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const = 0;
     104              : 
     105              :     /** @brief Replaces the current route by the given edges
     106              :      *
     107              :      * It is possible that the new route is not accepted, if a) it does not
     108              :      *  contain the vehicle's current edge, or b) something fails on insertion
     109              :      *  into the routes container (see in-line comments).
     110              :      *
     111              :      * @param[in] edges The new list of edges to pass
     112              :      * @param[in] onInit Whether the vehicle starts with this route
     113              :      * @param[in] check Whether the route should be checked for validity
     114              :      * @param[in] removeStops Whether stops should be removed if they do not fit onto the new route
     115              :      * @return Whether the new route was accepted
     116              :      */
     117              :     virtual 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;
     118              : 
     119              :     /** @brief Performs a rerouting using the given router
     120              :      *
     121              :      * Tries to find a new route between the current edge and the destination edge, first.
     122              :      * Tries to replace the current route by the new one using replaceRoute.
     123              :      *
     124              :      * @param[in] t The time for which the route is computed
     125              :      * @param[in] router The router to use
     126              :      * @return whether a valid route was found
     127              :      * @see replaceRoute
     128              :      */
     129              :     virtual 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;
     130              : 
     131              :     /** @brief Validates the current or given route
     132              :      * @param[out] msg Description why the route is not valid (if it is the case)
     133              :      * @param[in] route The route to check (or 0 if the current route shall be checked)
     134              :      * @return Whether the vehicle's current route is valid
     135              :      */
     136              :     virtual bool hasValidRoute(std::string& msg, ConstMSRoutePtr route = 0) const = 0;
     137              :     /// @brief checks wether the vehicle can depart on the first edge
     138              :     virtual bool hasValidRouteStart(std::string& msg) = 0;
     139              : 
     140              :     /// @brief computes validity attributes for the current route
     141              :     virtual int getRouteValidity(bool update = true, bool silent = false, std::string* msgReturn = nullptr) = 0;
     142              : 
     143              :     /** @brief Returns an iterator pointing to the current edge in this vehicles route
     144              :      * @return The current route pointer
     145              :      */
     146              :     virtual const ConstMSEdgeVector::const_iterator& getCurrentRouteEdge() const = 0;
     147              : 
     148              :     /// @return the current edge which may be internal
     149              :     virtual const MSEdge* getCurrentEdge() const = 0;
     150              : 
     151              :     /** @brief Returns the vehicle's emission model parameter
     152              :      *
     153              :      * @return The vehicle's emission parameters
     154              :      */
     155              :     virtual EnergyParams* getEmissionParameters() const = 0;
     156              : 
     157              :     /** @brief Replaces the vehicle's parameter
     158              :      */
     159              :     virtual void replaceParameter(const SUMOVehicleParameter* newParameter) = 0;
     160              : 
     161              :     /** @brief Called when the vehicle is inserted into the network
     162              :      *
     163              :      * Sets optional information about departure time, informs the vehicle
     164              :      *  control about a further running vehicle.
     165              :      */
     166              :     virtual void onDepart() = 0;
     167              : 
     168              :     /** @brief Returns the information whether the vehicle is on a road (is simulated)
     169              :      * @return Whether the vehicle is simulated
     170              :      */
     171              :     virtual bool isOnRoad() const = 0;
     172              : 
     173              :     /** @brief Returns whether the vehicle is idling (waiting to re-enter the net
     174              :      * @return true if the vehicle is waiting to enter the net (eg after parking)
     175              :     */
     176              :     virtual bool isIdling() const = 0;
     177              : 
     178              :     /** @brief Returns the information whether the front of the vehhicle is on the given lane
     179              :      * @return Whether the vehicle's front is on that lane
     180              :      */
     181              :     virtual bool isFrontOnLane(const MSLane*) const = 0;
     182              : 
     183              :     /** @brief Returns the information whether the vehicle is parked
     184              :      * @return Whether the vehicle is parked
     185              :      */
     186              :     virtual bool isParking() const = 0;
     187              : 
     188              :     /** @brief Returns the information whether the vehicle is fully controlled
     189              :      * via TraCI
     190              :      * @return Whether the vehicle is remote-controlled
     191              :      */
     192              :     virtual bool isRemoteControlled() const = 0;
     193              : 
     194              :     /** @brief Returns the information whether the vehicle is fully controlled
     195              :      * via TraCI
     196              :      * @return Whether the vehicle was remote-controlled within the given time range
     197              :      */
     198              :     virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const = 0;
     199              : 
     200              :     /** @brief Returns this vehicle's real departure time
     201              :      * @return This vehicle's real departure time
     202              :      */
     203              :     virtual SUMOTime getDeparture() const = 0;
     204              : 
     205              :     /** @brief Returns this vehicle's real departure position
     206              :      * @return This vehicle's real departure position
     207              :      */
     208              :     virtual double getDepartPos() const = 0;
     209              : 
     210              :     /** @brief Returns this vehicle's desired arrivalPos for its current route
     211              :      * (may change on reroute)
     212              :      * @return This vehicle's real arrivalPos
     213              :      */
     214              :     virtual double getArrivalPos() const = 0;
     215              : 
     216              :     /** @brief Sets this vehicle's desired arrivalPos for its current route
     217              :      */
     218              :     virtual void setArrivalPos(double arrivalPos) = 0;
     219              : 
     220              :     /** @brief Returns whether this vehicle has departed
     221              :      */
     222              :     virtual bool hasDeparted() const = 0;
     223              : 
     224              :     /** @brief Returns the edge on which this vehicle shall depart
     225              :      */
     226              :     virtual int getDepartEdge() const = 0;
     227              : 
     228              :     /** @brief Returns the distance that was already driven by this vehicle
     229              :      * @return the distance driven [m]
     230              :      */
     231              :     virtual double getOdometer() const = 0;
     232              : 
     233              :     /** @brief Returns the number of new routes this vehicle got
     234              :      * @return the number of new routes this vehicle got
     235              :      */
     236              :     virtual int getNumberReroutes() const = 0;
     237              : 
     238              :     /// @brief whether the given transportable is allowed to board this vehicle
     239              :     virtual bool allowsBoarding(const MSTransportable* t) const = 0;
     240              : 
     241              :     /** @brief Adds a person or container to this vehicle
     242              :      *
     243              :      * @param[in] transportable The person/container to add
     244              :      */
     245              :     virtual void addTransportable(MSTransportable* transportable) = 0;
     246              : 
     247              :     /** @brief Returns the number of persons
     248              :      * @return The number of passengers on-board
     249              :      */
     250              :     virtual int getPersonNumber() const = 0;
     251              : 
     252              :     /** @brief Returns the list of persons
     253              :      * @return The list of passengers on-board
     254              :      */
     255              :     virtual std::vector<std::string> getPersonIDList() const = 0;
     256              : 
     257              :     /** @brief Returns the number of containers
     258              :      * @return The number of contaiers on-board
     259              :      */
     260              :     virtual int getContainerNumber() const = 0;
     261              : 
     262              :     /// @brief removes a person or container
     263              :     virtual void removeTransportable(MSTransportable* t) = 0;
     264              : 
     265              :     /// @brief removes a person or containers mass
     266              :     virtual void removeTransportableMass(MSTransportable* t) = 0;
     267              : 
     268              :     /// @brief retrieve riding persons
     269              :     virtual const std::vector<MSTransportable*>& getPersons() const = 0;
     270              : 
     271              :     /// @brief retrieve riding containers
     272              :     virtual const std::vector<MSTransportable*>& getContainers() const = 0;
     273              : 
     274              :     /** @brief Adds a stop
     275              :      *
     276              :      * The stop is put into the sorted list.
     277              :      * @param[in] stop The stop to add
     278              :      * @return Whether the stop could be added
     279              :      */
     280              :     virtual bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,
     281              :                          ConstMSEdgeVector::const_iterator* searchStart = 0) = 0;
     282              : 
     283              :     /// @brief return list of route indices and stop positions for the remaining stops
     284              :     virtual std::vector<std::pair<int, double> > getStopIndices() const = 0;
     285              : 
     286              :     /// @brief returns whether the vehicle serves a public transport line that serves the given stop
     287              :     virtual bool isLineStop(double position) const = 0;
     288              : 
     289              :     /// @brief deletes the next stop at the given index if it exists
     290              :     virtual bool abortNextStop(int nextStopIndex = 0) = 0;
     291              : 
     292              : 
     293              :     /**
     294              :     * returns the next imminent stop in the stop queue
     295              :     * @return the upcoming stop
     296              :     */
     297              :     virtual MSParkingArea* getNextParkingArea() = 0;
     298              : 
     299              :     /** @brief Replaces a stop
     300              :       *
     301              :       * The stop replace the next stop into the sorted list.
     302              :       * @param[in] stop The stop to add
     303              :       * @return Whether the stop could be added
     304              :       */
     305              :     virtual bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg) = 0;
     306              : 
     307              :     virtual const std::vector<std::string>& getParkingBadges() const = 0;
     308              : 
     309              :     /// @brief Returns the remaining stop duration for a stopped vehicle or 0
     310              :     virtual SUMOTime remainingStopDuration() const = 0;
     311              : 
     312              :     /** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue
     313              :      */
     314              :     virtual bool isStopped() const = 0;
     315              :     /** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue
     316              :      */
     317              :     virtual bool isStoppedTriggered() const = 0;
     318              : 
     319              :     /** @brief Returns whether the vehicle is at a stop and parking
     320              :      */
     321              :     virtual bool isStoppedParking() const = 0;
     322              : 
     323              :     /** @brief Returns whether the vehicle is stopped in the range of the given position */
     324              :     virtual bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const = 0;
     325              : 
     326              :     /** @brief Returns whether the vehicle stops at the given stopping place */
     327              :     virtual bool stopsAt(MSStoppingPlace* stop) const = 0;
     328              : 
     329              :     /** @brief Returns whether the vehicle stops at the given edge */
     330              :     virtual bool stopsAtEdge(const MSEdge* edge) const = 0;
     331              : 
     332              :     /** @brief Returns whether the vehicle has to stop somewhere
     333              :      * @return Whether the vehicle has to stop somewhere
     334              :      */
     335              :     virtual bool hasStops() const = 0;
     336              : 
     337              :     /**
     338              :      * returns the list of stops not yet reached in the stop queue
     339              :      * @return the list of upcoming stops
     340              :      */
     341              :     virtual const std::list<MSStop>& getStops() const = 0;
     342              : 
     343              :     /**
     344              :     * returns the next imminent stop in the stop queue
     345              :     * @return the upcoming stop
     346              :     */
     347              :     virtual const MSStop& getNextStop() const = 0;
     348              : 
     349              :     /**
     350              :     * returns the next imminent stop in the stop queue
     351              :     * @return the upcoming stop
     352              :     */
     353              :     virtual MSStop& getNextStopMutable() = 0;
     354              : 
     355              :     /// @brief mark vehicle as active
     356              :     virtual void unregisterWaiting() = 0;
     357              : 
     358              :     /** @brief Returns parameters of the next stop or nullptr **/
     359              :     virtual const SUMOVehicleParameter::Stop* getNextStopParameter() const = 0;
     360              : 
     361              :     /// @brief get remaining stop duration or 0 if the vehicle isn't stopped
     362              :     virtual SUMOTime getStopDuration() const = 0;
     363              : 
     364              :     /**
     365              :      * schedule a new stop for the vehicle; each time a stop is reached, the vehicle
     366              :      * will wait for the given duration before continuing on its route
     367              :      * @param[in] stop Stop parameters
     368              :      * @param[out] errorMsg returned error message
     369              :      */
     370              :     virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg) = 0;
     371              : 
     372              :     virtual void setChosenSpeedFactor(const double factor) = 0;
     373              : 
     374              :     virtual SUMOTime getDepartDelay() const = 0;
     375              : 
     376              :     virtual SUMOTime getTimeLoss() const = 0;
     377              : 
     378              :     /// @brief get distance for coming to a stop (used for rerouting checks)
     379              :     virtual double getBrakeGap(bool delayed = false) const = 0;
     380              : 
     381              :     /// @brief Returns this vehicles impatience
     382              :     virtual double getImpatience() const = 0;
     383              : 
     384              :     /** @brief Returns this vehicle's devices
     385              :      * @return This vehicle's devices
     386              :      */
     387              :     virtual const std::vector<MSVehicleDevice*>& getDevices() const = 0;
     388              : 
     389              :     /// @brief Returns the vehicles's length
     390              :     virtual double getLength() const = 0;
     391              : 
     392              :     /* @brief Return whether this vehicle must be treated like a railway vehicle
     393              :      * either due to its vClass or the vClass of it's edge */
     394              :     virtual bool isRail() const = 0;
     395              : 
     396              :     virtual SUMOTime getLastActionTime() const = 0;
     397              : 
     398              :     /// @brief get bounding rectangle
     399              :     virtual PositionVector getBoundingBox(double offset = 0) const = 0;
     400              : 
     401              :     virtual std::unique_ptr<MFXOptionalLock> getScopeLock() = 0;
     402              : 
     403              :     /// @name parking memory io
     404              :     //@{
     405              :     virtual void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local) = 0;
     406              :     virtual SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const = 0;
     407              :     virtual void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score) = 0;
     408              :     virtual void resetParkingAreaScores() = 0;
     409              :     virtual int getNumberParkingReroutes() const = 0;
     410              :     virtual void setNumberParkingReroutes(int value) = 0;
     411              : 
     412              :     virtual void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local) = 0;
     413              :     virtual SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const = 0;
     414              :     virtual void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score) = 0;
     415              :     virtual void resetChargingStationScores() = 0;
     416              :     //@}
     417              : 
     418              :     /// @name state io
     419              :     //@{
     420              : 
     421              :     /// Saves the states of a vehicle
     422              :     virtual void saveState(OutputDevice& out) = 0;
     423              : 
     424              :     /** @brief Loads the state of this vehicle from the given description
     425              :      */
     426              :     virtual void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset) = 0;
     427              :     //@}
     428              : };
        

Generated by: LCOV version 2.0-1