LCOV - code coverage report
Current view: top level - src/microsim/traffic_lights - MSRailSignalControl.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 3 3 100.0 %
Date: 2024-05-19 15:37:39 Functions: 0 0 -

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2002-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    MSRailSignalControl.h
      15             : /// @author  Jakob Erdmann
      16             : /// @date    Sept 2020
      17             : ///
      18             : // Centralized services for rail signal control (Singleton)
      19             : // - monitors track usage for long-range deadlock prevention
      20             : /****************************************************************************/
      21             : #pragma once
      22             : #include <config.h>
      23             : #include <microsim/MSNet.h>
      24             : 
      25             : // ===========================================================================
      26             : // class declarations
      27             : // ===========================================================================
      28             : class MSRailSignal;
      29             : class MSEdge;
      30             : 
      31             : // ===========================================================================
      32             : // class definitions
      33             : // ===========================================================================
      34             : /**
      35             :  * @class MSRailSignalControl
      36             :  * @brief A signal for rails
      37             :  */
      38             : class MSRailSignalControl : public MSNet::VehicleStateListener {
      39             : public:
      40             :     ~MSRailSignalControl();
      41             : 
      42             :     static MSRailSignalControl& getInstance();
      43             : 
      44             :     static bool hasInstance() {
      45    77448259 :         return myInstance != nullptr;
      46             :     }
      47             : 
      48             :     static void cleanup();
      49             : 
      50             :     /** @brief Perform resets events when quick-loading state */
      51             :     static void clearState();
      52             : 
      53             :     /** @brief Called if a vehicle changes its state
      54             :      * @param[in] vehicle The vehicle which changed its state
      55             :      * @param[in] to The state the vehicle has changed to
      56             :      * @param[in] info Additional information on the state change
      57             :      */
      58             :     void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& info = "");
      59             : 
      60             :     /// @brief mark driveway that must receive additional checks if protectedBidi is ever used by a train route
      61             :     void registerProtectedDriveway(MSRailSignal* rs, int driveWayID, const MSEdge* protectedBidi);
      62             : 
      63             :     const std::set<const MSEdge*>& getUsedEdges() const {
      64             :         return myUsedEdges;
      65             :     }
      66             : 
      67             :     void addSignal(MSRailSignal* signal);
      68             : 
      69             :     const std::vector<MSRailSignal*>& getSignals() const {
      70             :         return mySignals;
      71             :     }
      72             : 
      73             :     void addGreenFlankSwitch(MSLink* link, int dwID) {
      74        1403 :         mySwitchedGreenFlanks.emplace_back(link, dwID);
      75        1403 :     }
      76             : 
      77             :     /// @brief final check for driveway compatibility of signals that switched green in this step
      78             :     void recheckGreen();
      79             : 
      80             : private:
      81             :     /** @brief Constructor */
      82             :     MSRailSignalControl();
      83             : 
      84             :     /// @brief compute additioanl deadlock-check requirements for registered driveways
      85             :     void updateDriveways(const MSEdge* used);
      86             : 
      87             :     /// @brief all rail edges that are part of a known route
      88             :     std::set<const MSEdge*> myUsedEdges;
      89             : 
      90             :     /// @brief map of driveways that must perform additional checks if the key edge is used by a train route
      91             :     std::map<const MSEdge*, std::vector<std::pair<MSRailSignal*, int> > > myProtectedDriveways;
      92             : 
      93             :     /// @brief list of all rail signals
      94             :     std::vector<MSRailSignal*> mySignals;
      95             : 
      96             :     /// @brief list of signals that switched green along with driveway index
      97             :     std::vector<std::pair<MSLink*, int> > mySwitchedGreenFlanks;
      98             :     std::map<std::pair<int, int>, bool> myDriveWayCompatibility;
      99             : 
     100             :     static MSRailSignalControl* myInstance;
     101             : 
     102             : 
     103             : };

Generated by: LCOV version 1.14