Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSRailSignal.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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/****************************************************************************/
20// A rail signal logic
21/****************************************************************************/
22#include <config.h>
23
24#include <cassert>
25#include <utility>
26#include <vector>
27#include <bitset>
28#ifdef HAVE_FOX
30#endif
33#include <microsim/MSNet.h>
34#include <microsim/MSEdge.h>
36#include <microsim/MSLane.h>
37#include <microsim/MSLink.h>
38#include <microsim/MSVehicle.h>
41#include <microsim/MSLane.h>
42
43#include "MSTLLogicControl.h"
44#include "MSTrafficLightLogic.h"
45#include "MSPhaseDefinition.h"
46#include "MSTLLogicControl.h"
48#include "MSRailSignalControl.h"
49#include "MSDriveWay.h"
50#include "MSRailSignal.h"
51
52//#define DEBUG_SELECT_DRIVEWAY
53//#define DEBUG_DRIVEWAY_UPDATE
54//#define DEBUG_SIGNALSTATE
55//#define DEBUG_REROUTE
56
57#define DEBUG_COND DEBUG_HELPER(this)
58#define DEBUG_COND_LINKINFO DEBUG_HELPER(myLink->getTLLogic())
59#define DEBUG_HELPER(obj) ((obj)->isSelected())
60//#define DEBUG_HELPER(obj) ((obj)->getID() == "")
61//#define DEBUG_HELPER(obj) (true)
62
63// ===========================================================================
64// static value definitions
65// ===========================================================================
66
73std::vector<const MSDriveWay*> MSRailSignal::myBlockingDriveWays;
75
76// ===========================================================================
77// method definitions
78// ===========================================================================
80 const std::string& id, const std::string& programID, SUMOTime delay,
81 const Parameterised::Map& parameters) :
82 MSTrafficLightLogic(tlcontrol, id, programID, 0, TrafficLightType::RAIL_SIGNAL, delay, parameters),
83 myNumericalID(myRSIndex++),
84 myCurrentPhase(DELTA_T, std::string(SUMO_MAX_CONNECTIONS, 'X')), // dummy phase
85 myPhaseIndex(0),
86 myDriveWayIndex(0) {
88 myMovingBlock = OptionsCont::getOptions().getBool("railsignal-moving-block");
90}
91
92void
94 if (myLanes.size() == 0) {
95 WRITE_WARNINGF(TL("Rail signal at junction '%' does not control any links"), getID());
96 }
97 for (LinkVector& links : myLinks) { //for every link index
98 if (links.size() != 1) {
99 throw ProcessError("At railSignal '" + getID() + "' found " + toString(links.size())
100 + " links controlled by index " + toString(links[0]->getTLIndex()));
101 }
102 myLinkInfos.push_back(LinkInfo(links[0]));
103 }
105 setTrafficLightSignals(MSNet::getInstance()->getCurrentTimeStep());
106 myNumLinks = (int)myLinks.size();
108}
109
110
114
115
116// ----------- Handling of controlled links
117void
122
123
124// ------------ Switching and setting current rows
127 // deschedule regular traffic light event,
128 // updateCurrentPhase is instead called from MSRailSignalControl::updateSignals
129 return SUMOTime_MAX;
130}
131
132
133
134bool
136#ifdef DEBUG_SIGNALSTATE
138#endif
139 bool keepActive = false;
140 // green by default so vehicles can be inserted at the borders of the network
141 std::string state(myLinks.size(), 'G');
142 for (LinkInfo& li : myLinkInfos) {
143 if (li.myLink->getApproaching().size() > 0 && li.myControlled) {
144 keepActive = true;
145 Approaching closest = li.myLink->getClosest();
146 MSDriveWay& driveway = li.getDriveWay(closest.first);
147 //std::cout << SIMTIME << " signal=" << getTLLinkID(li.myLink) << " veh=" << closest.first->getID() << " dw:\n";
148 //driveway.writeBlocks(*OutputDevice_COUT::getDevice());
149 const bool mustWait = !constraintsAllow(closest.first, true);
150 MSEdgeVector occupied;
151 if (mustWait || !driveway.reserve(closest, occupied)) {
152 state[li.myLink->getTLIndex()] = 'r';
153 if (occupied.size() > 0) {
154 li.reroute(const_cast<SUMOVehicle*>(closest.first), occupied);
155 }
156#ifdef DEBUG_SIGNALSTATE
157 if (gDebugFlag4) {
158 std::cout << SIMTIME << " rsl=" << li.getID() << " veh=" << closest.first->getID() << " notReserved\n";
159 }
160#endif
161 } else {
162 state[li.myLink->getTLIndex()] = 'G';
163#ifdef DEBUG_SIGNALSTATE
164 if (gDebugFlag4) {
165 std::cout << SIMTIME << " rsl=" << li.getID() << " veh=" << closest.first->getID() << " reserved\n";
166 }
167#endif
168 }
169 } else if (li.myControlled) {
170 if (li.myDriveways.empty()) {
171#ifdef DEBUG_SIGNALSTATE
172 if (gDebugFlag4) {
173 std::cout << SIMTIME << " rsl=" << li.getID() << " red for unitialized signal (no driveways yet)\n";
174 }
175#endif
176 state[li.myLink->getTLIndex()] = 'r';
177 } else {
178 const MSDriveWay& driveway = *li.myDriveways.front();
179 MSEdgeVector occupied;
180 if (driveway.foeDriveWayOccupied(true, nullptr, occupied) || driveway.foeDriveWayApproached()) {
181 keepActive = true;
182#ifdef DEBUG_SIGNALSTATE
183 if (gDebugFlag4) {
184 std::cout << SIMTIME << " rsl=" << li.getID() << " red for default driveway " << driveway.getID() << "\n";
185 }
186#endif
187 state[li.myLink->getTLIndex()] = 'r';
188 } else {
189#ifdef DEBUG_SIGNALSTATE
190 if (gDebugFlag4) {
191 std::cout << SIMTIME << " rsl=" << li.getID() << " green for default driveway " << driveway.getID() << "\n";
192 }
193#endif
194 }
195 }
196 } else {
197 state[li.myLink->getTLIndex()] = 'O';
198 }
199 }
200 if (myCurrentPhase.getState() != state) {
203 // set link priorities
205 // execute switch actions (3D-gui)
206 //const MSTLLogicControl::TLSLogicVariants& vars = myTLControl.get(myTLLogic->getID());
207 //vars.executeOnSwitchActions();
208 }
209#ifdef DEBUG_SIGNALSTATE
210 gDebugFlag4 = false;
211#endif
212 return keepActive;
213}
214
215
216bool
217MSRailSignal::constraintsAllow(const SUMOVehicle* veh, bool storeWaitRelation) const {
218 if (myConstraints.size() == 0) {
219 return true;
220 } else {
221 const std::string tripID = veh->getParameter().getParameter("tripId", veh->getID());
222 auto it = myConstraints.find(tripID);
223 if (it != myConstraints.end()) {
224 for (MSRailSignalConstraint* c : it->second) {
225 // ignore insertion constraints here
226 if (!c->isInsertionConstraint() && !c->cleared()) {
227#ifdef DEBUG_SIGNALSTATE
228 if (gDebugFlag4) {
229 std::cout << " constraint '" << c->getDescription() << "' not cleared\n";
230 }
231#endif
232 if (storeWaitRelation && MSGlobals::gTimeToTeleportRSDeadlock > 0
234 const SUMOVehicle* foe = c->getFoe();
235 if (foe != nullptr) {
237 }
238 }
239 if (myStoreVehicles) {
240 myConstraintInfo = c->getDescription();
241 }
242 return false;
243 }
244 }
245 }
246 return true;
247 }
248}
249
250
251void
252MSRailSignal::addConstraint(const std::string& tripId, MSRailSignalConstraint* constraint) {
253 myConstraints[tripId].push_back(constraint);
254}
255
256
257bool
258MSRailSignal::removeConstraint(const std::string& tripId, MSRailSignalConstraint* constraint) {
259 if (myConstraints.count(tripId) != 0) {
260 auto& constraints = myConstraints[tripId];
261 auto it = std::find(constraints.begin(), constraints.end(), constraint);
262 if (it != constraints.end()) {
263 delete *it;
264 constraints.erase(it);
265 return true;
266 }
267 }
268 return false;
269}
270
271void
273 for (auto item : myConstraints) {
274 for (MSRailSignalConstraint* c : item.second) {
275 delete c;
276 }
277 }
278 myConstraints.clear();
279}
280
281
282// ------------ Static Information Retrieval
283int
285 return 0;
286}
287
290 return myPhases;
291}
292
295 return myCurrentPhase;
296}
297
298// ------------ Dynamic Information Retrieval
299int
303
308
309// ------------ Conversion between time and phase
312 return 0;
313}
314
317 return 0;
318}
319
320int
322 return 0;
323}
324
325
326void
327MSRailSignal::addLink(MSLink* link, MSLane* lane, int pos) {
328 if (pos >= 0) {
329 MSTrafficLightLogic::addLink(link, lane, pos);
330 } // ignore uncontrolled link
331}
332
333
334std::string
335MSRailSignal::describeLinks(std::vector<MSLink*> links) {
336 std::string result;
337 for (MSLink* link : links) {
338 result += link->getDescription() + " ";
339 }
340 return result;
341}
342
343
344void
345MSRailSignal::writeBlocks(OutputDevice& od, bool writeVehicles) const {
346 od.openTag("railSignal");
348 for (const LinkInfo& li : myLinkInfos) {
349 MSLink* link = li.myLink;
350 od.openTag("link");
354 for (const MSDriveWay* dw : li.myDriveways) {
355 if (writeVehicles) {
356 dw->writeBlockVehicles(od);
357 } else {
358 dw->writeBlocks(od);
359 }
360 }
361 od.closeTag(); // link
362 }
363 od.closeTag(); // railSignal
364}
365
366
367void
369 const ConstMSEdgeVector& edges = ego->getRoute().getEdges();
370 int endIndex = ego->getParameter().arrivalEdge;
371 if (endIndex < 0) {
372 endIndex = (int)edges.size() - 1;
373 }
374 const int departIndex = ego->getParameter().departEdge;
375 MSDriveWay* prev = const_cast<MSDriveWay*>(MSDriveWay::getDepartureDriveway(ego, true));
376 if (update && ego->hasDeparted()) {
377 MSBaseVehicle* veh = dynamic_cast<MSBaseVehicle*>(const_cast<SUMOVehicle*>(ego));
378 if (!prev->hasTrain(veh) && prev->notifyEnter(*veh, prev->NOTIFICATION_REROUTE, nullptr) && !veh->hasReminder(prev)) {
379 veh->addReminder(prev, 1);
380 }
381 }
382 for (int i = departIndex; i <= endIndex - 1; i++) {
383 const MSEdge* e = edges[i];
385 const MSEdge* e2 = edges[i + 1];
386 for (MSLane* lane : e->getLanes()) {
387 for (MSLink* link : lane->getLinkCont()) {
388 if (&link->getLane()->getEdge() == e2) {
389 MSRailSignal* rs = const_cast<MSRailSignal*>(dynamic_cast<const MSRailSignal*>(link->getTLLogic()));
390 if (rs != nullptr) {
391 LinkInfo& li = rs->myLinkInfos[link->getTLIndex()];
392 // init driveway
393 MSDriveWay* dw = &li.getDriveWay(ego, i);
397 prev = dw;
398 if (update && rs->isActive()) {
399 // vehicle may have rerouted its intial trip
400 // after the states have been set
401 // @note: This is a hack because it could lead to invalid tls-output
402 // (it's still an improvement over switching based on default driveways)
403 if (!ego->hasDeparted()) {
404 rs->updateCurrentPhase();
406 } else if (ego->hasDeparted() && i <= ego->getRoutePosition()) {
407 MSBaseVehicle* veh = dynamic_cast<MSBaseVehicle*>(const_cast<SUMOVehicle*>(ego));
408 if (!dw->hasTrain(veh) && dw->notifyEnter(*veh, dw->NOTIFICATION_REROUTE, nullptr) && !veh->hasReminder(dw)) {
409 veh->addReminder(dw, 1);
410 for (MSDriveWay* sub : dw->getSubDriveWays()) {
411 if (!sub->hasTrain(veh) && sub->notifyEnter(*veh, dw->NOTIFICATION_REROUTE, nullptr) && !veh->hasReminder(sub)) {
412 veh->addReminder(sub, 1);
413 }
414 }
415 }
416 }
417 }
418 }
419 }
420 }
421 }
422 }
423 }
425}
426
427
428bool
429MSRailSignal::hasInsertionConstraint(MSLink* link, const MSVehicle* veh, std::string& info, bool& isInsertionOrder) {
430 if (link->getJunction() != nullptr && link->getJunction()->getType() == SumoXMLNodeType::RAIL_SIGNAL) {
431 const MSRailSignal* rs = dynamic_cast<const MSRailSignal*>(link->getTLLogic());
432 if (rs != nullptr && rs->myConstraints.size() > 0) {
433 const std::string tripID = veh->getParameter().getParameter("tripId", veh->getID());
434 auto it = rs->myConstraints.find(tripID);
435 if (it != rs->myConstraints.end()) {
436 for (MSRailSignalConstraint* c : it->second) {
437 if (c->isInsertionConstraint() && !c->cleared()) {
438#ifdef DEBUG_SIGNALSTATE
439 if (DEBUG_HELPER(rs)) {
440 std::cout << SIMTIME << " rsl=" << rs->getID() << " insertion constraint '" << c->getDescription() << "' for vehicle '" << veh->getID() << "' not cleared\n";
441 }
442#endif
443 info = c->getDescription();
444 isInsertionOrder = c->getType() == MSRailSignalConstraint::ConstraintType::INSERTION_ORDER;
446 const SUMOVehicle* foe = c->getFoe();
447 if (foe != nullptr) {
449 }
450 }
451 return true;
452 }
453 }
454 }
455 }
456 }
457 return false;
458}
459
460// ===========================================================================
461// LinkInfo method definitions
462// ===========================================================================
463
465 myLink(link) {
466 reset();
467}
468
470 for (MSDriveWay* dw : myDriveways) {
471 delete dw;
472 }
473 myDriveways.clear();
474}
475
476void
478 myLastRerouteTime = -1;
479 myLastRerouteVehicle = nullptr;
480 myDriveways.clear();
481 myControlled = isRailwayOrShared(myLink->getViaLaneOrLane()->getPermissions())
482 && isRailwayOrShared(myLink->getLane()->getPermissions());
483}
484
485
486std::string
488 return myLink->getTLLogic()->getID() + "_" + toString(myLink->getTLIndex());
489}
490
491
494 MSEdge* first = &myLink->getLane()->getEdge();
495 auto searchStartIt = searchStart < 0 ? veh->getCurrentRouteEdge() : veh->getRoute().begin() + searchStart;
496 MSRouteIterator firstIt = std::find(searchStartIt, veh->getRoute().end(), first);
497 if (firstIt == veh->getRoute().end()) {
498 // possibly the vehicle has already gone past the first edge (i.e.
499 // because first is short or the step-length is high)
500 // lets look backward along the route
501 // give some slack because the vehicle might have been braking from a higher speed and using ballistic integration
502 double lookBack = SPEED2DIST(veh->getSpeed() + 10);
503 int routeIndex = veh->getRoutePosition() - 1;
504 while (lookBack > 0 && routeIndex > 0) {
505 const MSEdge* prevEdge = veh->getRoute().getEdges()[routeIndex];
506 if (prevEdge == first) {
507 firstIt = veh->getRoute().begin() + routeIndex;
508 break;
509 }
510 lookBack -= prevEdge->getLength();
511 routeIndex--;
512 }
513 }
514 MSRailSignal* rs = const_cast<MSRailSignal*>(dynamic_cast<const MSRailSignal*>(myLink->getTLLogic()));
515 if (firstIt == veh->getRoute().end()) {
516 WRITE_WARNING("Invalid approach information to rail signal '" + MSDriveWay::getClickableTLLinkID(myLink) + "' after rerouting for vehicle '" + veh->getID()
517 + "' first driveway edge '" + first->getID() + "' time=" + time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
518 if (myDriveways.empty()) {
519 ConstMSEdgeVector dummyRoute;
520 dummyRoute.push_back(&myLink->getLane()->getEdge());
521 MSDriveWay* dw = MSDriveWay::buildDriveWay(rs->getNewDrivewayID(), myLink, dummyRoute.begin(), dummyRoute.end());
522 myDriveways.push_back(dw);
523 }
524 return *myDriveways.front();
525 }
526 //std::cout << SIMTIME << " veh=" << veh->getID() << " rsl=" << getID() << " dws=" << myDriveways.size() << "\n";
527 return getDriveWay(firstIt, veh->getRoute().end(), veh->getID());
528}
529
530
533 for (MSDriveWay* dw : myDriveways) {
534 if (dw->match(firstIt, endIt)) {
535 return *dw;
536 }
537#ifdef DEBUG_SELECT_DRIVEWAY
538 std::cout << SIMTIME << " rs=" << getID() << " veh=" << info << " other dwSignal=" << dw->foundSignal() << " dwRoute=" << toString(dw->getRoute()) << "\n";
539#else
540 UNUSED_PARAMETER(info);
541#endif
542 }
543 MSRailSignal* rs = const_cast<MSRailSignal*>(dynamic_cast<const MSRailSignal*>(myLink->getTLLogic()));
544 MSDriveWay* dw = MSDriveWay::buildDriveWay(rs->getNewDrivewayID(), myLink, firstIt, endIt);
545 dw->setVehicle(info);
546#ifdef DEBUG_SELECT_DRIVEWAY
547 std::cout << SIMTIME << " rs=" << getID() << " veh=" << info << " new dwSignal=" << dw->foundSignal() << " dwRoute=" << toString(dw->getRoute()) << "\n";
548#endif
549 myDriveways.push_back(dw);
550 return *myDriveways.back();
551}
552
553
554void
556 MSDevice_Routing* rDev = static_cast<MSDevice_Routing*>(veh->getDevice(typeid(MSDevice_Routing)));
558 if (rDev != nullptr
559 && rDev->mayRerouteRailSignal()
560 && (myLastRerouteVehicle != veh
561 // reroute each vehicle only once if no periodic routing is allowed,
562 // otherwise with the specified period
563 || (rDev->getPeriod() > 0 && myLastRerouteTime + rDev->getPeriod() <= now))) {
564 myLastRerouteVehicle = veh;
565 myLastRerouteTime = now;
566
567#ifdef DEBUG_REROUTE
568 ConstMSEdgeVector oldRoute = veh->getRoute().getEdges();
570 std::cout << SIMTIME << " reroute veh=" << veh->getID() << " rs=" << getID() << " occupied=" << toString(occupied) << "\n";
571 }
572#endif
573 std::map<const MSEdge*, double> prohibited;
574 for (MSEdge* e : occupied) {
575 // indefinite occupation because vehicles might be in deadlock on their current routes
576 prohibited[e] = -1;
577 }
578 MSRoutingEngine::reroute(*veh, now, "railSignal:" + getID(), false, true, prohibited);
579#ifdef DEBUG_REROUTE
580 // attention this works only if we are not parallel!
582 if (veh->getRoute().getEdges() != oldRoute) {
583 std::cout << " rerouting successful\n";
584 }
585 }
586#endif
587 }
588}
589
590void
599
600
601void
603 resetStored();
604 myStoreVehicles = true;
605 MSEdgeVector occupied;
606 // call for side effects
607 dw->foeDriveWayOccupied(true, nullptr, occupied);
608 myStoreVehicles = false;
609}
610
611void
613 resetStored();
614 myStoreVehicles = true;
615 LinkInfo& li = myLinkInfos[linkIndex];
616 if (li.myLink->getApproaching().size() > 0) {
617 Approaching closest = li.myLink->getClosest();
618 MSDriveWay& driveway = li.getDriveWay(closest.first);
619 MSEdgeVector occupied;
620 myRequestedDriveWay = driveway.getID();
621 // call for side effects
622 driveway.reserve(closest, occupied);
623 constraintsAllow(closest.first);
624 } else if (li.myDriveways.size() > 0) {
625 li.myDriveways.front()->conflictLaneOccupied();
626 li.myDriveways.front()->foeDriveWayApproached();
627 }
628 myStoreVehicles = false;
629}
630
633 storeTraCIVehicles(linkIndex);
634 return myBlockingVehicles;
635}
636
639 storeTraCIVehicles(linkIndex);
640 return myRivalVehicles;
641}
642
645 storeTraCIVehicles(linkIndex);
646 return myPriorityVehicles;
647}
648
649std::string
651 storeTraCIVehicles(linkIndex);
652 return myConstraintInfo;
653}
654
655
656std::string
658 storeTraCIVehicles(linkIndex);
659 return myRequestedDriveWay;
660}
661
662
663std::vector<const MSDriveWay*>
665 storeTraCIVehicles(linkIndex);
666 return myBlockingDriveWays;
667}
668
669
675
676
677std::vector<const MSDriveWay*>
682
683const MSDriveWay&
684MSRailSignal::retrieveDriveWay(int numericalID) const {
685 for (const LinkInfo& li : myLinkInfos) {
686 for (const MSDriveWay* dw : li.myDriveways) {
687 if (dw->getNumericalID() == numericalID) {
688 return *dw;
689 }
690 }
691 }
692 throw ProcessError("Invalid driveway id " + toString(numericalID) + " at railSignal '" + getID() + "'");
693}
694
695const MSDriveWay&
697 return myLinkInfos[tlIndex].getDriveWay(veh);
698}
699
700const MSDriveWay&
702 return myLinkInfos[tlIndex].getDriveWay(first, end);
703}
704
705
706const std::vector<MSDriveWay*>
708 return myLinkInfos[tlIndex].myDriveways;
709}
710
711
712std::string
714 MSRailSignal* rs = const_cast<MSRailSignal*>(this);
715 if (myLinkInfos.size() == 1) {
716 return toString(rs->getBlockingVehicles(0));
717 } else {
718 std::string result;
719 for (int i = 0; i < (int)myLinkInfos.size(); i++) {
720 result += toString(i) + ": " + toString(rs->getBlockingVehicles(i)) + ";";
721 }
722 return result;
723 }
724}
725std::string
727 MSRailSignal* rs = const_cast<MSRailSignal*>(this);
728 if (myLinkInfos.size() == 1) {
729 return toString(rs->getRivalVehicles(0));
730 } else {
731 std::string result;
732 for (int i = 0; i < (int)myLinkInfos.size(); i++) {
733 result += toString(i) + ": " + toString(rs->getRivalVehicles(i)) + ";";
734 }
735 return result;
736 }
737}
738std::string
740 MSRailSignal* rs = const_cast<MSRailSignal*>(this);
741 if (myLinkInfos.size() == 1) {
742 return toString(rs->getPriorityVehicles(0));
743 } else {
744 std::string result;
745 for (int i = 0; i < (int)myLinkInfos.size(); i++) {
746 result += toString(i) + ": " + toString(rs->getPriorityVehicles(i)) + ";";
747 }
748 return result;
749 }
750}
751std::string
753 MSRailSignal* rs = const_cast<MSRailSignal*>(this);
754 if (myLinkInfos.size() == 1) {
755 return rs->getConstraintInfo(0);
756 } else {
757 std::string result;
758 for (int i = 0; i < (int)myLinkInfos.size(); i++) {
759 result += toString(i) + ": " + rs->getConstraintInfo(i);
760 }
761 return result;
762 }
763}
764std::string
766 MSRailSignal* rs = const_cast<MSRailSignal*>(this);
767 if (myLinkInfos.size() == 1) {
768 return toString(rs->getRequestedDriveWay(0));
769 } else {
770 std::string result;
771 for (int i = 0; i < (int)myLinkInfos.size(); i++) {
772 result += toString(i) + ": " + toString(rs->getRequestedDriveWay(i)) + ";";
773 }
774 return result;
775 }
776}
777std::string
779 MSRailSignal* rs = const_cast<MSRailSignal*>(this);
780 if (myLinkInfos.size() == 1) {
781 return toString(rs->getBlockingDriveWays(0));
782 } else {
783 std::string result;
784 for (int i = 0; i < (int)myLinkInfos.size(); i++) {
785 result += toString(i) + ": " + toString(rs->getBlockingDriveWays(i)) + ";";
786 }
787 return result;
788 }
789}
790
791void
792MSRailSignal::setParameter(const std::string& key, const std::string& value) {
793 // some pre-defined parameters can be updated at runtime
794 if (key == "moving-block") {
795 bool movingBlock = StringUtils::toBool(value);
796 if (movingBlock != myMovingBlock) {
797 // recompute driveways
798 myMovingBlock = movingBlock;
799 for (LinkInfo& li : myLinkInfos) {
800 li.reset();
801 }
803 setTrafficLightSignals(MSNet::getInstance()->getCurrentTimeStep());
804 }
805 }
806 Parameterised::setParameter(key, value);
807}
808
809
810std::string
814/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define DEBUG_HELPER(obj)
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
#define DEBUG_COND_LINKINFO
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:57
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define SPEED2DIST(x)
Definition SUMOTime.h:45
#define SIMSTEP
Definition SUMOTime.h:61
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:62
bool isRailwayOrShared(SVCPermissions permissions)
Returns whether an edge with the given permissions is a railway edge or a shared road/rail edge.
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ SUMO_ATTR_ID
@ SUMO_ATTR_TLLINKINDEX
link: the index of the link within the traffic light
bool gDebugFlag4
Definition StdDefs.cpp:46
#define SUMO_MAX_CONNECTIONS
the maximum number of connections across an intersection
Definition StdDefs.h:45
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
The base class for microscopic and mesoscopic vehicles.
bool hasReminder(MSMoveReminder *rem) const
Checks whether the vehilce has the given MoveReminder.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
void addReminder(MSMoveReminder *rem, double pos=0)
Adds a MoveReminder dynamically.
SUMOTime getStartupDelay() const
Get the vehicle type's startupDelay.
Definition MSCFModel.h:293
A device that performs vehicle rerouting based on current edge speeds.
SUMOTime getPeriod() const
bool mayRerouteRailSignal() const
return whether the equipped vehicle may receive dispatch information at a rail signal
static std::string getClickableTLLinkID(const MSLink *link)
return logicID_linkIndex in a way that allows clicking in sumo-gui
const std::vector< MSDriveWay * > & getSubDriveWays() const
Definition MSDriveWay.h:170
bool hasTrain(SUMOVehicle *veh) const
whether the given train is on this driveway
void setVehicle(const std::string &vehID)
Definition MSDriveWay.h:142
const std::vector< const MSEdge * > & getRoute() const
Definition MSDriveWay.h:114
static MSDriveWay * buildDriveWay(const std::string &id, const MSLink *link, MSRouteIterator first, MSRouteIterator end)
construct a new driveway by searching along the given route until all block structures are found
bool foeDriveWayApproached() const
whether any of my Foes is being approached
static const MSDriveWay * getDepartureDriveway(const SUMOVehicle *veh, bool init=false)
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane)
Checks whether the reminder is activated by a vehicle entering the lane.
bool reserve(const Approaching &closest, MSEdgeVector &occupied)
attempt reserve this driveway for the given vehicle
bool foeDriveWayOccupied(bool store, const SUMOVehicle *ego, MSEdgeVector &occupied) const
whether any of myFoes is occupied (vehicles that are the target of a join must be ignored)
A road/street connecting two junctions.
Definition MSEdge.h:77
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
bool isNormal() const
return whether this edge is an internal edge
Definition MSEdge.h:263
const MSJunction * getToJunction() const
Definition MSEdge.h:426
double getLength() const
return the length of the edge
Definition MSEdge.h:693
static SUMOTime gTimeToTeleportRSDeadlock
Definition MSGlobals.h:72
SumoXMLNodeType getType() const
return the type of this Junction
Definition MSJunction.h:133
Representation of a lane in the micro simulation.
Definition MSLane.h:84
@ NOTIFICATION_REROUTE
The vehicle changed it's route.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:334
The definition of a single phase of a tls logic.
const std::string & getState() const
Returns the state within this phase.
void setState(const std::string &_state)
A base class for constraints.
void notifyApproach(const MSLink *link)
switch rail signal to active
void addSignal(MSRailSignal *signal)
void addDrivewayFollower(const MSDriveWay *dw, const MSDriveWay *dw2)
void addWaitRelation(const SUMOVehicle *waits, const MSRailSignal *rs, const SUMOVehicle *reason, MSRailSignalConstraint *constraint=nullptr)
void addDWDeadlockChecks(const MSRailSignal *rs, MSDriveWay *dw)
check whether the given signal and driveway are part of a deadlock circle
static MSRailSignalControl & getInstance()
A signal for rails.
static VehicleVector myRivalVehicles
std::string getBlockingVehicleIDs() const
Phases myPhases
The list of phases this logic uses.
std::string getConstraintInfo(int linkIndex)
return information regarding active rail signal constraints for the closest approaching vehicle
static VehicleVector myPriorityVehicles
std::string getRequestedDriveWay() const
int myPhaseIndex
MSTrafficLightLogic requires that the phase index changes whenever signals change their state.
SUMOTime getOffsetFromIndex(int index) const override
Returns the position (start of a phase during a cycle) from of a given step.
void setParameter(const std::string &key, const std::string &value) override
Sets a parameter and updates internal constants.
static std::string myConstraintInfo
MSPhaseDefinition myCurrentPhase
The current phase.
void addConstraint(const std::string &tripId, MSRailSignalConstraint *constraint)
register constraint for signal switching
std::vector< LinkInfo > myLinkInfos
data storage for every link at this node (more than one when directly guarding a switch)
const MSDriveWay & retrieveDriveWayForVeh(int tlIndex, const SUMOVehicle *veh)
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const override
Returns the index of the logic at the given simulation step.
std::string getPriorityVehicleIDs() const
MSRailSignal(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, SUMOTime delay, const Parameterised::Map &parameters)
Constructor.
static std::string myRequestedDriveWay
VehicleVector getBlockingVehicles(int linkIndex) override
return vehicles that block the intersection/rail signal for vehicles that wish to pass the given link...
void writeBlocks(OutputDevice &od, bool writeVehicles) const
write rail signal block output for all links and driveways
VehicleVector getRivalVehicles(int linkIndex) override
return vehicles that approach the intersection/rail signal and are in conflict with vehicles that wis...
int myDriveWayIndex
running number of driveways created for this signal
static std::string describeLinks(std::vector< MSLink * > links)
print link descriptions
~MSRailSignal()
Destructor.
static void resetStored()
reset temporary storage for injected conflict output
void adaptLinkInformationFrom(const MSTrafficLightLogic &logic) override
Applies information about controlled links and lanes from the given logic.
static int myRSIndex
static VehicleVector myBlockingVehicles
bool constraintsAllow(const SUMOVehicle *veh, bool storeWaitRelation=false) const
whether the given vehicle is free to drive
void removeConstraints()
void storeTraCIVehicles(int linkIndex)
update vehicle lists for traci calls
int getIndexFromOffset(SUMOTime offset) const override
Returns the step (the phasenumber) of a given position of the cycle.
void init(NLDetectorBuilder &nb) override
Initialises the rail signal with information about adjacent rail signals.
std::map< std::string, std::vector< MSRailSignalConstraint * > > myConstraints
map from tripId to constraint list
std::pair< const SUMOVehicle *const, const MSLink::ApproachingVehicleInformation > Approaching
int getPhaseNumber() const override
Returns the number of phases.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
SUMOTime trySwitch() override
Switches to the next phase.
std::string getBlockingDriveWayIDs() const
const std::vector< MSDriveWay * > retrieveDriveWays(int tlIndex) const
const MSDriveWay & retrieveDriveWay(int numericalID) const
static bool myStoreVehicles
std::string getRequestedDriveWay(int linkIndex) override
return vehicles that approach the intersection/rail signal and have priority over vehicles that wish ...
bool myMovingBlock
whether the signal is in moving block mode (only protects from oncoming and flanking trains)
bool removeConstraint(const std::string &tripId, MSRailSignalConstraint *constraint)
remove constraint for signal switching
static std::vector< const MSDriveWay * > myBlockingDriveWays
bool updateCurrentPhase()
returns the state of the signal that actually required
const Phases & getPhases() const override
Returns the phases of this tls program.
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns the definition of the current phase.
std::string getConstraintInfo() const
std::string getNewDrivewayID()
static void initDriveWays(const SUMOVehicle *ego, bool update)
void addLink(MSLink *link, MSLane *lane, int pos) override
Adds a link on building.
const MSDriveWay & retrieveDriveWayForRoute(int tlIndex, MSRouteIterator first, MSRouteIterator end)
std::string getRivalVehicleIDs() const
static bool hasInsertionConstraint(MSLink *link, const MSVehicle *veh, std::string &info, bool &isInsertionOrder)
VehicleVector getPriorityVehicles(int linkIndex) override
return vehicles that approach the intersection/rail signal and have priority over vehicles that wish ...
std::vector< const MSDriveWay * > getBlockingDriveWays(int linkIndex) override
return vehicles that approach the intersection/rail signal and have priority over vehicles that wish ...
int getCurrentPhaseIndex() const override
Returns the current index within the program.
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:125
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition MSRoute.cpp:79
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition MSRoute.cpp:73
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const Prohibitions &prohibited={})
initiate the rerouting, create router / thread pool on first use
A class that stores and controls tls and switching of their programs.
void deschedule(MSTrafficLightLogic *tlLogic)
Marks this swicth as invalid (if the phase duration has changed, f.e.)
The parent class for traffic light logics.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
std::vector< const SUMOVehicle * > VehicleVector
list of vehicles
SUMOTime myDefaultCycleTime
The cycle time (without changes)
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
SwitchCommand * mySwitchCommand
The current switch command.
int myNumLinks
number of controlled links
bool isActive() const
whether this logic is the active program
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
virtual void addLink(MSLink *link, MSLane *lane, int pos)
Adds a link on building.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
Builds detectors for microsim.
const std::string & getID() const
Returns the id.
Definition Named.h:74
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.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::map< std::string, std::string > Map
parameters map
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual SUMOTime getWaitingTime(const bool accumulated=false) const =0
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual int getRoutePosition() const =0
return index of edge within route
Representation of a vehicle.
Definition SUMOVehicle.h:62
virtual bool hasDeparted() const =0
Returns whether this vehicle has departed.
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual const MSRoute & getRoute() const =0
Returns the current route.
int departEdge
(optional) The initial edge within the route of the vehicle
int arrivalEdge
(optional) The final edge within the route of the vehicle
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
#define UNUSED_PARAMETER(x)
#define DEBUG_COND
Definition json.hpp:4471