LCOV - code coverage report
Current view: top level - src/microsim/trigger - MSTriggeredRerouter.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 3 3 100.0 %
Date: 2024-05-06 15:32:35 Functions: 1 1 100.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    MSTriggeredRerouter.h
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Michael Behrisch
      18             : /// @author  Mirco Sturari
      19             : /// @date    Mon, 25 July 2005
      20             : ///
      21             : // Reroutes vehicles passing an edge
      22             : /****************************************************************************/
      23             : #pragma once
      24             : #include <config.h>
      25             : 
      26             : #include <string>
      27             : #include <vector>
      28             : #include <utils/common/Command.h>
      29             : #include <utils/common/Named.h>
      30             : #include <utils/xml/SUMOSAXHandler.h>
      31             : #include <utils/distribution/RandomDistributor.h>
      32             : #include <microsim/MSMoveReminder.h>
      33             : 
      34             : 
      35             : // ===========================================================================
      36             : // class declarations
      37             : // ===========================================================================
      38             : class MSNet;
      39             : class MSLane;
      40             : class MSRoute;
      41             : class SUMOVehicle;
      42             : class MSParkingArea;
      43             : 
      44             : 
      45             : // ===========================================================================
      46             : // class definitions
      47             : // ===========================================================================
      48             : /**
      49             :  * @class MSTriggeredRerouter
      50             :  * @brief Reroutes traffic objects passing an edge
      51             :  *
      52             :  * A rerouter can be positioned on a list of edges and gives traffic objects which
      53             :  *  enters one of these edges a new route.
      54             :  *
      55             :  * The new route may be either chosen from a set of routes where each is
      56             :  *  chosen with a certain probability, or newly computed, either by keeping
      57             :  *  the old destination or by choosing a new one from a set of existing ones.
      58             :  */
      59             : class MSTriggeredRerouter :
      60             :     public Named, public MSMoveReminder,
      61             :     public SUMOSAXHandler {
      62             : 
      63             :     friend class GUIEdge; // dynamic instantiation
      64             : 
      65             : public:
      66             :     /** @brief Constructor
      67             :      *
      68             :      * @param[in] id The id of the rerouter
      69             :      * @param[in] edges The edges the rerouter is placed at
      70             :      * @param[in] prob The probability the rerouter reoutes vehicles with
      71             :      */
      72             :     MSTriggeredRerouter(const std::string& id, const MSEdgeVector& edges,
      73             :                         double prob, bool off, bool optional, SUMOTime timeThreshold,
      74             :                         const std::string& vTypes, const Position& pos);
      75             : 
      76             : 
      77             :     /** @brief Destructor */
      78             :     virtual ~MSTriggeredRerouter();
      79             : 
      80             :     typedef std::pair<MSParkingArea*, bool> ParkingAreaVisible;
      81             : 
      82             :     /**
      83             :      * @struct RerouteInterval
      84             :      * Describes the rerouting definitions valid for an interval
      85             :      */
      86        3349 :     struct RerouteInterval {
      87             :         /// unique ID for this interval
      88             :         long long int id;
      89             :         /// The begin time these definitions are valid
      90             :         SUMOTime begin;
      91             :         /// The end time these definitions are valid
      92             :         SUMOTime end;
      93             :         /// The list of closed edges
      94             :         MSEdgeVector closed;
      95             :         /// The list of closed lanes
      96             :         std::vector<MSLane*> closedLanes;
      97             :         /// The list of edges that are affect by closed lanes
      98             :         MSEdgeVector closedLanesAffected;
      99             :         /// The distributions of new destinations or vias to use
     100             :         RandomDistributor<MSEdge*> edgeProbs;
     101             :         /// The distributions of new routes to use
     102             :         RandomDistributor<ConstMSRoutePtr> routeProbs;
     103             :         /// The permissions to use
     104             :         SVCPermissions permissions;
     105             :         /// The distributions of new parking areas to use as destinations
     106             :         RandomDistributor<ParkingAreaVisible> parkProbs;
     107             :         /// The edge probs are vias and not destinations
     108             :         bool isVia = false;
     109             :     };
     110             : 
     111             :     /** @brief Tries to reroute the vehicle
     112             :      *
     113             :      * It will not try to reroute if it is a
     114             :      * lane change because there should be another rerouter on the lane
     115             :      * the vehicle is coming from.
     116             :      * Returns false - the vehicle will not be rerouted again.
     117             :      *
     118             :      * @param[in] veh The entering vehicle.
     119             :      * @param[in] reason how the vehicle enters the lane
     120             :      * @return always false (the vehicle will not be rerouted again)
     121             :      * @see MSMoveReminder
     122             :      * @see MSMoveReminder::notifyEnter
     123             :      * @see MSMoveReminder::Notification
     124             :      */
     125             :     bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
     126             : 
     127             :     /// @name Methods called on vehicle movement / state change, overwriting MSDevice
     128             :     /// @{
     129             : 
     130             :     /** @brief Triggers rerouting (once) for vehicles that are already on the edge when the rerouter activates
     131             :      *
     132             :      * @param[in] veh Vehicle that asks this reminder.
     133             :      * @param[in] oldPos Position before move.
     134             :      * @param[in] newPos Position after move with newSpeed.
     135             :      * @param[in] newSpeed Moving speed.
     136             :      * @return True (always).
     137             :      */
     138             :     bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
     139             : 
     140             :     /** @brief Removes the reminder
     141             :      *
     142             :      * @param[in] veh The leaving vehicle.
     143             :      * @param[in] lastPos Position on the lane when leaving.
     144             :      * @param[in] isArrival whether the vehicle arrived at its destination
     145             :      * @param[in] isLaneChange whether the vehicle changed from the lane
     146             :      * @return false if the vehicle left th edge
     147             :      */
     148             :     bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
     149             : 
     150             :     bool triggerRouting(SUMOTrafficObject& veh, MSMoveReminder::Notification reason);
     151             : 
     152             :     /// Returns the rerouting definition valid for the given time and object, nullptr if none
     153             :     const RerouteInterval* getCurrentReroute(SUMOTime time, SUMOTrafficObject& obj) const;
     154             : 
     155             :     /// Sets the edge permission if there are any defined in the closingEdge
     156             :     SUMOTime setPermissions(const SUMOTime currentTime);
     157             : 
     158             :     /// Returns the rerouting definition valid for the given time, 0 if none
     159             :     const RerouteInterval* getCurrentReroute(SUMOTime time) const;
     160             : 
     161             :     /// Sets whether the process is currently steered by the user
     162             :     void setUserMode(bool val);
     163             : 
     164             :     /// Sets the probability with which a vehicle is rerouted given by the user
     165             :     void setUserUsageProbability(double prob);
     166             : 
     167             :     /// Returns whether the user is setting the rerouting probability
     168             :     bool inUserMode() const;
     169             : 
     170             :     /// Returns the rerouting probability
     171             :     double getProbability() const;
     172             : 
     173             :     /// Returns the rerouting probability given by the user
     174             :     double getUserProbability() const;
     175             : 
     176             :     // @brief return whether this moveReminder triggers parking reroute
     177        2519 :     bool isParkingRerouter() const {
     178        2519 :         return myHaveParkProbs;
     179             :     }
     180             : 
     181             :     const Position& getPosition() {
     182             :         return myPosition;
     183             :     }
     184             : 
     185             :     static double getWeight(SUMOVehicle& veh, const std::string param, const double defaultWeight);
     186             : 
     187             :     static MSParkingArea* rerouteParkingArea(const MSTriggeredRerouter::RerouteInterval* rerouteDef,
     188             :             SUMOVehicle& veh, bool& newDestination, ConstMSEdgeVector& newRoute);
     189             : 
     190             :     /// @brief return all rerouter instances
     191             :     static const std::map<std::string, MSTriggeredRerouter*>& getInstances() {
     192             :         return myInstances;
     193             :     }
     194             : 
     195             :     /// @brief issues warning for incomplete parkingReroute relationships
     196             :     static void checkParkingRerouteConsistency();
     197             : 
     198             : protected:
     199             :     /// @name inherited from GenericSAXHandler
     200             :     //@{
     201             : 
     202             :     /** @brief Called on the opening of a tag;
     203             :      *
     204             :      * @param[in] element ID of the currently opened element
     205             :      * @param[in] attrs Attributes within the currently opened element
     206             :      * @exception ProcessError If something fails
     207             :      * @see GenericSAXHandler::myStartElement
     208             :      */
     209             :     virtual void myStartElement(int element,
     210             :                                 const SUMOSAXAttributes& attrs);
     211             : 
     212             : 
     213             :     /** @brief Called when a closing tag occurs
     214             :      *
     215             :      * @param[in] element ID of the currently opened element
     216             :      * @exception ProcessError If something fails
     217             :      * @see GenericSAXHandler::myEndElement
     218             :      */
     219             :     virtual void myEndElement(int element);
     220             :     //@}
     221             : 
     222             :     /** @brief Checks whether the detector measures objects of the given type.
     223             :     *
     224             :     * @param[in] obj the traffic object of which the type is checked.
     225             :     * @return whether it should be measured
     226             :     */
     227             :     bool applies(const SUMOTrafficObject& obj) const;
     228             : 
     229             :     static bool affected(const std::set<SUMOTrafficObject::NumericalID>& edgeIndices, const MSEdgeVector& closed);
     230             : 
     231             :     typedef std::map<std::string, double> ParkingParamMap_t;
     232             :     typedef std::map<MSParkingArea*, ParkingParamMap_t, ComparatorIdLess> MSParkingAreaMap_t;
     233             : 
     234             :     /// determine attributes of candiate parking area for scoring
     235             :     static bool addParkValues(SUMOVehicle& veh, double brakeGap, bool newDestination,
     236             :                               MSParkingArea* pa, double paOccupancy, double prob,
     237             :                               SUMOAbstractRouter<MSEdge, SUMOVehicle>& router,
     238             :                               MSParkingAreaMap_t& parkAreas,
     239             :                               std::map<MSParkingArea*, ConstMSEdgeVector>& newRoutes,
     240             :                               std::map<MSParkingArea*, ConstMSEdgeVector>& parkApproaches,
     241             :                               ParkingParamMap_t& maxValues);
     242             : 
     243             : protected:
     244             :     /// @brief edges where vehicles are notified
     245             :     const MSEdgeVector myEdges;
     246             : 
     247             :     /// List of rerouting definition intervals
     248             :     std::vector<RerouteInterval> myIntervals;
     249             : 
     250             :     /// The probability and the user-given probability
     251             :     double myProbability, myUserProbability;
     252             : 
     253             :     /// Information whether the current rerouting probability is the user-given
     254             :     bool myAmInUserMode;
     255             : 
     256             :     /// Information whether the rerouting will only take place on request
     257             :     bool myAmOptional;
     258             : 
     259             :     /// Where are we located in the network
     260             :     Position myPosition;
     261             : 
     262             :     // @brief waiting time threshold for activation
     263             :     SUMOTime myTimeThreshold;
     264             : 
     265             :     /// @brief The vehicle types to look for (empty means all)
     266             :     std::set<std::string> myVehicleTypes;
     267             : 
     268             :     /// used during loading
     269             :     RerouteInterval myParsedRerouteInterval;
     270             : 
     271             :     /// whether this rerouter has loaded parkingReroute definitions
     272             :     bool myHaveParkProbs;
     273             : 
     274             :     /// @brief special destination values
     275             :     static MSEdge mySpecialDest_keepDestination;
     276             :     static MSEdge mySpecialDest_terminateRoute;
     277             : 
     278             :     static std::map<std::string, MSTriggeredRerouter*> myInstances;
     279             : 
     280             : private:
     281             :     /// @brief Invalidated copy constructor.
     282             :     MSTriggeredRerouter(const MSTriggeredRerouter&);
     283             : 
     284             :     /// @brief Invalidated assignment operator.
     285             :     MSTriggeredRerouter& operator=(const MSTriggeredRerouter&);
     286             : 
     287             : 
     288             : };

Generated by: LCOV version 1.14