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: 2024-11-20 15:55:46 Functions: - 0 0

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

Generated by: LCOV version 2.0-1