Eclipse SUMO - Simulation of Urban MObility
MSRailSignalControl.h
Go to the documentation of this file.
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 /****************************************************************************/
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 // ===========================================================================
39 public:
41 
43 
44  static bool hasInstance() {
45  return myInstance != nullptr;
46  }
47 
48  static void cleanup();
49 
51  static void clearState();
52 
58  void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& info = "");
59 
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  mySwitchedGreenFlanks.emplace_back(link, dwID);
75  }
76 
78  void recheckGreen();
79 
80 private:
83 
85  void updateDriveways(const MSEdge* used);
86 
88  std::set<const MSEdge*> myUsedEdges;
89 
91  std::map<const MSEdge*, std::vector<std::pair<MSRailSignal*, int> > > myProtectedDriveways;
92 
94  std::vector<MSRailSignal*> mySignals;
95 
97  std::vector<std::pair<MSLink*, int> > mySwitchedGreenFlanks;
98  std::map<std::pair<int, int>, bool> myDriveWayCompatibility;
99 
101 
102 
103 };
A road/street connecting two junctions.
Definition: MSEdge.h:77
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:635
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:602
A signal for rails.
void addSignal(MSRailSignal *signal)
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
const std::set< const MSEdge * > & getUsedEdges() const
std::map< const MSEdge *, std::vector< std::pair< MSRailSignal *, int > > > myProtectedDriveways
map of driveways that must perform additional checks if the key edge is used by a train route
std::vector< MSRailSignal * > mySignals
list of all rail signals
MSRailSignalControl()
Constructor.
std::set< const MSEdge * > myUsedEdges
all rail edges that are part of a known route
void recheckGreen()
final check for driveway compatibility of signals that switched green in this step
static MSRailSignalControl * myInstance
void addGreenFlankSwitch(MSLink *link, int dwID)
static MSRailSignalControl & getInstance()
const std::vector< MSRailSignal * > & getSignals() const
void updateDriveways(const MSEdge *used)
compute additioanl deadlock-check requirements for registered driveways
std::map< std::pair< int, int >, bool > myDriveWayCompatibility
static void clearState()
Perform resets events when quick-loading state.
std::vector< std::pair< MSLink *, int > > mySwitchedGreenFlanks
list of signals that switched green along with driveway index
void registerProtectedDriveway(MSRailSignal *rs, int driveWayID, const MSEdge *protectedBidi)
mark driveway that must receive additional checks if protectedBidi is ever used by a train route
A signal for rails.
Definition: MSRailSignal.h:46
Representation of a vehicle.
Definition: SUMOVehicle.h:60