LCOV - code coverage report
Current view: top level - src/mesosim - MEVehicle.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 29 35 82.9 %
Date: 2024-04-27 15:34:54 Functions: 6 11 54.5 %

          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    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      274956 : 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 lane the vehicle is on
      79             :     * @return The vehicle's current lane
      80             :     */
      81    11386480 :     const MSLane* getLane() const {
      82    11386480 :         return nullptr;
      83             :     }
      84             : 
      85             :     /** @brief Return current position (x/y, cartesian)
      86             :      *
      87             :      * If the vehicle's myLane is 0, Position::INVALID.
      88             :      * @param[in] offset optional offset in longitudinal direction
      89             :      * @return The current position (in cartesian coordinates)
      90             :      * @see myLane
      91             :      */
      92             :     Position getPosition(const double offset = 0) const;
      93             : 
      94             : 
      95             :     /** @brief Returns the vehicle's estimated speed assuming no delays
      96             :      * @return The vehicle's estimated speed
      97             :      * @note This is only an upper bound. The speed will be lower if the preceeding vehicle is delayed
      98             :      */
      99             :     double getSpeed() const;
     100             : 
     101             :     /** @brief Returns the vehicle's estimated average speed on the segment assuming no further delays
     102             :      * @return The vehicle's estimated average speed
     103             :      * @note This is only an upper bound. The speed will be lower if the preceeding vehicle is delayed
     104             :      */
     105             :     double getAverageSpeed() const;
     106             : 
     107             :     /// @brief Returns the vehicle's estimated speed after driving accross the link
     108             :     double estimateLeaveSpeed(const MSLink* link) const;
     109             : 
     110             : 
     111             :     /** @brief Returns the vehicle's estimated speed taking into account delays
     112             :      * @return The vehicle's estimated speed
     113             :      * @param[in, out] earliestArrival A lower bound on leaveTime, modified to contain new lower bound on leave Time
     114             :      * @note This is only an upper bound. The speed may be even lower if there are further delays downstream
     115             :      */
     116             :     double getConservativeSpeed(SUMOTime& earliestArrival) const;
     117             : 
     118             :     /// @name insertion/removal
     119             :     //@{
     120             : 
     121             :     /** @brief Called when the vehicle is removed from the network.
     122             :      *
     123             :      * Moves along work reminders and
     124             :      *  informs all devices about quitting. Calls "leaveLane" then.
     125             :      *
     126             :      * @param[in] reason why the vehicle leaves (reached its destination, parking, teleport)
     127             :      */
     128             :     void onRemovalFromNet(const MSMoveReminder::Notification reason);
     129             :     //@}
     130             : 
     131             : 
     132             :     /** @brief Update when the vehicle enters a new edge in the move step.
     133             :      * @return Whether the vehicle's route has ended (due to vaporization, or because the destination was reached)
     134             :      */
     135             :     bool moveRoutePointer();
     136             : 
     137             :     /** @brief Returns whether this vehicle has already arived
     138             :      * (reached the arrivalPosition on its final edge)
     139             :      */
     140             :     bool hasArrived() const;
     141             : 
     142             :     /** @brief Returns the information whether the vehicle is on a road (is simulated)
     143             :      * @return Whether the vehicle is simulated
     144             :      */
     145             :     bool isOnRoad() const;
     146             : 
     147             :     /** @brief Returns whether the vehicle is trying to re-enter the net
     148             :      * @return true if the vehicle is trying to enter the net (eg after parking)
     149             :      */
     150             :     virtual bool isIdling() const;
     151             : 
     152             : 
     153             :     /** @brief registers vehicle with the given link
     154             :      *
     155             :      * @param[in] link the link on which the car shall register its approach
     156             :      */
     157             :     void setApproaching(MSLink* link);
     158             : 
     159             :     /// @brief Returns the remaining stop duration for a stopped vehicle or 0
     160           0 :     SUMOTime remainingStopDuration() const {
     161           0 :         return 0;
     162             :     }
     163             : 
     164             :     ///@brief ends the current stop and performs loading/unloading
     165             :     void processStop();
     166             : 
     167             :     /** @brief Returns until when to stop at the current segment and sets the information that the stop has been reached
     168             :      * @param[in] time the current time
     169             :      * @return stop time for the segment
     170             :      */
     171             :     SUMOTime checkStop(SUMOTime time);
     172             : 
     173             :     /**
     174             :     * resumes a vehicle from stopping
     175             :     * @return true on success, the resuming fails if the vehicle wasn't parking in the first place
     176             :     */
     177             :     bool resumeFromStopping();
     178             : 
     179             :     /// @brief get distance for coming to a stop (used for rerouting checks)
     180      147061 :     double getBrakeGap(bool delayed = false) const {
     181             :         UNUSED_PARAMETER(delayed);
     182      147061 :         return mySegment == nullptr || myQueIndex == MESegment::PARKING_QUEUE ? 0 : mySegment->getLength();
     183             :     }
     184             : 
     185             :     /** @brief Sets the (planned) time at which the vehicle leaves its current segment
     186             :      * @param[in] t The leaving time
     187             :      */
     188             :     inline void setEventTime(SUMOTime t, bool hasDelay = true) {
     189             :         assert(t > myLastEntryTime);
     190    42784634 :         if (hasDelay && mySegment != nullptr) {
     191             :             mySegment->getEdge().markDelayed();
     192             :         }
     193    55894062 :         myEventTime = t;
     194     8973862 :     }
     195             : 
     196             : 
     197             :     /** @brief Returns the (planned) time at which the vehicle leaves its current segment
     198             :      * @return The time the vehicle thinks it leaves its segment at
     199             :      */
     200             :     inline SUMOTime getEventTime() const {
     201   147209322 :         return myEventTime;
     202             :     }
     203             : 
     204             : 
     205             :     /** @brief Sets the current segment the vehicle is at together with its que
     206             :      * @param[in] s The current segment
     207             :      * @param[in] q The current que
     208             :      */
     209    68352220 :     inline virtual void setSegment(MESegment* s, int idx = 0) {
     210    68352220 :         mySegment = s;
     211    68352220 :         myQueIndex = idx;
     212    68352220 :     }
     213             : 
     214             : 
     215             :     /** @brief Returns the current segment the vehicle is on
     216             :      * @return The segment the vehicle is on
     217             :      */
     218             :     inline MESegment* getSegment() const {
     219    52332049 :         return mySegment;
     220             :     }
     221             : 
     222             : 
     223             :     /** @brief Returns the index of the que the vehicle is in
     224             :      * @return The que index
     225             :      */
     226           0 :     inline int getQueIndex() const {
     227   198532332 :         return myQueIndex;
     228             :     }
     229             : 
     230             :     /** @brief Get the vehicle's lateral position on the edge of the given lane
     231             :      * (or its current edge if lane == 0)
     232             :      * @return The lateral position of the vehicle (in m distance between right
     233             :      * side of vehicle and ride side of edge
     234             :      */
     235             :     double getRightSideOnEdge(const MSLane* /*lane*/) const;
     236             : 
     237             :     /** @brief Sets the entry time for the current segment
     238             :      * @param[in] t The entry time
     239             :      */
     240             :     inline void setLastEntryTime(SUMOTime t) {
     241    33794101 :         myLastEntryTime = t;
     242             :     }
     243             : 
     244             : 
     245             :     /** @brief Returns the time the vehicle entered the current segment
     246             :      * @return The entry time
     247             :      */
     248             :     SUMOTime getLastEntryTime() const {
     249    41874073 :         return myLastEntryTime;
     250             :     }
     251             : 
     252             : 
     253             :     /** @brief Sets the time at which the vehicle was blocked
     254             :      * @param[in] t The blocking time
     255             :      */
     256             :     inline void setBlockTime(const SUMOTime t) {
     257             :         assert(t > myLastEntryTime);
     258    34053696 :         myBlockTime = t;
     259      259595 :     }
     260             : 
     261             : 
     262             :     /** @brief Returns the time at which the vehicle was blocked
     263             :      * @return The blocking time
     264             :      */
     265             :     inline SUMOTime getBlockTime() const {
     266    10567862 :         return myBlockTime;
     267             :     }
     268             : 
     269             : 
     270             :     /// @brief Returns the duration for which the vehicle was blocked
     271   123376325 :     inline SUMOTime getWaitingTime(const bool accumulated = false) const {
     272             :         UNUSED_PARAMETER(accumulated);
     273   123376325 :         return MAX2(SUMOTime(0), myEventTime - myBlockTime);
     274             :     }
     275             : 
     276        3678 :     inline SUMOTime getTimeLoss() const {
     277             :         // slow-downs while driving are not modelled
     278        3678 :         return getWaitingTime();
     279             :     }
     280             : 
     281             :     /// @brief Returns the earliest leave time for the current segment
     282           0 :     double getEventTimeSeconds() const {
     283      646503 :         return STEPS2TIME(getEventTime());
     284             :     }
     285             : 
     286             :     /// @brief Returns the entry time for the current segment
     287           0 :     double getLastEntryTimeSeconds() const {
     288      646503 :         return STEPS2TIME(getLastEntryTime());
     289             :     }
     290             : 
     291             :     /// @brief Returns the time at which the vehicle was blocked on the current segment
     292           0 :     double getBlockTimeSeconds() const {
     293      646503 :         return STEPS2TIME(getBlockTime());
     294             :     }
     295             : 
     296             :     /// @brief Returns the delay that is accrued due to option --meso-tls-penalty or --meso-minor-penalty
     297             :     double getCurrentLinkPenaltySeconds() const;
     298             : 
     299             :     /// @brief Returns the delay that is accrued due to option --meso-tls-penalty or --meso-minor-penalty
     300             :     double getCurrentStoppingTimeSeconds() const;
     301             : 
     302             :     /// Replaces the current route by the given one
     303             :     bool replaceRoute(ConstMSRoutePtr route,  const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true, std::string* msgReturn = nullptr);
     304             : 
     305             :     /** @brief Returns whether the vehicle is allowed to pass the next junction, checks also for triggered stops
     306             :      * @return true iff the vehicle may drive over the next junction
     307             :      */
     308             :     bool mayProceed();
     309             : 
     310             :     /** @brief Updates a single vehicle detector if present
     311             :      */
     312             :     void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
     313             : 
     314             :     /** @brief Updates all vehicle detectors
     315             :      */
     316             :     void updateDetectors(SUMOTime currentTime, const bool isLeave,
     317             :                          const MSMoveReminder::Notification reason = MSMoveReminder::NOTIFICATION_JUNCTION);
     318             : 
     319             :     /** @brief Returns the velocity/lane influencer
     320             :      *
     321             :      * If no influencer was existing before, one is built, first
     322             :      * @return Reference to this vehicle's speed influencer
     323             :      */
     324             :     BaseInfluencer& getBaseInfluencer();
     325             : 
     326             :     const BaseInfluencer* getBaseInfluencer() const;
     327             : 
     328     7719889 :     bool hasInfluencer() const {
     329     7719889 :         return myInfluencer != nullptr;
     330             :     }
     331             : 
     332             :     /// @name state io
     333             :     //@{
     334             : 
     335             :     /// Saves the states of a vehicle
     336             :     void saveState(OutputDevice& out);
     337             : 
     338             :     /** @brief Loads the state of this vehicle from the given description
     339             :      */
     340             :     void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
     341             :     //@}
     342             : 
     343             : 
     344             : protected:
     345             :     /// @brief The segment the vehicle is at
     346             :     MESegment* mySegment;
     347             : 
     348             :     /// @brief Index of the que the vehicle is in (important for multiqueue extension)
     349             :     int myQueIndex;
     350             : 
     351             :     /// @brief The (planned) time of leaving the segment (cell)
     352             :     SUMOTime myEventTime;
     353             : 
     354             :     /// @brief The time the vehicle entered its current segment
     355             :     SUMOTime myLastEntryTime;
     356             : 
     357             :     /// @brief The time at which the vehicle was blocked on its current segment
     358             :     SUMOTime myBlockTime;
     359             : 
     360             :     /// @brief An instance of a velocity/lane influencing instance; built in "getInfluencer"
     361             :     BaseInfluencer* myInfluencer;
     362             : 
     363             : };

Generated by: LCOV version 1.14