49 myMaxTrainLength(
OptionsCont::getOptions().getFloat(
"railway.max-train-length"))
105 for (
const auto& links : signal->
getLinks()) {
106 for (
const MSLink* link : links) {
122 std::set<const SUMOVehicle*> seen;
123 std::vector<WaitRelation> list;
125 std::vector<MSRailSignalConstraint*> constraints;
126 std::vector<const SUMOVehicle*> constraintBlocked;
127 std::vector<const MSRailSignal*> constraintSignals;
129 while (seen.count(cur) == 0) {
132 if (it->second.constraint !=
nullptr) {
133 constraints.push_back(it->second.constraint);
134 constraintBlocked.push_back(cur);
135 constraintSignals.push_back(it->second.railSignal);
138 list.push_back(it->second);
139 cur = it->second.foe;
151 if (!constraints.empty() && oc.
getBool(
"time-to-teleport.remove-constraint")) {
152 resolved = constraints.front();
154 std::vector<std::string> vehicles;
155 for (
auto item : list) {
156 vehicles.push_back(item.foe->getID());
160 resolvedUnblocked = constraintBlocked.front();
161 resolvedSignal = constraintSignals.front();
165 if (oc.
isSet(
"deadlock-output")) {
168 std::vector<std::string> signals;
169 std::vector<std::string> vehicles;
170 std::vector<std::string> tripIDs;
171 for (
auto item : list) {
172 signals.push_back(item.railSignal ==
nullptr ?
"INSERTION" : item.railSignal->getID());
173 vehicles.push_back(item.foe->getID());
174 tripIDs.push_back(item.foe->getParameter().getParameter(
"tripId", item.foe->getID()));
178 std::rotate(signals.begin(), signals.begin() + 1, signals.end());
180 if (constraints.empty()) {
183 od.
openTag(
"constraintDeadlock");
188 if (!constraints.empty()) {
191 if (resolved !=
nullptr) {
192 od.
openTag(
"resolvedConstraint");
197 for (
auto item : list) {
198 int start = item.foe->getRoutePosition();
200 const std::vector<MSLane*>& further =
dynamic_cast<const MSVehicle*
>(item.foe)->getFurtherLanes();
203 const MSRoute& route = item.foe->getRoute();
212 return resolved ==
nullptr;
223 WRITE_WARNING(
"Deadlocks should be loaded before any vehicles");
225#ifdef DEBUG_BUILD_DEADLOCK_CHECK
226 std::cout <<
" loadedDeadlockCheck signals=" <<
toString(signals) <<
"\n";
231 const int n = (int)signals.size();
232 for (
int i = 0; i < n; i++) {
241 const int signalIndex = (int)dl.
edges.size();
244 auto it = edges.begin();
245 while (it != edges.end() && (*it)->getToJunction() != j) {
248 if (it == edges.end()) {
249 throw ProcessError(
"Rail signal junction '" + j->
getID() +
"' not passed by loaded deadlock edges '" +
toString(edges) +
"'.");
251 const MSEdge* firstSignalEdge = *it;
253 for (
auto it2 = edges.begin(); it2 != it; it2++) {
255 const MSLink* link = (*it2)->getLanes().front()->getLinkTo((*(it2 + 1))->getLanes().front());
257 firstSignalEdge = *it2;
263 dl.
edges.push_back(edges);
264#ifdef DEBUG_BUILD_DEADLOCK_CHECK
265 std::cout <<
" loadedDeadlockRoute signal=" << rs->
getID() <<
" signalEdge=" << firstSignalEdge->
getID() <<
" edges=" <<
toString(edges) <<
"\n";
284#ifdef DEBUG_BUILD_DEADLOCK_CHECK
285 std::cout <<
" needsDeadlockChecks? rs=" << rs->
getID() <<
" dw=" << dw->
getID() <<
"\n";
290 for (
const auto& pair : itDL->second) {
292 std::vector<const MSDriveWay*> deadlockFoes;
293 if (dl.
edges.empty()) {
297 if (forwardEnd == &dw->
getForward().back()->getEdge()) {
311 if (deadlockFoes.size() < dl.
signals.size()) {
312 signalIndex = (signalIndex + 1) % dl.
signals.size();
315#ifdef DEBUG_BUILD_DEADLOCK_CHECK
316 std::cout <<
" findDLfoes dw=" << dw->
getID() <<
" foundFoes=" <<
toString(deadlockFoes) <<
" otherRS=" << other->
getID() <<
"\n";
318 deadlockFoes.push_back(dw);
320#ifdef DEBUG_BUILD_DEADLOCK_CHECK
321 std::cout <<
" follower=" << follower->getID() <<
" followerFoes=" <<
toString(follower->getFoes()) <<
"\n";
324 if (foe->getForward().back()->getToJunction() == otherJ) {
326 }
else if (foe->isSubDriveWay() && foe->getParent()->getForward().back()->getToJunction() == otherJ && foe->getParentRemainingLength() <
myMaxTrainLength) {
335#ifdef DEBUG_BUILD_DEADLOCK_CHECK
336 std::cout <<
" add deadlock check dlFoes=" <<
toString(deadlockFoes) <<
"\n";;
339 if (!dldw->isDepartDriveway()) {
346 std::vector<const MSDriveWay*> df(deadlockFoes);
347 df.erase(std::find(df.begin(), df.end(), dldw));
348#ifdef DEBUG_BUILD_DEADLOCK_CHECK
349 std::cout <<
" dldw=" << dldw->getID() <<
" df=" <<
toString(df) <<
"\n";
351 const_cast<MSDriveWay*
>(dldw)->addDWDeadlock(df);
361 const size_t n = de.size();
362#ifdef DEBUG_BUILD_DEADLOCK_CHECK
363 std::cout <<
" findDLfoesFromRoutes dw=" << dw->
getID() <<
" foundFoes=" <<
toString(deadlockFoes)
368 if (dw->
getRoute().size() >= n && std::equal(de.begin(), de.end(),
370 deadlockFoes.push_back(dw);
371 if (deadlockFoes.size() < dl.
signals.size()) {
372 signalIndex = (signalIndex + 1) % dl.
signals.size();
387 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 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.
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
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 (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.
#define UNUSED_PARAMETER(x)
storage for loaded deadlocks
ConstMSEdgeVector forwardEnds
std::vector< const MSRailSignal * > signals
std::vector< ConstMSEdgeVector > edges