54 myMaxTrainLength(
OptionsCont::getOptions().getFloat(
"railway.max-train-length"))
110 for (
const auto& links : signal->
getLinks()) {
111 for (
const MSLink* link : links) {
127 std::set<const SUMOVehicle*> seen;
128 std::vector<WaitRelation> list;
130 std::vector<MSRailSignalConstraint*> constraints;
131 std::vector<const SUMOVehicle*> constraintBlocked;
132 std::vector<const MSRailSignal*> constraintSignals;
134 while (seen.count(cur) == 0) {
137 if (it->second.constraint !=
nullptr) {
138 constraints.push_back(it->second.constraint);
139 constraintBlocked.push_back(cur);
140 constraintSignals.push_back(it->second.railSignal);
143 list.push_back(it->second);
144 cur = it->second.foe;
156 if (!constraints.empty() && oc.
getBool(
"time-to-teleport.remove-constraint")) {
157 resolved = constraints.front();
159 std::vector<std::string> vehicles;
160 for (
auto item : list) {
161 vehicles.push_back(item.foe->getID());
165 resolvedUnblocked = constraintBlocked.front();
166 resolvedSignal = constraintSignals.front();
170 if (oc.
isSet(
"deadlock-output")) {
173 std::vector<std::string> signals;
174 std::vector<std::string> vehicles;
175 std::vector<std::string> tripIDs;
176 for (
auto item : list) {
177 signals.push_back(item.railSignal ==
nullptr ?
"INSERTION" : item.railSignal->getID());
178 vehicles.push_back(item.foe->getID());
179 tripIDs.push_back(item.foe->getParameter().getParameter(
"tripId", item.foe->getID()));
183 std::rotate(signals.begin(), signals.begin() + 1, signals.end());
185 if (constraints.empty()) {
188 od.
openTag(
"constraintDeadlock");
193 if (!constraints.empty()) {
196 if (resolved !=
nullptr) {
197 od.
openTag(
"resolvedConstraint");
202 for (
auto item : list) {
203 int start = item.foe->getRoutePosition();
205 const std::vector<MSLane*>& further =
dynamic_cast<const MSVehicle*
>(item.foe)->getFurtherLanes();
208 const MSRoute& route = item.foe->getRoute();
217 return resolved ==
nullptr;
228 WRITE_WARNING(
"Deadlocks should be loaded before any vehicles");
230#ifdef DEBUG_BUILD_DEADLOCK_CHECK
231 std::cout <<
" loadedDeadlockCheck signals=" <<
toString(signals) <<
"\n";
236 const int n = (int)signals.size();
237 for (
int i = 0; i < n; i++) {
246 const int signalIndex = (int)dl.
edges.size();
249 auto it = edges.begin();
250 while (it != edges.end() && (*it)->getToJunction() != j) {
253 if (it == edges.end()) {
254 throw ProcessError(
"Rail signal junction '" + j->
getID() +
"' not passed by loaded deadlock edges '" +
toString(edges) +
"'.");
256 const MSEdge* firstSignalEdge = *it;
258 for (
auto it2 = edges.begin(); it2 != it; it2++) {
260 const MSLink* link = (*it2)->getLanes().front()->getLinkTo((*(it2 + 1))->getLanes().front());
262 firstSignalEdge = *it2;
268 dl.
edges.push_back(edges);
269#ifdef DEBUG_BUILD_DEADLOCK_CHECK
270 std::cout <<
" loadedDeadlockRoute signal=" << rs->
getID() <<
" signalEdge=" << firstSignalEdge->
getID() <<
" edges=" <<
toString(edges) <<
"\n";
289#ifdef DEBUG_BUILD_DEADLOCK_CHECK
290 std::cout <<
" needsDeadlockChecks? rs=" << rs->
getID() <<
" dw=" << dw->
getID() <<
"\n";
295 for (
const auto& pair : itDL->second) {
297 std::vector<const MSDriveWay*> deadlockFoes;
298 if (dl.
edges.empty()) {
302 if (forwardEnd == &dw->
getForward().back()->getEdge()) {
316 if (deadlockFoes.size() < dl.
signals.size()) {
317 signalIndex = (signalIndex + 1) % dl.
signals.size();
320#ifdef DEBUG_BUILD_DEADLOCK_CHECK
321 std::cout <<
" findDLfoes dw=" << dw->
getID() <<
" foundFoes=" <<
toString(deadlockFoes) <<
" otherRS=" << other->
getID() <<
"\n";
323 deadlockFoes.push_back(dw);
325#ifdef DEBUG_BUILD_DEADLOCK_CHECK
326 std::cout <<
" follower=" << follower->getID() <<
" followerFoes=" <<
toString(follower->getFoes()) <<
"\n";
329 if (foe->getForward().back()->getToJunction() == otherJ) {
331 }
else if (foe->isSubDriveWay() && foe->getParent()->getForward().back()->getToJunction() == otherJ && foe->getParentRemainingLength() <
myMaxTrainLength) {
340#ifdef DEBUG_BUILD_DEADLOCK_CHECK
341 std::cout <<
" add deadlock check dlFoes=" <<
toString(deadlockFoes) <<
"\n";;
344 if (!dldw->isDepartDriveway()) {
351 std::vector<const MSDriveWay*> df(deadlockFoes);
352 df.erase(std::find(df.begin(), df.end(), dldw));
353#ifdef DEBUG_BUILD_DEADLOCK_CHECK
354 std::cout <<
" dldw=" << dldw->getID() <<
" df=" <<
toString(df) <<
"\n";
356 const_cast<MSDriveWay*
>(dldw)->addDWDeadlock(df);
366 const size_t n = de.size();
367#ifdef DEBUG_BUILD_DEADLOCK_CHECK
368 std::cout <<
" findDLfoesFromRoutes dw=" << dw->
getID() <<
" foundFoes=" <<
toString(deadlockFoes)
373 if (dw->
getRoute().size() >= n && std::equal(de.begin(), de.end(),
375 deadlockFoes.push_back(dw);
376 if (deadlockFoes.size() < dl.
signals.size()) {
377 signalIndex = (signalIndex + 1) % dl.
signals.size();
392 assert(rs !=
nullptr);
std::vector< const MSEdge * > ConstMSEdgeVector
#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_EDGES
the edges of a route
@ SUMO_ATTR_TIME
trigger: the time of the step
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static bool haveDriveWays()
static const std::vector< MSDriveWay * > & getEndingDriveWays(const MSEdge *edge)
const std::vector< const MSLane * > & getForward() const
const std::vector< const MSEdge * > & getRoute() const
A road/street connecting two junctions.
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
SumoXMLEdgeFunc getFunction() const
Returns the edge type (SumoXMLEdgeFunc)
static int gNumSimThreads
how many threads to use for simulation
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
The base class for an intersection.
bool isTLSControlled() const
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 loadDeadlockRoute(const ConstMSEdgeVector &edges)
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::vector< Deadlock > myLoadedDeadlocks
void addDrivewayFollower(const MSDriveWay *dw, const MSDriveWay *dw2)
std::vector< MSRailSignal * > mySignals
list of all rail signals
void findDeadlockFoesFromRoutes(const MSDriveWay *dw, const Deadlock &dl, int signalIndex, std::vector< const MSDriveWay * > deadlockFoes)
MSRailSignalControl()
Constructor.
void loadDeadlockCheck(std::vector< const MSRailSignal * > signals)
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
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.
static SVCPermissions myMBClasses
std::map< const MSDriveWay *, std::set< const MSDriveWay *, ComparatorNumericalIdLess > > myDriveWaySucc
std::map< const MSRailSignal *, std::vector< std::pair< int, int > > > mySignalDeadlocks
void findDeadlockFoes(const MSDriveWay *dw, const Deadlock &dl, int signalIndex, std::vector< const MSDriveWay * > deadlockFoes)
const MSJunction * getJunction() const
get the unique junction controlled by this signal
bool updateCurrentPhase()
returns the state of the signal that actually required
static void initDriveWays(const SUMOVehicle *ego, bool update)
MSRouteIterator end() const
Returns the end of the list of edges to pass.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
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.
Representation of a vehicle in the micro simulation.
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.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
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 (normal) route edge the object is currently at.
Representation of a vehicle.
virtual bool isRail() const =0
virtual double getLength() const =0
Returns the vehicles's length.
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.
A scoped lock which only triggers on condition.
#define UNUSED_PARAMETER(x)
storage for loaded deadlocks
ConstMSEdgeVector forwardEnds
std::vector< const MSRailSignal * > signals
std::vector< ConstMSEdgeVector > edges