99 for (
const auto& links : signal->
getLinks()) {
100 for (
const MSLink* link : links) {
116 std::set<const SUMOVehicle*> seen;
117 std::vector<WaitRelation> list;
119 std::vector<MSRailSignalConstraint*> constraints;
120 std::vector<const SUMOVehicle*> constraintBlocked;
121 std::vector<const MSRailSignal*> constraintSignals;
123 while (seen.count(cur) == 0) {
126 if (it->second.constraint !=
nullptr) {
127 constraints.push_back(it->second.constraint);
128 constraintBlocked.push_back(cur);
129 constraintSignals.push_back(it->second.railSignal);
132 list.push_back(it->second);
133 cur = it->second.foe;
145 if (!constraints.empty() && oc.
getBool(
"time-to-teleport.remove-constraint")) {
146 resolved = constraints.front();
148 std::vector<std::string> vehicles;
149 for (
auto item : list) {
150 vehicles.push_back(item.foe->getID());
154 resolvedUnblocked = constraintBlocked.front();
155 resolvedSignal = constraintSignals.front();
159 if (oc.
isSet(
"deadlock-output")) {
162 std::vector<std::string> signals;
163 std::vector<std::string> vehicles;
164 std::vector<std::string> tripIDs;
165 for (
auto item : list) {
166 signals.push_back(item.railSignal ==
nullptr ?
"INSERTION" : item.railSignal->getID());
167 vehicles.push_back(item.foe->getID());
168 tripIDs.push_back(item.foe->getParameter().getParameter(
"tripId", item.foe->getID()));
171 if (constraints.empty()) {
174 od.
openTag(
"constraintDeadlock");
179 if (!constraints.empty()) {
182 if (resolved !=
nullptr) {
183 od.
openTag(
"resolvedConstraint");
192 return resolved ==
nullptr;
203 WRITE_WARNING(
"Deadlocks should be loaded before any vehicles");
205 const int n = (int)signals.size();
206 for (
int i = 0; i < n; i++) {
207 std::vector<const MSRailSignal*> others;
208 for (
int j = 0; j < n; j++) {
209 others.push_back(signals[(i + j + 1) % n]);
229 const std::vector<const MSRailSignal*>& others = itDL->second;
231 std::vector<const MSDriveWay*> deadlockFoes;
238#ifdef DEBUG_BUILD_DEADLOCK_CHECK
241 int circleIndex = (int)deadlockFoes.size();
242 if (circleIndex < (
int)others.size()) {
244 deadlockFoes.push_back(dw);
247 if (foe->getForward().back()->getEdge().getToJunction()->getID() == other->
getID()) {
253#ifdef DEBUG_BUILD_DEADLOCK_CHECK
254 std::cout <<
" add deadlock check foes=" <<
toString(deadlockFoes) <<
"\n";;
257 if (dldw->isDepartDriveway()) {
258 const_cast<MSDriveWay*
>(dldw)->addDWDeadlock(deadlockFoes);
261 if (!pred->isDepartDriveway()) {
263 if (std::find(others.begin(), others.end(), predRS) != others.end()) {
269 const_cast<MSDriveWay*
>(pred)->addDWDeadlock(deadlockFoes);
281 assert(rs !=
nullptr);
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
const SVCPermissions SVC_UNSPECIFIED
permissions not specified
bool isRailwayOrShared(SVCPermissions permissions)
Returns whether an edge with the given permissions is a railway edge or a shared road/rail edge.
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
const long long int VEHPARS_FORCE_REROUTE
@ SUMO_TAG_DEADLOCK
Saved deadlock information, also for loading as an extra check.
@ SUMO_ATTR_TIME
trigger: the time of the step
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static bool haveDriveWays()
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
SumoXMLEdgeFunc getFunction() const
Returns the edge type (SumoXMLEdgeFunc)
const MSTrafficLightLogic * getTLLogic() const
Returns the TLS index.
VehicleState
Definition of a vehicle state.
@ BUILT
The vehicle was built, but has not yet departed.
@ NEWROUTE
The vehicle got a new route.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
A base class for constraints.
virtual void setActive(bool active)=0
virtual void write(OutputDevice &out, const std::string &tripId) const =0
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.
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
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
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 findDeadlockFoes(const MSDriveWay *dw, const std::vector< const MSRailSignal * > &others, std::vector< const MSDriveWay * > deadlockFoes)
bool updateCurrentPhase()
returns the state of the signal that actually required
static void initDriveWays(const SUMOVehicle *ego, bool update)
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
bool isActive() const
whether this logic is the active program
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
Representation of a vehicle.
virtual bool isRail() const =0
virtual bool hasValidRoute(std::string &msg, ConstMSRoutePtr route=0) const =0
Validates the current or given route.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
#define UNUSED_PARAMETER(x)