LCOV - code coverage report
Current view: top level - src/mesosim - MEVehicle.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 84.6 % 39 33
Test Date: 2026-04-16 16:39:47 Functions: 61.5 % 13 8

            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    MEVehicle.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @date    Tue, May 2005
      17              : ///
      18              : // A vehicle from the mesoscopic point of view
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <iostream>
      24              : #include <cassert>
      25              : #include <map>
      26              : #include <vector>
      27              : #include <microsim/MSBaseVehicle.h>
      28              : #include <microsim/MSEdge.h>
      29              : #include <utils/common/StdDefs.h>
      30              : #include "MESegment.h"
      31              : 
      32              : class MSLane;
      33              : class MSLink;
      34              : 
      35              : // ===========================================================================
      36              : // class definitions
      37              : // ===========================================================================
      38              : /**
      39              :  * @class MEVehicle
      40              :  * @brief A vehicle from the mesoscopic point of view
      41              :  */
      42       306754 : class MEVehicle : public MSBaseVehicle {
      43              : public:
      44              :     /** @brief Constructor
      45              :      * @param[in] pars The vehicle description
      46              :      * @param[in] route The vehicle's route
      47              :      * @param[in] type The vehicle's type
      48              :      * @param[in] speedFactor The factor for driven lane's speed limits
      49              :      * @exception ProcessError If a value is wrong
      50              :      */
      51              :     MEVehicle(SUMOVehicleParameter* pars, ConstMSRoutePtr route,
      52              :               MSVehicleType* type, const double speedFactor);
      53              : 
      54              : 
      55              :     /** @brief Get the vehicle's position along the lane
      56              :      * @return The position of the vehicle (in m from the lane's begin)
      57              :      */
      58              :     double getPositionOnLane() const;
      59              : 
      60              : 
      61              :     /** @brief Get the vehicle's position relative to the given lane
      62              :      *  @return The back position of the vehicle (in m from the given lane's begin)
      63              :      */
      64              :     double getBackPositionOnLane(const MSLane* lane) const;
      65              : 
      66              : 
      67              :     /** @brief Returns the vehicle's direction in degrees
      68              :      * @return The vehicle's current angle
      69              :      */
      70              :     double getAngle() const;
      71              : 
      72              : 
      73              :     /** @brief Returns the slope of the road at vehicle's position in degrees
      74              :      * @return The slope
      75              :      */
      76              :     double getSlope() const;
      77              : 
      78              :     /** @brief Returns the edge the vehicle is currently at (possibly an
      79              :      * internal edge)
      80              :      */
      81              :     const MSEdge* getCurrentEdge() const;
      82              : 
      83              :     /** @brief Returns the lane the vehicle is on
      84              :     * @return The vehicle's current lane
      85              :     */
      86     11595141 :     const MSLane* getLane() const {
      87     11595141 :         return nullptr;
      88              :     }
      89              : 
      90          978 :     const MSLane* getBackLane() const {
      91          978 :         return nullptr;
      92              :     }
      93              : 
      94              :     /** @brief Return current position (x/y, cartesian)
      95              :      *
      96              :      * If the vehicle's myLane is 0, Position::INVALID.
      97              :      * @param[in] offset optional offset in longitudinal direction
      98              :      * @return The current position (in cartesian coordinates)
      99              :      * @see myLane
     100              :      */
     101              :     Position getPosition(const double offset = 0) const;
     102              : 
     103              :     /// @brief get bounding rectangle
     104              :     PositionVector getBoundingBox(double offset = 0) const;
     105              : 
     106              :     /** @brief Returns the vehicle's estimated speed assuming no delays
     107              :      * @return The vehicle's estimated speed
     108              :      * @note This is only an upper bound. The speed will be lower if the preceding vehicle is delayed
     109              :      */
     110              :     double getSpeed() const;
     111              : 
     112              :     /** @brief Returns the vehicle's estimated average speed on the segment assuming no further delays
     113              :      * @return The vehicle's estimated average speed
     114              :      * @note This is only an upper bound. The speed will be lower if the preceding vehicle is delayed
     115              :      */
     116              :     double getAverageSpeed() const;
     117              : 
     118              :     /// @brief Returns the vehicle's estimated speed after driving across the link
     119              :     double estimateLeaveSpeed(const MSLink* link) const;
     120              : 
     121              : 
     122              :     /** @brief Returns the vehicle's estimated speed taking into account delays
     123              :      * @return The vehicle's estimated speed
     124              :      * @param[in, out] earliestArrival A lower bound on leaveTime, modified to contain new lower bound on leave Time
     125              :      * @note This is only an upper bound. The speed may be even lower if there are further delays downstream
     126              :      */
     127              :     double getConservativeSpeed(SUMOTime& earliestArrival) const;
     128              : 
     129              :     /// @name insertion/removal
     130              :     //@{
     131              : 
     132              :     /** @brief Called when the vehicle is removed from the network.
     133              :      *
     134              :      * Moves along work reminders and
     135              :      *  informs all devices about quitting. Calls "leaveLane" then.
     136              :      *
     137              :      * @param[in] reason why the vehicle leaves (reached its destination, parking, teleport)
     138              :      */
     139              :     void onRemovalFromNet(const MSMoveReminder::Notification reason);
     140              :     //@}
     141              : 
     142              : 
     143              :     /** @brief Update when the vehicle enters a new edge in the move step.
     144              :      * @return Whether the vehicle's route has ended (due to vaporization, or because the destination was reached)
     145              :      */
     146              :     bool moveRoutePointer();
     147              : 
     148              :     /** @brief Returns whether this vehicle has already arrived
     149              :      * (reached the arrivalPosition on its final edge)
     150              :      */
     151              :     bool hasArrived() const;
     152              : 
     153              :     /** @brief Returns the information whether the vehicle is on a road (is simulated)
     154              :      * @return Whether the vehicle is simulated
     155              :      */
     156              :     bool isOnRoad() const;
     157              : 
     158              :     /** @brief Returns whether the vehicle is trying to re-enter the net
     159              :      * @return true if the vehicle is trying to enter the net (eg after parking)
     160              :      */
     161              :     virtual bool isIdling() const;
     162              : 
     163              : 
     164              :     /** @brief registers vehicle with the given link
     165              :      *
     166              :      * @param[in] link the link on which the car shall register its approach
     167              :      */
     168              :     void setApproaching(MSLink* link);
     169              : 
     170              :     /// @brief Returns the remaining stop duration for a stopped vehicle or 0
     171            0 :     SUMOTime remainingStopDuration() const {
     172            0 :         return 0;
     173              :     }
     174              : 
     175              :     ///@brief ends the current stop and performs loading/unloading
     176              :     void processStop();
     177              : 
     178              :     /** @brief Returns until when to stop at the current segment and sets the information that the stop has been reached
     179              :      * @param[in] time the current time
     180              :      * @return stop time for the segment
     181              :      */
     182              :     SUMOTime checkStop(SUMOTime time);
     183              : 
     184              :     /**
     185              :     * resumes a vehicle from stopping
     186              :     * @return true on success, the resuming fails if the vehicle wasn't parking in the first place
     187              :     */
     188              :     bool resumeFromStopping();
     189              : 
     190              :     /// @brief get distance for coming to a stop (used for rerouting checks)
     191       158623 :     double getBrakeGap(bool delayed = false) const {
     192              :         UNUSED_PARAMETER(delayed);
     193       158623 :         return mySegment == nullptr || myQueIndex == MESegment::PARKING_QUEUE ? 0 : mySegment->getLength();
     194              :     }
     195              : 
     196              :     /** @brief Sets the (planned) time at which the vehicle leaves its current segment
     197              :      * @param[in] t The leaving time
     198              :      */
     199              :     inline void setEventTime(SUMOTime t, bool hasDelay = true) {
     200              :         assert(t > myLastEntryTime);
     201     55118880 :         if (hasDelay && mySegment != nullptr) {
     202              :             mySegment->getEdge().markDelayed();
     203              :         }
     204     43800330 :         myEventTime = t;
     205     11318550 :     }
     206              : 
     207              : 
     208              :     /** @brief Returns the (planned) time at which the vehicle leaves its current segment
     209              :      * @return The time the vehicle thinks it leaves its segment at
     210              :      */
     211              :     inline SUMOTime getEventTime() const {
     212    122796730 :         return myEventTime;
     213              :     }
     214              : 
     215              : 
     216              :     /** @brief Sets the current segment the vehicle is at together with its que
     217              :      * @param[in] s The current segment
     218              :      * @param[in] q The current que
     219              :      */
     220     52778753 :     inline virtual void setSegment(MESegment* s, int idx = 0) {
     221     52778753 :         mySegment = s;
     222     52778753 :         myQueIndex = idx;
     223     52778753 :     }
     224              : 
     225              : 
     226              :     /** @brief Returns the current segment the vehicle is on
     227              :      * @return The segment the vehicle is on
     228              :      */
     229              :     inline MESegment* getSegment() const {
     230     49457289 :         return mySegment;
     231              :     }
     232              : 
     233              :     int getSegmentIndex() const;
     234              : 
     235              :     /** @brief Returns the index of the que the vehicle is in
     236              :      * @return The que index
     237              :      */
     238            0 :     inline int getQueIndex() const {
     239    166895335 :         return myQueIndex;
     240              :     }
     241              : 
     242              :     /** @brief Get the vehicle's lateral position on the edge of the given lane
     243              :      * (or its current edge if lane == 0)
     244              :      * @return The lateral position of the vehicle (in m distance between right
     245              :      * side of vehicle and ride side of edge
     246              :      */
     247              :     double getRightSideOnEdge(const MSLane* /*lane*/) const;
     248              : 
     249              :     /** @brief Sets the entry time for the current segment
     250              :      * @param[in] t The entry time
     251              :      */
     252              :     inline void setLastEntryTime(SUMOTime t) {
     253     26045361 :         myLastEntryTime = t;
     254              :     }
     255              : 
     256              : 
     257              :     /** @brief Returns the time the vehicle entered the current segment
     258              :      * @return The entry time
     259              :      */
     260              :     SUMOTime getLastEntryTime() const {
     261     34195494 :         return myLastEntryTime;
     262              :     }
     263              : 
     264              :     /** @brief Returns the time of the vehicle's last action point.
     265              :      * @return The time of the last action point
     266              :      */
     267         4876 :     SUMOTime getLastActionTime() const {
     268         4876 :         return SIMSTEP;
     269              :     }
     270              : 
     271              :     /** @brief Sets the time at which the vehicle was blocked
     272              :      * @param[in] t The blocking time
     273              :      */
     274              :     inline void setBlockTime(const SUMOTime t) {
     275              :         assert(t > myLastEntryTime);
     276     26395372 :         myBlockTime = t;
     277       350011 :     }
     278              : 
     279              : 
     280              :     /** @brief Returns the time at which the vehicle was blocked
     281              :      * @return The blocking time
     282              :      */
     283              :     inline SUMOTime getBlockTime() const {
     284     13211635 :         return myBlockTime;
     285              :     }
     286              : 
     287              : 
     288              :     /// @brief Returns the duration for which the vehicle was blocked
     289    153744946 :     inline SUMOTime getWaitingTime(const bool accumulated = false) const {
     290              :         UNUSED_PARAMETER(accumulated);
     291    153744946 :         return MAX2(SUMOTime(0), myEventTime - myBlockTime);
     292              :     }
     293              : 
     294         5019 :     inline SUMOTime getTimeLoss() const {
     295              :         // slow-downs while driving are not modelled
     296         5019 :         return getWaitingTime();
     297              :     }
     298              : 
     299              :     /// @brief Returns the earliest leave time for the current segment
     300            0 :     double getEventTimeSeconds() const {
     301       365087 :         return STEPS2TIME(getEventTime());
     302              :     }
     303              : 
     304              :     /// @brief Returns the entry time for the current segment
     305            0 :     double getLastEntryTimeSeconds() const {
     306       359355 :         return STEPS2TIME(getLastEntryTime());
     307              :     }
     308              : 
     309              :     /// @brief Returns the time at which the vehicle was blocked on the current segment
     310            0 :     double getBlockTimeSeconds() const {
     311       353643 :         return STEPS2TIME(getBlockTime());
     312              :     }
     313              : 
     314              :     /// @brief Returns the delay that is accrued due to option --meso-tls-penalty or --meso-minor-penalty
     315              :     double getCurrentLinkPenaltySeconds() const;
     316              : 
     317              :     /// @brief Returns the delay that is accrued due to option --meso-tls-penalty or --meso-minor-penalty
     318              :     double getCurrentStoppingTimeSeconds() const;
     319              : 
     320              :     /// Replaces the current route by the given one
     321              :     bool replaceRoute(ConstMSRoutePtr route,  const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true, std::string* msgReturn = nullptr);
     322              : 
     323              :     /** @brief Returns whether the vehicle is allowed to pass the next junction, checks also for triggered stops
     324              :      * @return true iff the vehicle may drive over the next junction
     325              :      */
     326              :     bool mayProceed();
     327              : 
     328              :     /** @brief Updates a single vehicle detector if present
     329              :      */
     330              :     void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
     331              : 
     332              :     /** @brief Updates all vehicle detectors
     333              :      */
     334              :     void updateDetectors(const SUMOTime currentTime, const SUMOTime exitTime, const bool isLeave,
     335              :                          const MSMoveReminder::Notification reason = MSMoveReminder::NOTIFICATION_JUNCTION);
     336              : 
     337              :     /** @brief Returns the velocity/lane influencer
     338              :      *
     339              :      * If no influencer was existing before, one is built, first
     340              :      * @return Reference to this vehicle's speed influencer
     341              :      */
     342              :     BaseInfluencer& getBaseInfluencer();
     343              : 
     344              :     const BaseInfluencer* getBaseInfluencer() const;
     345              : 
     346      9173239 :     bool hasInfluencer() const {
     347      9173239 :         return myInfluencer != nullptr;
     348              :     }
     349              : 
     350              :     /// @name state io
     351              :     //@{
     352              : 
     353              :     /// Saves the states of a vehicle
     354              :     void saveState(OutputDevice& out);
     355              : 
     356              :     /** @brief Loads the state of this vehicle from the given description
     357              :      */
     358              :     void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
     359              :     //@}
     360              : 
     361              : 
     362              : protected:
     363              :     /// @brief The segment the vehicle is at
     364              :     MESegment* mySegment;
     365              : 
     366              :     /// @brief Index of the que the vehicle is in (important for multiqueue extension)
     367              :     int myQueIndex;
     368              : 
     369              :     /// @brief The (planned) time of leaving the segment (cell)
     370              :     SUMOTime myEventTime;
     371              : 
     372              :     /// @brief The time the vehicle entered its current segment
     373              :     SUMOTime myLastEntryTime;
     374              : 
     375              :     /// @brief The time at which the vehicle was blocked on its current segment
     376              :     SUMOTime myBlockTime;
     377              : 
     378              :     /// @brief An instance of a velocity/lane influencing instance; built in "getInfluencer"
     379              :     BaseInfluencer* myInfluencer;
     380              : 
     381              : };
        

Generated by: LCOV version 2.0-1