44 #define MAX_BLOCK_LENGTH 20000 45 #define MAX_SIGNAL_WARNINGS 10 48 #define DEBUG_COND (getID() == "disabled") 55 class ApproachingVehicleInformation;
60 const std::string&
id,
const std::string& programID,
61 const std::map<std::string, std::string>& parameters) :
70 LinkVectorVector::iterator i2;
75 LinkVector::const_iterator i;
76 for (i = links.begin(); i != links.end(); i++) {
83 std::vector<const MSLane*> afferentBlock;
84 bool noRailSignal =
true;
87 afferentBlock.push_back(approachingLane);
88 const MSLane* currentLane = approachingLane;
90 double blockLength = approachingLane->
getLength();
91 while (noRailSignal) {
92 std::vector<MSLane::IncomingLaneInfo> incomingLanes = currentLane->
getIncomingLanes();
94 for (
auto it = incomingLanes.begin(); it != incomingLanes.end();) {
96 it = incomingLanes.erase(it);
102 if (!incomingLanes.empty()) {
103 precedentLane = incomingLanes.front().lane;
105 precedentLane =
nullptr;
107 if (precedentLane ==
nullptr) {
108 noRailSignal =
false;
111 "' exceeds maximum length (stopped searching at lane '" + precedentLane->
getID() +
"' after " +
toString(blockLength) +
"m).");
112 noRailSignal =
false;
116 noRailSignal =
false;
118 afferentBlock.push_back(precedentLane);
119 blockLength += precedentLane->
getLength();
120 currentLane = precedentLane;
129 std::vector<const MSLane*> succeedingBlock;
130 succeedingBlock.push_back(toLane);
131 currentLane = toLane;
132 bool noRailSignalLocal =
true;
133 double blockLength = toLane->
getLength();
134 while (noRailSignalLocal) {
136 std::vector<MSLink*> outGoingLinks = currentLane->
getLinkCont();
137 std::vector<MSLink*>::const_iterator j;
138 for (j = outGoingLinks.begin(); j != outGoingLinks.end(); j++) {
141 noRailSignalLocal =
false;
145 if (noRailSignalLocal) {
147 std::vector<const MSLane*> outGoingLanes;
151 outGoingLanes.push_back(it.first);
154 if (outGoingLanes.size() == 0) {
155 noRailSignalLocal =
false;
158 "' exceeds maximum length (stopped searching at lane '" + currentLane->
getID() +
"' after " +
toString(blockLength) +
"m).");
159 noRailSignalLocal =
false;
161 if (outGoingLanes.size() > 1) {
163 WRITE_WARNING(
"Rail lane '" + currentLane->
getID() +
"' has more than one outgoing lane but does not have a rail signal at its end");
169 const MSLane* nextLane = outGoingLanes.front();
170 succeedingBlock.push_back(nextLane);
172 currentLane = nextLane;
180 #ifdef DEBUG_SUCCEEDINGBLOCKS 182 std::cout <<
"railSignal=" <<
getID() <<
" mySucceedingBlocks:\n";
184 std::cout <<
" toLane=" << item.first->getID() <<
" succ=" <<
toString(item.second) <<
"\n";
191 std::queue<const MSLane*> revLanes;
192 for (std::vector<const MSLane*>::iterator laneIt = it->second.begin(); laneIt != it->second.end(); laneIt++) {
193 const MSLane* lane = *laneIt;
196 if (reverseEdge !=
nullptr) {
198 revLanes.push(revLane);
200 if (pred !=
nullptr) {
207 while (!revLanes.empty()) {
208 const MSLane* revLane = revLanes.front();
209 it->second.push_back(revLane);
240 std::string state(
myLinks.size(),
'G');
243 bool succeedingBlockOccupied =
false;
245 for (
const MSLane* l : block) {
247 succeedingBlockOccupied =
true;
251 if (!succeedingBlockOccupied) {
255 for (
auto apprIt : it->second->getApproaching()) {
258 succeedingBlockOccupied =
true;
274 if (succeedingBlockOccupied) {
275 std::vector<MSLink*>::const_iterator k;
281 bool hasOccupiedBlock =
false;
282 std::vector<MSLink*>::const_iterator k;
284 std::vector<const MSLane*>::const_iterator l;
286 if (!(*l)->isEmpty()) {
287 hasOccupiedBlock =
true;
289 std::vector<MSLink*>::const_iterator m;
298 if (hasOccupiedBlock) {
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Builds detectors for microsim.
MSEdge & getEdge() const
Returns the lane's edge.
MSLane * getLane() const
Returns the connected lane.
void updateCurrentPhase()
updates the current phase of the signal
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
The base class for an intersection.
const MSLane * getLaneBefore() const
return the internalLaneBefore if it exists and the laneBefore otherwise
std::map< MSLane *, std::vector< MSLink * > > myLinksToLane
A map that maps an outgoing lane from the junction to its set of links that lead to this lane...
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
int getIndexFromOffset(SUMOTime offset) const
Returns the step (the phasenumber) of a given position of the cycle.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
#define SUMO_MAX_CONNECTIONS
the maximum number of connections across an intersection
double getLength() const
Returns the lane's length.
std::map< const MSLane *, const MSLink * > mySucceedingBlocksIncommingLinks
A map of lanes to links of approaching vehicles of succeeding blocks.
MSLink * getLinkTo(const MSLane *) const
returns the link to the given lane or 0, if it is not connected
MSLane * getCanonicalPredecessorLane() const
const std::string & getID() const
Returns the id.
const MSJunction * getToJunction() const
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
const MSEdge * getBidiEdge() const
return opposite superposable/congruent edge, if it exist and 0 else
#define WRITE_WARNING(msg)
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index...
std::map< MSLink *, int > myLinkIndices
A map that maps a link to its link index.
A class that stores and controls tls and switching of their programs.
A road/street connecting two junctions.
void setState(const std::string &_state)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::vector< MSLane * > myOutgoingLanes
The set of lanes going out from the junction.
SUMOTime myDefaultCycleTime
The cycle time (without changes)
void init(NLDetectorBuilder &nb)
Initialises the rail signal with information about adjacent rail signals.
classes which drive on tracks
Phases myPhases
The list of phases this logic uses.
const Phases & getPhases() const
Returns the phases of this tls program.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
std::map< MSLane *, std::vector< const MSLane * > > mySucceedingBlocks
A map that maps an outgoing lane from the junction to its vector of lanes leading to the next signal...
int getPhaseNumber() const
Returns the number of phases.
#define MAX_SIGNAL_WARNINGS
const std::vector< std::pair< const MSLane *, const MSEdge * > > getOutgoingViaLanes() const
get the list of outgoing lanes
SUMOTime trySwitch()
Switches to the next phase.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index...
MSRailSignal(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const std::map< std::string, std::string > ¶meters)
Constructor.
void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const
Returns the index of the logic at the given simulation step.
std::string getAppropriateState()
returns the state of the signal that actually required
The parent class for traffic light logics.
MSPhaseDefinition myCurrentPhase
The current phase.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
std::map< MSLink *, std::vector< const MSLane * > > myAfferentBlocks
A map that maps a link from the junction to its vector of lanes leading from a previous signal to thi...
SUMOTime getOffsetFromIndex(int index) const
Returns the position (start of a phase during a cycle) from of a given step.
The definition of a single phase of a tls logic.
Representation of a lane in the micro simulation.
int getCurrentPhaseIndex() const
Returns the current index within the program.
SumoXMLNodeType getType() const
return the type of this Junction
~MSRailSignal()
Destructor.