LCOV - code coverage report
Current view: top level - src/microsim - MSMoveReminder.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 20 20
Test Date: 2024-10-24 15:46:30 Functions: 90.9 % 11 10

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2003-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    MSMoveReminder.h
      15              : /// @author  Christian Roessel
      16              : /// @author  Daniel Krajzewicz
      17              : /// @author  Sascha Krieg
      18              : /// @author  Michael Behrisch
      19              : /// @author  Jakob Erdmann
      20              : /// @date    2003-05-21
      21              : ///
      22              : // Something on a lane to be noticed about vehicle movement
      23              : /****************************************************************************/
      24              : #pragma once
      25              : #include <config.h>
      26              : 
      27              : #include <iostream>
      28              : #include <map>
      29              : #include <utils/common/SUMOTime.h>
      30              : #include <utils/common/StdDefs.h>
      31              : #ifdef HAVE_FOX
      32              : #include <utils/foxtools/fxheader.h>
      33              : #endif
      34              : 
      35              : 
      36              : // ===========================================================================
      37              : // class declarations
      38              : // ===========================================================================
      39              : class SUMOTrafficObject;
      40              : class MSLane;
      41              : 
      42              : 
      43              : // ===========================================================================
      44              : // class definitions
      45              : // ===========================================================================
      46              : /**
      47              :  * @class MSMoveReminder
      48              :  * @brief Something on a lane to be noticed about vehicle movement
      49              :  *
      50              :  * Base class of all move-reminders. During move, the vehicles call
      51              :  *  notifyMove() for all reminders on their current lane (all lanes
      52              :  *  they pass during one step). If a vehicle enters the lane the reminder is
      53              :  *  positioned at during insertion or lanechange notifyEnter() is
      54              :  *  called. If a vehicle leaves the reminder lane it calls notifyLeave().
      55              :  *
      56              :  * The reminder knows whom to tell about move, insertion and lanechange. The
      57              :  * vehicles will remove the reminder that is not notifyMove() from
      58              :  * their reminder container.
      59              :  *
      60              :  * @see MSLane::addMoveReminder
      61              :  * @see MSLane::getMoveReminder
      62              :  * @note: cannot inherit from Named because it would couse double inheritance
      63              :  */
      64              : class MSMoveReminder {
      65              : public:
      66              :     /** @brief Constructor.
      67              :      *
      68              :      * @param[in] lane Lane on which the reminder will work.
      69              :      * @param[in] doAdd whether to add the reminder to the lane
      70              :      */
      71              :     MSMoveReminder(const std::string& description, MSLane* const lane = nullptr, const bool doAdd = true);
      72              : 
      73              : 
      74              :     /** @brief Destructor
      75              :      */
      76     13117538 :     virtual ~MSMoveReminder() {}
      77              : 
      78              : 
      79              :     /** @brief Returns the lane the reminder works on.
      80              :      *
      81              :      * @return The lane the reminder is anchored on.
      82              :      */
      83              :     const MSLane* getLane() const {
      84    102205533 :         return myLane;
      85              :     }
      86              : 
      87              : 
      88              :     /// @brief Definition of a vehicle state
      89              :     enum Notification {
      90              :         /// @brief The vehicle has departed (was inserted into the network)
      91              :         NOTIFICATION_DEPARTED,
      92              :         /// @brief The vehicle arrived at a junction
      93              :         NOTIFICATION_JUNCTION,
      94              :         /// @brief The vehicle changes the segment (meso only)
      95              :         NOTIFICATION_SEGMENT,
      96              :         /// @brief The vehicle changes lanes (micro only)
      97              :         NOTIFICATION_LANE_CHANGE,
      98              :         /// @brief The vehicle has been loaded from a state file
      99              :         NOTIFICATION_LOAD_STATE,
     100              :         /* All notifications below must result in the vehicle not being on the net
     101              :          * (onLeaveLane sets amOnNet=false if reason>=NOTIFICATION_TELEPORT) */
     102              :         /// @brief The vehicle is being teleported
     103              :         NOTIFICATION_TELEPORT,
     104              :         /// @brief The vehicle continues being teleported past an edge
     105              :         NOTIFICATION_TELEPORT_CONTINUATION,
     106              :         /// @brief The vehicle starts or ends parking
     107              :         NOTIFICATION_PARKING,
     108              :         /// @brief The vehicle needs another parking area
     109              :         NOTIFICATION_PARKING_REROUTE,
     110              :         /// @brief The vehicle arrived at its destination (is deleted)
     111              :         NOTIFICATION_ARRIVED, // arrived and everything after is treated as permanent deletion from the net
     112              :         /// @brief The vehicle was teleported out of the net
     113              :         NOTIFICATION_TELEPORT_ARRIVED,
     114              :         /// @brief The vehicle got removed by a calibrator
     115              :         NOTIFICATION_VAPORIZED_CALIBRATOR,
     116              :         /// @brief The vehicle got removed by a collision
     117              :         NOTIFICATION_VAPORIZED_COLLISION,
     118              :         /// @brief The vehicle got removed via TraCI
     119              :         NOTIFICATION_VAPORIZED_TRACI,
     120              :         /// @brief The vehicle got removed via the GUI
     121              :         NOTIFICATION_VAPORIZED_GUI,
     122              :         /// @brief The vehicle got vaporized with a vaporizer
     123              :         NOTIFICATION_VAPORIZED_VAPORIZER,
     124              :         /// @brief The vehicle got removed via stationfinder device
     125              :         NOTIFICATION_VAPORIZED_BREAKDOWN
     126              :     };
     127              : 
     128              : 
     129              :     /// @name Interface methods, to be derived by subclasses
     130              :     /// @{
     131              : 
     132              :     /** @brief Checks whether the reminder is activated by a vehicle entering the lane
     133              :      *
     134              :      * Lane change means in this case that the vehicle changes to the lane
     135              :      *  the reminder is placed at.
     136              :      *
     137              :      * @param[in] veh The entering vehicle.
     138              :      * @param[in] reason how the vehicle enters the lane
     139              :      * @return True if vehicle enters the reminder.
     140              :      * @see Notification
     141              :      */
     142       506419 :     virtual bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane) {
     143              :         UNUSED_PARAMETER(reason);
     144              :         UNUSED_PARAMETER(&veh);
     145              :         UNUSED_PARAMETER(&enteredLane);
     146       506419 :         return true;
     147              :     }
     148              : 
     149              : 
     150              :     /** @brief Checks whether the reminder still has to be notified about the vehicle moves
     151              :      *
     152              :      * Indicator if the reminders is still active for the passed
     153              :      * vehicle/parameters. If false, the vehicle will erase this reminder
     154              :      * from its reminder-container.
     155              :      *
     156              :      * @param[in] veh Vehicle that asks this reminder.
     157              :      * @param[in] oldPos Position before move.
     158              :      * @param[in] newPos Position after move with newSpeed.
     159              :      * @param[in] newSpeed Moving speed.
     160              :      *
     161              :      * @return True if vehicle hasn't passed the reminder completely.
     162              :      */
     163    126266335 :     virtual bool notifyMove(SUMOTrafficObject& veh,
     164              :                             double oldPos,
     165              :                             double newPos,
     166              :                             double newSpeed) {
     167              :         UNUSED_PARAMETER(oldPos);
     168              :         UNUSED_PARAMETER(newPos);
     169              :         UNUSED_PARAMETER(newSpeed);
     170              :         UNUSED_PARAMETER(&veh);
     171    126266335 :         return true;
     172              :     }
     173              : 
     174              :     /** @brief Computes idling emission values and adds them to the emission sums
     175              :     *
     176              :     * Idling implied by zero velocity, acceleration and slope
     177              :     *
     178              :     * @param[in] veh The vehicle
     179              :     *
     180              :     * @see MSMoveReminder::notifyMove
     181              :     * @see PollutantsInterface
     182              :     */
     183       123130 :     virtual bool notifyIdle(SUMOTrafficObject& veh) {
     184              :         UNUSED_PARAMETER(&veh);
     185       123130 :         return true;
     186              :     }
     187              : 
     188              :     /// @brief called to update state for parking vehicles
     189      6759241 :     virtual void notifyParking() {}
     190              : 
     191              :     /// @brief called to update state for stopped vehicles
     192        30528 :     virtual void notifyStopEnded() {}
     193              : 
     194              :     /** @brief Called if the vehicle leaves the reminder's lane
     195              :      *
     196              :      * Informs if vehicle leaves reminder lane (due to lane change, removal
     197              :      *  from the network, or leaving to the next lane).
     198              :      *  The default is to do nothing.
     199              :      *
     200              :      * @param[in] veh The leaving vehicle.
     201              :      * @param[in] lastPos Position on the lane when leaving.
     202              :      * @param[in] reason how the vehicle leaves the lane
     203              :      * @see Notification
     204              :      *
     205              :      * @return True if the reminder wants to receive further info.
     206              :      */
     207       569615 :     virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = nullptr) {
     208              :         UNUSED_PARAMETER(&veh);
     209              :         UNUSED_PARAMETER(lastPos);
     210              :         UNUSED_PARAMETER(reason);
     211              :         UNUSED_PARAMETER(enteredLane);
     212       569615 :         return true;
     213              :     }
     214              : 
     215              :     /** @brief Called if the vehicle's back leaves the reminder's lane
     216              :      *
     217              :      * Informs if vehicle back leaves reminder lane (due to lane change, removal
     218              :      *  from the network, or leaving to the next lane).
     219              :      *  The default is to do nothing.
     220              :      *
     221              :      * @param[in] veh The leaving vehicle.
     222              :      * @param[in] reason how the vehicle leaves the lane
     223              :      * @param[in] leftLane The lane that the vehicle's back left
     224              :      * @see Notification
     225              :      *
     226              :      * @return True if the reminder wants to receive further info.
     227              :      */
     228        44671 :     virtual bool notifyLeaveBack(SUMOTrafficObject& veh, Notification reason, const MSLane* leftLane) {
     229              :         UNUSED_PARAMETER(&veh);
     230              :         UNUSED_PARAMETER(reason);
     231              :         UNUSED_PARAMETER(leftLane);
     232        44671 :         return true;
     233              :     }
     234              : 
     235              :     // TODO: Documentation
     236              :     void updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
     237              :                         SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
     238              :                         bool cleanUp);
     239              : 
     240              :     /// @}
     241              : 
     242              :     /** @brief Internal notification about the vehicle moves.
     243              :      *  @note meso uses this though it never calls notifyMove()
     244              :      *
     245              :      * Indicator if the reminders is still active for the passed
     246              :      * vehicle/parameters. If false, the vehicle will erase this reminder
     247              :      * from its reminder-container.
     248              :      *
     249              :      * @param[in] veh Vehicle that asks this reminder.
     250              :      * @param[in] frontOnLane time the front of the vehicle spent on the lane.
     251              :      * @param[in] timeOnLane time some part of the vehicle spent on the lane.
     252              :      * @param[in] meanSpeedFrontOnLane Average speed for the time that the front is on the lane.
     253              :      * @param[in] meanSpeedVehicleOnLane Average speed for the time that the vehicle is on the lane (with front or back).
     254              :      * @param[in] travelledDistanceFrontOnLane distance travelled while overlapping with the lane.
     255              :      * @param[in] travelledDistanceVehicleOnLane distance travelled while front was on the lane.
     256              :      * @param[in] meanLengthOnLane the average length of the vehicle's part on the lane during the last step (==complete length in meso case)
     257              :      */
     258      7663641 :     virtual void notifyMoveInternal(const SUMOTrafficObject& veh,
     259              :                                     const double frontOnLane,
     260              :                                     const double timeOnLane,
     261              :                                     const double meanSpeedFrontOnLane,
     262              :                                     const double meanSpeedVehicleOnLane,
     263              :                                     const double travelledDistanceFrontOnLane,
     264              :                                     const double travelledDistanceVehicleOnLane,
     265              :                                     const double meanLengthOnLane) {
     266              :         UNUSED_PARAMETER(&veh);
     267              :         UNUSED_PARAMETER(frontOnLane);
     268              :         UNUSED_PARAMETER(timeOnLane);
     269              :         UNUSED_PARAMETER(meanSpeedFrontOnLane);
     270              :         UNUSED_PARAMETER(meanSpeedVehicleOnLane);
     271              :         UNUSED_PARAMETER(travelledDistanceFrontOnLane);
     272              :         UNUSED_PARAMETER(travelledDistanceVehicleOnLane);
     273              :         UNUSED_PARAMETER(meanLengthOnLane);
     274      7663641 :     }
     275              : 
     276              :     void setDescription(const std::string& description) {
     277        30602 :         myDescription = description;
     278        30602 :     }
     279              : 
     280              :     const std::string& getDescription() const {
     281              :         return myDescription;
     282              :     }
     283              : 
     284              :     // @brief return whether this moveReminder triggers parking reroute
     285          120 :     virtual bool isParkingRerouter() const {
     286          120 :         return false;
     287              :     }
     288              : 
     289              : protected:
     290              :     void removeFromVehicleUpdateValues(SUMOTrafficObject& veh);
     291              : 
     292              : protected:
     293              : 
     294              :     /// @brief Lane on which the reminder works
     295              :     MSLane* myLane;
     296              :     /// @brief a description of this moveReminder
     297              :     std::string myDescription;
     298              : 
     299              : #ifdef HAVE_FOX
     300              :     /// @brief the mutex for notifications
     301              :     mutable FXMutex myNotificationMutex;
     302              : #endif
     303              : 
     304              : private:
     305              :     std::map<long long int, std::pair<SUMOTime, double> > myLastVehicleUpdateValues;
     306              : 
     307              : 
     308              : private:
     309              :     MSMoveReminder& operator=(const MSMoveReminder&); // just to avoid a compiler warning
     310              : 
     311              : };
        

Generated by: LCOV version 2.0-1