57 myReconstructAddedConnections(false),
58 myReconstructRemovedConnections(false),
59 myPhasesLoaded(false) {
102 NBConnection conn(from, fromLane, to, toLane, linkIndex);
125 (*i)->removeTrafficLight(&dummy);
160 (*it).replaceFrom(removed, removedLane, by, byLane);
161 (*it).replaceTo(removed, removedLane, by, byLane);
196 if (it->getFrom() == conn.
getFrom() &&
197 it->getTo() == conn.
getTo() &&
235 const EdgeVector& incoming = (*i)->getIncomingEdges();
236 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
237 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
238 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
245 EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge);
246 if (k != myOutgoing.end()) {
248 bool controlled =
false;
250 if ((*it).getFrom() == edge) {
259 (*j)->setIsInnerEdge();
289 (*it).shiftLaneIndex(edge, offset);
304 const int numNormalLinks = noLinksAll;
305 int oldCrossings = 0;
307 std::vector<NBNode::Crossing*> crossings;
309 const std::vector<NBNode::Crossing*>& c = (*i)->getCrossings();
311 (*i)->setCrossingTLIndices(
getID(), noLinksAll);
312 copy(c.begin(), c.end(), std::back_inserter(crossings));
313 noLinksAll += (int)c.size();
314 oldCrossings += (*i)->numCrossingsFromSumoNet();
316 if ((
int)crossings.size() != oldCrossings) {
318 if (phases.size() > 0) {
322 std::vector<int> fromLanes(size, 0);
324 const std::string crossingDefaultState(crossings.size(),
'r');
330 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
331 if ((*it).state.find_first_of(
"yY") != std::string::npos) {
332 brakingTime =
MAX2(brakingTime, it->duration);
334 const std::string state = it->state.substr(0, numNormalLinks) + crossingDefaultState;
350 assert(fromEdges.size() > 0);
351 assert(fromEdges.size() == toEdges.size());
352 const int size = (int)fromEdges.size();
359 "' with " +
toString(size) +
" links.");
375 const std::vector<NBTrafficLightLogic::PhaseDefinition> phases =
myTLLogic->
getPhases();
376 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
377 const std::string state = (*it).state;
389 && (state[i2] ==
'G' || state[i2] ==
'g')
395 if (forbidden || rightTurnConflict) {
433 #ifdef DEBUG_RECONSTRUCTION 437 std::cout <<
" " << *it <<
"\n";
453 (*i)->removeTrafficLight(&dummy);
467 if (myReconstructRemovedConnections) {
468 myReconstructRemovedConnections =
false;
492 const std::vector<NBTrafficLightLogic::PhaseDefinition> phases =
myTLLogic->
getPhases();
494 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
495 std::string newState = it->state;
496 newState.erase(newState.begin() + removed);
497 newLogic->
addStep(it->duration, newState);
506 #ifdef DEBUG_RECONSTRUCTION 507 if (debugPrintModified) {
508 std::cout <<
" newLinks:\n";
510 std::cout <<
" " << *it <<
"\n";
void addPhase(SUMOTime duration, const std::string &state, SUMOTime minDur, SUMOTime maxDur)
Adds a phase to the logic the new phase is inserted at the end of the list of already added phases...
void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
TrafficLightType getType() const
get the algorithm type (static etc..)
TrafficLightType myType
The algorithm type for the traffic light.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
NBLoadedSUMOTLDef(const std::string &id, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled ...
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
void collectEdges()
Build the list of participating edges.
void collectAllLinks()
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
static const std::string DummyID
id for temporary definitions
void setOffset(SUMOTime offset)
Sets the offset of this tls.
void reconstructLogic()
adapt to removal or addition of connections
int getNumLinks()
Returns the number of participating links.
RightOnRedConflicts myRightOnRedConflicts
A SUMO-compliant built logic for a traffic light.
TrafficLightType getType() const
get the algorithm type (static etc..)
bool myReconstructAddedConnections
whether the logic must be reconstructed
void registerModifications(bool addedConnections, bool removedConnections)
register changes that necessitate recomputation
EdgeVector myIncomingEdges
The list of incoming edges.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getProgramID() const
Returns the ProgramID.
The representation of a single edge during network building.
class for identifying connections
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
int getFromLane() const
returns the from-lane
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
The base class for traffic light logic definitions.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
SUMOTime myOffset
The offset in the program.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
#define UNUSED_PARAMETER(x)
#define WRITE_WARNING(msg)
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
static OptionsCont & getOptions()
Retrieves the options.
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane, bool lefthand=false)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
void setTLIndex(int tlIndex)
SUMOTime getOffset()
Returns the offset.
void setType(TrafficLightType type)
set the algorithm type (static etc..)
const std::string & getID() const
Returns the id.
static std::string addPedestrianPhases(NBTrafficLightLogic *logic, SUMOTime greenTime, SUMOTime minDur, SUMOTime maxDur, std::string state, const std::vector< NBNode::Crossing * > &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
add 1 or 2 phases depending on the presence of pedestrian crossings
virtual void collectEdges()
Build the list of participating edges.
static const int InvalidTlIndex
bool hasConnectionTo(NBEdge *destEdge, int destLane, int fromLane=-1) const
Retrieves info about a connection to a certain lane of a certain edge.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
static void addPedestrianScramble(NBTrafficLightLogic *logic, int noLinksAll, SUMOTime greenTime, SUMOTime yellowTime, const std::vector< NBNode::Crossing * > &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
add an additional pedestrian phase if there are crossings that did not get green yet ...
const NBConnectionVector & getControlledLinks() const
returns the controlled links (depends on previous call to collectLinks)
void patchIfCrossingsAdded()
repair the plan if controlled nodes received pedestrian crossings
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, bool reconstruct=true)
Adds a connection and immediately informs the edges.
std::set< NBNode * > myOriginalNodes
The original nodes for which the loaded logic is valid.
void initNeedsContRelation() const
int getNumLanes() const
Returns the number of lanes.
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
void setProgramID(const std::string &programID)
Sets the programID.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority, bool sameNodeOnly=false) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
void closeBuilding(bool checkVarDurations=true)
closes the building process
SUMOTime getOffset() const
Returns the offset of first switch.
std::set< NBEdge * > myShifted
set of edges with shifted lane indices (to avoid shifting twice)
bool myRightOnRedConflictsReady
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
NBNode * getToNode() const
Returns the destination node of the edge.
void setID(const std::string &newID)
resets the id
bool myNeedsContRelationReady
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
int getToLane() const
returns the to-lane
void collectLinks()
Collects the links participating in this traffic light (only if not previously loaded) ...
NBEdge * getTo() const
returns the to-edge (end of the connection)
NeedsContRelation myNeedsContRelation
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
bool myReconstructRemovedConnections
~NBLoadedSUMOTLDef()
Destructor.
data structure for caching needsCont information
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
void collectEdgeVectors(EdgeVector &fromEdges, EdgeVector &toEdges, std::vector< int > &fromLanes) const
Collects the edges for each tlIndex.
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
A traffic light logics which must be computed (only nodes/edges are given)
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
NBConnectionVector myControlledLinks
The list of controlled links.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
void shiftTLConnectionLaneIndex(NBEdge *edge, int offset)
patches signal plans by modifying lane indices
NBTrafficLightLogic * myTLLogic
phases are added directly to myTLLogic which is then returned in myCompute()
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
NBNode * getFromNode() const
Returns the origin node of the edge.