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-03-02 16:00:03 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              :     /** @brief Returns the vehicle's emission model parameter
     149              :      *
     150              :      * @return The vehicle's emission parameters
     151              :      */
     152              :     virtual EnergyParams* getEmissionParameters() const = 0;
     153              : 
     154              :     /** @brief Replaces the vehicle's parameter
     155              :      */
     156              :     virtual void replaceParameter(const SUMOVehicleParameter* newParameter) = 0;
     157              : 
     158              :     /** @brief Called when the vehicle is inserted into the network
     159              :      *
     160              :      * Sets optional information about departure time, informs the vehicle
     161              :      *  control about a further running vehicle.
     162              :      */
     163              :     virtual void onDepart() = 0;
     164              : 
     165              :     /** @brief Returns the information whether the vehicle is on a road (is simulated)
     166              :      * @return Whether the vehicle is simulated
     167              :      */
     168              :     virtual bool isOnRoad() const = 0;
     169              : 
     170              :     /** @brief Returns whether the vehicle is idling (waiting to re-enter the net
     171              :      * @return true if the vehicle is waiting to enter the net (eg after parking)
     172              :     */
     173              :     virtual bool isIdling() const = 0;
     174              : 
     175              :     /** @brief Returns the information whether the front of the vehhicle is on the given lane
     176              :      * @return Whether the vehicle's front is on that lane
     177              :      */
     178              :     virtual bool isFrontOnLane(const MSLane*) const = 0;
     179              : 
     180              :     /** @brief Returns the information whether the vehicle is parked
     181              :      * @return Whether the vehicle is parked
     182              :      */
     183              :     virtual bool isParking() const = 0;
     184              : 
     185              :     /** @brief Returns the information whether the vehicle is fully controlled
     186              :      * via TraCI
     187              :      * @return Whether the vehicle is remote-controlled
     188              :      */
     189              :     virtual bool isRemoteControlled() const = 0;
     190              : 
     191              :     /** @brief Returns the information whether the vehicle is fully controlled
     192              :      * via TraCI
     193              :      * @return Whether the vehicle was remote-controlled within the given time range
     194              :      */
     195              :     virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const = 0;
     196              : 
     197              :     /** @brief Returns this vehicle's real departure time
     198              :      * @return This vehicle's real departure time
     199              :      */
     200              :     virtual SUMOTime getDeparture() const = 0;
     201              : 
     202              :     /** @brief Returns this vehicle's real departure position
     203              :      * @return This vehicle's real departure position
     204              :      */
     205              :     virtual double getDepartPos() const = 0;
     206              : 
     207              :     /** @brief Returns this vehicle's desired arrivalPos for its current route
     208              :      * (may change on reroute)
     209              :      * @return This vehicle's real arrivalPos
     210              :      */
     211              :     virtual double getArrivalPos() const = 0;
     212              : 
     213              :     /** @brief Sets this vehicle's desired arrivalPos for its current route
     214              :      */
     215              :     virtual void setArrivalPos(double arrivalPos) = 0;
     216              : 
     217              :     /** @brief Returns whether this vehicle has departed
     218              :      */
     219              :     virtual bool hasDeparted() const = 0;
     220              : 
     221              :     /** @brief Returns the edge on which this vehicle shall depart
     222              :      */
     223              :     virtual int getDepartEdge() const = 0;
     224              : 
     225              :     /** @brief Returns the distance that was already driven by this vehicle
     226              :      * @return the distance driven [m]
     227              :      */
     228              :     virtual double getOdometer() const = 0;
     229              : 
     230              :     /** @brief Returns the number of new routes this vehicle got
     231              :      * @return the number of new routes this vehicle got
     232              :      */
     233              :     virtual int getNumberReroutes() const = 0;
     234              : 
     235              :     /// @brief whether the given transportable is allowed to board this vehicle
     236              :     virtual bool allowsBoarding(const MSTransportable* t) const = 0;
     237              : 
     238              :     /** @brief Adds a person or container to this vehicle
     239              :      *
     240              :      * @param[in] transportable The person/container to add
     241              :      */
     242              :     virtual void addTransportable(MSTransportable* transportable) = 0;
     243              : 
     244              :     /** @brief Returns the number of persons
     245              :      * @return The number of passengers on-board
     246              :      */
     247              :     virtual int getPersonNumber() const = 0;
     248              : 
     249              :     /** @brief Returns the list of persons
     250              :      * @return The list of passengers on-board
     251              :      */
     252              :     virtual std::vector<std::string> getPersonIDList() const = 0;
     253              : 
     254              :     /** @brief Returns the number of containers
     255              :      * @return The number of contaiers on-board
     256              :      */
     257              :     virtual int getContainerNumber() const = 0;
     258              : 
     259              :     /// @brief removes a person or container
     260              :     virtual void removeTransportable(MSTransportable* t) = 0;
     261              : 
     262              :     /// @brief removes a person or containers mass
     263              :     virtual void removeTransportableMass(MSTransportable* t) = 0;
     264              : 
     265              :     /// @brief retrieve riding persons
     266              :     virtual const std::vector<MSTransportable*>& getPersons() const = 0;
     267              : 
     268              :     /// @brief retrieve riding containers
     269              :     virtual const std::vector<MSTransportable*>& getContainers() const = 0;
     270              : 
     271              :     /** @brief Adds a stop
     272              :      *
     273              :      * The stop is put into the sorted list.
     274              :      * @param[in] stop The stop to add
     275              :      * @return Whether the stop could be added
     276              :      */
     277              :     virtual bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,
     278              :                          ConstMSEdgeVector::const_iterator* searchStart = 0) = 0;
     279              : 
     280              :     /// @brief return list of route indices and stop positions for the remaining stops
     281              :     virtual std::vector<std::pair<int, double> > getStopIndices() const = 0;
     282              : 
     283              :     /// @brief returns whether the vehicle serves a public transport line that serves the given stop
     284              :     virtual bool isLineStop(double position) const = 0;
     285              : 
     286              :     /// @brief deletes the next stop at the given index if it exists
     287              :     virtual bool abortNextStop(int nextStopIndex = 0) = 0;
     288              : 
     289              : 
     290              :     /**
     291              :     * returns the next imminent stop in the stop queue
     292              :     * @return the upcoming stop
     293              :     */
     294              :     virtual MSParkingArea* getNextParkingArea() = 0;
     295              : 
     296              :     /** @brief Replaces a stop
     297              :       *
     298              :       * The stop replace the next stop into the sorted list.
     299              :       * @param[in] stop The stop to add
     300              :       * @return Whether the stop could be added
     301              :       */
     302              :     virtual bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg) = 0;
     303              : 
     304              :     virtual const std::vector<std::string>& getParkingBadges() const = 0;
     305              : 
     306              :     /// @brief Returns the remaining stop duration for a stopped vehicle or 0
     307              :     virtual SUMOTime remainingStopDuration() const = 0;
     308              : 
     309              :     /** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue
     310              :      */
     311              :     virtual bool isStopped() const = 0;
     312              :     /** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue
     313              :      */
     314              :     virtual bool isStoppedTriggered() const = 0;
     315              : 
     316              :     /** @brief Returns whether the vehicle is at a stop and parking
     317              :      */
     318              :     virtual bool isStoppedParking() const = 0;
     319              : 
     320              :     /** @brief Returns whether the vehicle is stopped in the range of the given position */
     321              :     virtual bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const = 0;
     322              : 
     323              :     /** @brief Returns whether the vehicle stops at the given stopping place */
     324              :     virtual bool stopsAt(MSStoppingPlace* stop) const = 0;
     325              : 
     326              :     /** @brief Returns whether the vehicle stops at the given edge */
     327              :     virtual bool stopsAtEdge(const MSEdge* edge) const = 0;
     328              : 
     329              :     /** @brief Returns whether the vehicle has to stop somewhere
     330              :      * @return Whether the vehicle has to stop somewhere
     331              :      */
     332              :     virtual bool hasStops() const = 0;
     333              : 
     334              :     /**
     335              :      * returns the list of stops not yet reached in the stop queue
     336              :      * @return the list of upcoming stops
     337              :      */
     338              :     virtual const std::list<MSStop>& getStops() const = 0;
     339              : 
     340              :     /**
     341              :     * returns the next imminent stop in the stop queue
     342              :     * @return the upcoming stop
     343              :     */
     344              :     virtual const MSStop& getNextStop() const = 0;
     345              : 
     346              :     /**
     347              :     * returns the next imminent stop in the stop queue
     348              :     * @return the upcoming stop
     349              :     */
     350              :     virtual MSStop& getNextStopMutable() = 0;
     351              : 
     352              :     /// @brief mark vehicle as active
     353              :     virtual void unregisterWaiting() = 0;
     354              : 
     355              :     /** @brief Returns parameters of the next stop or nullptr **/
     356              :     virtual const SUMOVehicleParameter::Stop* getNextStopParameter() const = 0;
     357              : 
     358              :     /// @brief get remaining stop duration or 0 if the vehicle isn't stopped
     359              :     virtual SUMOTime getStopDuration() const = 0;
     360              : 
     361              :     /**
     362              :      * schedule a new stop for the vehicle; each time a stop is reached, the vehicle
     363              :      * will wait for the given duration before continuing on its route
     364              :      * @param[in] stop Stop parameters
     365              :      * @param[out] errorMsg returned error message
     366              :      */
     367              :     virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg) = 0;
     368              : 
     369              :     virtual void setChosenSpeedFactor(const double factor) = 0;
     370              : 
     371              :     virtual SUMOTime getDepartDelay() const = 0;
     372              : 
     373              :     virtual SUMOTime getTimeLoss() const = 0;
     374              : 
     375              :     /// @brief get distance for coming to a stop (used for rerouting checks)
     376              :     virtual double getBrakeGap(bool delayed = false) const = 0;
     377              : 
     378              :     /// @brief Returns this vehicles impatience
     379              :     virtual double getImpatience() const = 0;
     380              : 
     381              :     /** @brief Returns this vehicle's devices
     382              :      * @return This vehicle's devices
     383              :      */
     384              :     virtual const std::vector<MSVehicleDevice*>& getDevices() const = 0;
     385              : 
     386              :     /// @brief Returns the vehicles's length
     387              :     virtual double getLength() const = 0;
     388              : 
     389              :     /* @brief Return whether this vehicle must be treated like a railway vehicle
     390              :      * either due to its vClass or the vClass of it's edge */
     391              :     virtual bool isRail() const = 0;
     392              : 
     393              :     virtual SUMOTime getLastActionTime() const = 0;
     394              : 
     395              :     /// @brief get bounding rectangle
     396              :     virtual PositionVector getBoundingBox(double offset = 0) const = 0;
     397              : 
     398              :     virtual std::unique_ptr<MFXOptionalLock> getScopeLock() = 0;
     399              : 
     400              :     /// @name parking memory io
     401              :     //@{
     402              :     virtual void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local) = 0;
     403              :     virtual SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const = 0;
     404              :     virtual void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score) = 0;
     405              :     virtual void resetParkingAreaScores() = 0;
     406              :     virtual int getNumberParkingReroutes() const = 0;
     407              :     virtual void setNumberParkingReroutes(int value) = 0;
     408              : 
     409              :     virtual void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local) = 0;
     410              :     virtual SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const = 0;
     411              :     virtual void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score) = 0;
     412              :     virtual void resetChargingStationScores() = 0;
     413              :     //@}
     414              : 
     415              :     /// @name state io
     416              :     //@{
     417              : 
     418              :     /// Saves the states of a vehicle
     419              :     virtual void saveState(OutputDevice& out) = 0;
     420              : 
     421              :     /** @brief Loads the state of this vehicle from the given description
     422              :      */
     423              :     virtual void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset) = 0;
     424              :     //@}
     425              : };
        

Generated by: LCOV version 2.0-1