Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2025 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// ===========================================================================
28class MSRailSignal;
30class MSEdge;
31class MSDriveWay;
32
33// ===========================================================================
34// class definitions
35// ===========================================================================
41public:
43
45
46 static bool hasInstance() {
47 return myInstance != nullptr;
48 }
49
50 static void cleanup();
51
53 static void clearState();
54
57 myWaitRelations.clear();
58 myWrittenDeadlocks.clear();
59 }
60
61 void addWaitRelation(const SUMOVehicle* waits, const MSRailSignal* rs, const SUMOVehicle* reason, MSRailSignalConstraint* constraint = nullptr);
62
63 void addDrivewayFollower(const MSDriveWay* dw, const MSDriveWay* dw2);
64
66 void addDWDeadlockChecks(const MSRailSignal* rs, MSDriveWay* dw);
67
69 bool haveDeadlock(const SUMOVehicle* veh) const;
70
71 void addDeadlockCheck(std::vector<const MSRailSignal*> signals);
72
78 void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& info = "");
79
80 void addSignal(MSRailSignal* signal);
81
82 const std::vector<MSRailSignal*>& getSignals() const {
83 return mySignals;
84 }
85
86 const std::map<const MSRailSignal*, std::vector<const MSRailSignal*> >& getDeadlockChecks() const {
87 return myDeadlockChecks;
88 }
89
91 void notifyApproach(const MSLink* link);
92
94 void updateSignals(SUMOTime t);
95
96
97 static bool isSignalized(SUMOVehicleClass svc) {
98 return (mySignalizedClasses & svc) == svc;
99 }
100
103 }
104
105protected:
106
107 void findDeadlockFoes(const MSDriveWay* dw, const std::vector<const MSRailSignal*>& others, std::vector<const MSDriveWay*> deadlockFoes);
108
109
110private:
113
115 void updateDriveways(const MSEdge* used);
116
118 std::set<const MSEdge*> myUsedEdges;
119
121 WaitRelation(const MSRailSignal* _railSignal = nullptr, const SUMOVehicle* _foe = nullptr, MSRailSignalConstraint* _constraint = nullptr) :
122 railSignal(_railSignal), foe(_foe), constraint(_constraint) {}
123 // indices along route
127 };
128 std::map<const SUMOVehicle*, WaitRelation> myWaitRelations;
129
130 mutable std::set<std::set<const SUMOVehicle*> > myWrittenDeadlocks;
131
132 std::map<const MSRailSignal*, std::vector<const MSRailSignal*> > myDeadlockChecks;
133 std::map<const MSDriveWay*, std::set<const MSDriveWay*>> myDriveWaySucc;
134 std::map<const MSDriveWay*, std::set<const MSDriveWay*>> myDriveWayPred;
135
137 std::vector<MSRailSignal*> mySignals;
138
140 std::vector<std::pair<MSLink*, int> > mySwitchedGreenFlanks;
141 std::map<std::pair<int, int>, bool> myDriveWayCompatibility;
142 std::set<MSRailSignal*, ComparatorNumericalIdLess> myActiveSignals;
143
146
148
149
150};
long long int SUMOTime
Definition GUI.h:36
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
A road/street connecting two junctions.
Definition MSEdge.h:77
Interface for objects listening to vehicle state changes.
Definition MSNet.h:647
VehicleState
Definition of a vehicle state.
Definition MSNet.h:614
A base class for constraints.
A signal for rails.
static bool isSignalized(SUMOVehicleClass svc)
void notifyApproach(const MSLink *link)
switch rail signal to active
void addSignal(MSRailSignal *signal)
void vehicleStateChanged(const SUMOVehicle *const vehicle, MSNet::VehicleState to, const std::string &info="")
Called if a vehicle changes its state.
std::map< const MSDriveWay *, std::set< const MSDriveWay * > > myDriveWaySucc
void addDeadlockCheck(std::vector< const MSRailSignal * > signals)
void addDrivewayFollower(const MSDriveWay *dw, const MSDriveWay *dw2)
std::vector< MSRailSignal * > mySignals
list of all rail signals
std::map< const MSRailSignal *, std::vector< const MSRailSignal * > > myDeadlockChecks
MSRailSignalControl()
Constructor.
std::set< const MSEdge * > myUsedEdges
all rail edges that are part of a known route
void addWaitRelation(const SUMOVehicle *waits, const MSRailSignal *rs, const SUMOVehicle *reason, MSRailSignalConstraint *constraint=nullptr)
static MSRailSignalControl * myInstance
std::map< const SUMOVehicle *, WaitRelation > myWaitRelations
void addDWDeadlockChecks(const MSRailSignal *rs, MSDriveWay *dw)
check whether the given signal and driveway are part of a deadlock circle
static MSRailSignalControl & getInstance()
std::map< const MSDriveWay *, std::set< const MSDriveWay * > > myDriveWayPred
const std::map< const MSRailSignal *, std::vector< const MSRailSignal * > > & getDeadlockChecks() const
void updateDriveways(const MSEdge *used)
compute additioanl deadlock-check requirements for registered driveways
static SVCPermissions mySignalizedClasses
signalized classes
bool haveDeadlock(const SUMOVehicle *veh) const
whether there is a circle in the waiting-for relationships that contains the given vehicle
const std::vector< MSRailSignal * > & getSignals() const
std::set< std::set< const SUMOVehicle * > > myWrittenDeadlocks
void updateSignals(SUMOTime t)
update active rail signals
std::set< MSRailSignal *, ComparatorNumericalIdLess > myActiveSignals
std::map< std::pair< int, int >, bool > myDriveWayCompatibility
static void clearState()
Perform resets events when quick-loading state.
static void initSignalized(SVCPermissions svc)
void resetWaitRelations()
reset all waiting-for relationships at the start of the simulation step
std::vector< std::pair< MSLink *, int > > mySwitchedGreenFlanks
list of signals that switched green along with driveway index
void findDeadlockFoes(const MSDriveWay *dw, const std::vector< const MSRailSignal * > &others, std::vector< const MSDriveWay * > deadlockFoes)
A signal for rails.
Representation of a vehicle.
Definition SUMOVehicle.h:62
WaitRelation(const MSRailSignal *_railSignal=nullptr, const SUMOVehicle *_foe=nullptr, MSRailSignalConstraint *_constraint=nullptr)