57#define DEBUG_COND DEBUG_HELPER(this)
58#define DEBUG_COND_LINKINFO DEBUG_HELPER(myLink->getTLLogic())
59#define DEBUG_HELPER(obj) ((obj)->isSelected())
80 const std::string&
id,
const std::string& programID,
SUMOTime delay,
83 myNumericalID(myRSIndex++),
99 if (links.size() != 1) {
101 +
" links controlled by index " +
toString(links[0]->getTLIndex()));
136#ifdef DEBUG_SIGNALSTATE
139 bool keepActive =
false;
141 std::string state(
myLinks.size(),
'G');
143 if (li.myLink->getApproaching().size() > 0) {
146 MSDriveWay& driveway = li.getDriveWay(closest.first);
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);
156#ifdef DEBUG_SIGNALSTATE
158 std::cout <<
SIMTIME <<
" rsl=" << li.getID() <<
" veh=" << closest.first->getID() <<
" notReserved\n";
162 state[li.myLink->getTLIndex()] =
'G';
163#ifdef DEBUG_SIGNALSTATE
165 std::cout <<
SIMTIME <<
" rsl=" << li.getID() <<
" veh=" << closest.first->getID() <<
" reserved\n";
170 if (li.myDriveways.empty()) {
171#ifdef DEBUG_SIGNALSTATE
173 std::cout <<
SIMTIME <<
" rsl=" << li.getID() <<
" red for unitialized signal (no driveways yet)\n";
176 state[li.myLink->getTLIndex()] =
'r';
178 const MSDriveWay& driveway = *li.myDriveways.front();
182#ifdef DEBUG_SIGNALSTATE
184 std::cout <<
SIMTIME <<
" rsl=" << li.
getID() <<
" red for default driveway " << driveway.
getID() <<
"\n";
187 state[li.myLink->getTLIndex()] =
'r';
189#ifdef DEBUG_SIGNALSTATE
191 std::cout <<
SIMTIME <<
" rsl=" << li.getID() <<
" green for default driveway " << driveway.
getID() <<
"\n";
207#ifdef DEBUG_SIGNALSTATE
224 if (!c->isInsertionConstraint() && !c->cleared()) {
225#ifdef DEBUG_SIGNALSTATE
227 std::cout <<
" constraint '" << c->getDescription() <<
"' not cleared\n";
233 if (foe !=
nullptr) {
259 auto it = std::find(constraints.begin(), constraints.end(), constraint);
260 if (it != constraints.end()) {
262 constraints.erase(it);
335 for (
MSLink* link : links) {
336 result += link->getDescription() +
" ";
354 dw->writeBlockVehicles(od);
370 endIndex = (int)edges.size() - 1;
374 for (
int i = departIndex; i <= endIndex - 1; i++) {
375 const MSEdge* e = edges[i];
377 const MSEdge* e2 = edges[i + 1];
379 for (
MSLink* link : lane->getLinkCont()) {
380 if (&link->getLane()->getEdge() == e2) {
417 if (c->isInsertionConstraint() && !c->cleared()) {
418#ifdef DEBUG_SIGNALSTATE
420 std::cout <<
SIMTIME <<
" rsl=" << rs->
getID() <<
" insertion constraint '" << c->getDescription() <<
"' for vehicle '" << veh->
getID() <<
"' not cleared\n";
423 info = c->getDescription();
427 if (foe !=
nullptr) {
458 myLastRerouteTime = -1;
459 myLastRerouteVehicle =
nullptr;
466 return myLink->getTLLogic()->getID() +
"_" +
toString(myLink->getTLIndex());
472 MSEdge* first = &myLink->getLane()->getEdge();
481 while (lookBack > 0 && routeIndex > 0) {
483 if (prevEdge == first) {
495 if (myDriveways.empty()) {
497 dummyRoute.push_back(&myLink->getLane()->getEdge());
499 myDriveways.push_back(dw);
501 return *myDriveways.front();
511 if (dw->match(firstIt, endIt)) {
514#ifdef DEBUG_SELECT_DRIVEWAY
515 std::cout <<
SIMTIME <<
" rs=" <<
getID() <<
" veh=" << info <<
" other dwSignal=" << dw->foundSignal() <<
" dwRoute=" <<
toString(dw->getRoute()) <<
"\n";
523#ifdef DEBUG_SELECT_DRIVEWAY
524 std::cout <<
SIMTIME <<
" rs=" <<
getID() <<
" veh=" << info <<
" new dwSignal=" << dw->foundSignal() <<
" dwRoute=" <<
toString(dw->
getRoute()) <<
"\n";
526 myDriveways.push_back(dw);
527 return *myDriveways.back();
537 && (myLastRerouteVehicle != veh
541 myLastRerouteVehicle = veh;
542 myLastRerouteTime = now;
547 std::cout <<
SIMTIME <<
" reroute veh=" << veh->
getID() <<
" rs=" <<
getID() <<
" occupied=" <<
toString(occupied) <<
"\n";
555 std::cout <<
" rerouting successful\n";
594 driveway.
reserve(closest, occupied);
635std::vector<const MSDriveWay*>
649std::vector<const MSDriveWay*>
659 if (dw->getNumericalID() == numericalID) {
674 return myLinkInfos[tlIndex].getDriveWay(first, end);
678const std::vector<MSDriveWay*>
691 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
704 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
717 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
730 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
743 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
756 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
766 if (key ==
"moving-block") {
#define DEBUG_HELPER(obj)
std::vector< const MSEdge * > ConstMSEdgeVector
std::vector< MSEdge * > MSEdgeVector
#define DEBUG_COND_LINKINFO
ConstMSEdgeVector::const_iterator MSRouteIterator
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
@ SUMO_ATTR_TLLINKINDEX
link: the index of the link within the traffic light
#define UNUSED_PARAMETER(x)
#define SUMO_MAX_CONNECTIONS
the maximum number of connections across an intersection
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
SUMOTime getStartupDelay() const
Get the vehicle type's startupDelay.
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
void setVehicle(const std::string &vehID)
static const MSDriveWay * getDepartureDriveway(const SUMOVehicle *veh)
const std::vector< const MSEdge * > & getRoute() const
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
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.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
bool isNormal() const
return whether this edge is an internal edge
const MSJunction * getToJunction() const
double getLength() const
return the length of the edge
static SUMOTime gTimeToTeleportRSDeadlock
SumoXMLNodeType getType() const
return the type of this Junction
Representation of a lane in the micro simulation.
MSJunction * getJunction() const
int getTLIndex() const
Returns the TLS index.
const MSLane * getLaneBefore() const
return the internalLaneBefore if it exists and the laneBefore otherwise
ApproachingVehicleInformation getApproaching(const SUMOVehicle *veh) const
std::pair< const SUMOVehicle *const, const ApproachingVehicleInformation > getClosest() const
get the closest vehicle approaching this link
MSLane * getViaLaneOrLane() const
return the via lane if it exists and the lane otherwise
const MSTrafficLightLogic * getTLLogic() const
Returns the TLS index.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
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()
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 ¶meters)
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 VehicleVector myBlockingVehicles
bool constraintsAllow(const SUMOVehicle *veh, bool storeWaitRelation=false) const
whether the given vehicle is free to drive
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
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.
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const MSEdgeVector &prohibited=MSEdgeVector())
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.
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.
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.
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
void reroute(SUMOVehicle *veh, const MSEdgeVector &occupied)
try rerouting vehicle if reservation failed
MSDriveWay & getDriveWay(const SUMOVehicle *)
retrieve an existing Driveway or construct a new driveway based on the vehicles route
void reset()
init LinkInfo
LinkInfo(MSLink *link)
constructor
std::vector< MSDriveWay * > myDriveways
all driveways immediately following this link
std::string getID() const
return id for this railsignal-link