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-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// ===========================================================================
28class MSRailSignal;
30class MSEdge;
31
32// ===========================================================================
33// class definitions
34// ===========================================================================
40public:
42
44
45 static bool hasInstance() {
46 return myInstance != nullptr;
47 }
48
49 static void cleanup();
50
52 static void clearState();
53
56 myWaitRelations.clear();
57 myWrittenDeadlocks.clear();
58 }
59
60 void addWaitRelation(const SUMOVehicle* waits, const MSRailSignal* rs, const SUMOVehicle* reason, MSRailSignalConstraint* constraint = nullptr);
61
62 void addDrivewayFollower(const MSDriveWay* dw, const MSDriveWay* dw2);
63
65 void addDWDeadlockChecks(const MSRailSignal* rs, MSDriveWay* dw);
66
68 bool haveDeadlock(const SUMOVehicle* veh) const;
69
70 void addDeadlockCheck(std::vector<const MSRailSignal*> signals);
71
77 void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to, const std::string& info = "");
78
79 void addSignal(MSRailSignal* signal);
80
81 const std::vector<MSRailSignal*>& getSignals() const {
82 return mySignals;
83 }
84
85 const std::map<const MSRailSignal*, std::vector<const MSRailSignal*> >& getDeadlockChecks() const {
86 return myDeadlockChecks;
87 }
88
90 void notifyApproach(const MSLink* link);
91
93 void updateSignals(SUMOTime t);
94
95
96protected:
97
98 void findDeadlockFoes(const MSDriveWay* dw, const std::vector<const MSRailSignal*>& others, std::vector<const MSDriveWay*> deadlockFoes);
99
100
101private:
104
106 void updateDriveways(const MSEdge* used);
107
109 std::set<const MSEdge*> myUsedEdges;
110
112 WaitRelation(const MSRailSignal* _railSignal = nullptr, const SUMOVehicle* _foe = nullptr, MSRailSignalConstraint* _constraint = nullptr) :
113 railSignal(_railSignal), foe(_foe), constraint(_constraint) {}
114 // indices along route
118 };
119 std::map<const SUMOVehicle*, WaitRelation> myWaitRelations;
120
121 mutable std::set<std::set<const SUMOVehicle*> > myWrittenDeadlocks;
122
123 std::map<const MSRailSignal*, std::vector<const MSRailSignal*> > myDeadlockChecks;
124 std::map<const MSDriveWay*, std::set<const MSDriveWay*>> myDriveWaySucc;
125 std::map<const MSDriveWay*, std::set<const MSDriveWay*>> myDriveWayPred;
126
128 std::vector<MSRailSignal*> mySignals;
129
131 std::vector<std::pair<MSLink*, int> > mySwitchedGreenFlanks;
132 std::map<std::pair<int, int>, bool> myDriveWayCompatibility;
133 std::set<MSRailSignal*, ComparatorNumericalIdLess> myActiveSignals;
134
136
137
138};
long long int SUMOTime
Definition GUI.h:36
A road/street connecting two junctions.
Definition MSEdge.h:77
Interface for objects listening to vehicle state changes.
Definition MSNet.h:641
VehicleState
Definition of a vehicle state.
Definition MSNet.h:608
A base class for constraints.
A signal for rails.
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
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.
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)