 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
50 myReconstructAddedConnections(false),
51 myReconstructRemovedConnections(false),
52 myPhasesLoaded(false) {
61 myOriginalNodes(def->getNodes().begin(), def->getNodes().end()),
62 myReconstructAddedConnections(false),
63 myReconstructRemovedConnections(false),
64 myPhasesLoaded(false) {
70 if (sumoDef !=
nullptr) {
105 NBConnection conn(from, fromLane, to, toLane, linkIndex, linkIndex2);
130 (*i)->removeTrafficLight(&dummy);
165 (*it).replaceFrom(removed, removedLane, by, byLane);
166 (*it).replaceTo(removed, removedLane, by, byLane);
206 if (it->getFrom() == conn.
getFrom() &&
207 it->getTo() == conn.
getTo() &&
245 const EdgeVector& incoming = (*i)->getIncomingEdges();
246 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
247 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
248 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
255 EdgeVector::iterator k = std::find(myOutgoing.begin(), myOutgoing.end(), edge);
256 if (k != myOutgoing.end()) {
258 bool controlled =
false;
260 if ((*it).getFrom() == edge) {
269 (*j)->setInsideTLS();
299 (*it).shiftLaneIndex(edge, offset, threshold);
314 const int numNormalLinks = noLinksAll;
315 int oldCrossings = 0;
317 bool customIndex =
false;
318 std::vector<NBNode::Crossing*> crossings;
320 const std::vector<NBNode::Crossing*>& c = (*i)->getCrossings();
322 customIndex |= (*i)->setCrossingTLIndices(
getID(), noLinksAll);
323 copy(c.begin(), c.end(), std::back_inserter(crossings));
324 noLinksAll += (int)c.size();
325 oldCrossings += (*i)->numCrossingsFromSumoNet();
327 if ((
int)crossings.size() != oldCrossings) {
330 if (phases.size() > 0 && (
331 (int)(phases.front().state.size()) < noLinksAll ||
332 ((
int)(phases.front().state.size()) > noLinksAll && !customIndex))) {
336 std::vector<int> fromLanes(size, 0);
338 const std::string crossingDefaultState(crossings.size(),
'r');
344 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
345 const std::string state = it->state.substr(0, numNormalLinks) + crossingDefaultState;
352 }
else if (phases.size() == 0) {
361 assert(fromEdges.size() > 0);
362 assert(fromEdges.size() == toEdges.size());
363 const int size = (int)fromEdges.size();
370 "' with " +
toString(size) +
" links.");
386 const std::vector<NBTrafficLightLogic::PhaseDefinition> phases =
myTLLogic->
getPhases();
387 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
388 const std::string state = (*it).state;
400 && (state[i2] ==
'G' || state[i2] ==
'g')
406 if (forbidden || rightTurnConflict) {
445 #ifdef DEBUG_RECONSTRUCTION
449 std::cout <<
" " << *it <<
"\n";
466 (*i)->removeTrafficLight(&dummy);
470 if (newLogic !=
nullptr) {
506 bool exclusive =
true;
508 if (other != con && other.
getTLIndex() == removed) {
516 if (other.getTLIndex() > removed) {
517 other.setTLIndex(other.getTLIndex() - 1);
523 if (c->customTLIndex > removed) {
529 const std::vector<NBTrafficLightLogic::PhaseDefinition> phases =
myTLLogic->
getPhases();
531 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
532 std::string newState = it->state;
533 newState.erase(newState.begin() + removed);
534 newLogic->
addStep(it->duration, newState);
544 #ifdef DEBUG_RECONSTRUCTION
545 if (debugPrintModified) {
546 std::cout <<
" newLinks:\n";
548 std::cout <<
" " << *it <<
"\n";
559 maxIndex =
MAX2(maxIndex, c.getTLIndex());
563 maxIndex =
MAX2(maxIndex, c->tlLinkIndex);
564 maxIndex =
MAX2(maxIndex, c->tlLinkIndex2);
619 std::map<int, int> indexUsage;
621 indexUsage[c.getTLIndex()]++;
625 indexUsage[c->tlLinkIndex]++;
626 indexUsage[c->tlLinkIndex2]++;
629 for (
auto it : indexUsage) {
630 if (it.first >= 0 && it.second > 1) {
639 bool hasMinMaxDur =
false;
642 std::cout <<
" phase=" << phase.state <<
" maxDur=" << phase.maxDur <<
"\n";
649 std::set<int> yellowIndices;
651 for (
int i = 0; i < (int)phase.state.size(); i++) {
652 if (phase.state[i] ==
'y' || phase.state[i] ==
'Y') {
653 yellowIndices.insert(i);
658 bool needMinMaxDur =
false;
660 std::set<int> greenIndices;
661 if (phase.state.find_first_of(
"yY") != std::string::npos) {
664 for (
int i = 0; i < (int)phase.state.size(); i++) {
665 if (yellowIndices.count(i) != 0 && phase.state[i] ==
'G') {
666 needMinMaxDur =
true;
667 greenIndices.insert(i);
673 if (greenIndices.count(c.getTLIndex()) != 0) {
674 maxSpeed =
MAX2(maxSpeed, c.getFrom()->getLaneSpeed(c.getFromLane()));
678 const double minDurBySpeed = maxSpeed * 3.6 / 6 - 3.3;
void reconstructLogic()
adapt to removal or addition of connections
data structure for caching needsCont information
#define UNUSED_PARAMETER(x)
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
#define WRITE_WARNING(msg)
NBTrafficLightLogic * myTLLogic
phases are added directly to myTLLogic which is then returned in myCompute()
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled
void collectEdgeVectors(EdgeVector &fromEdges, EdgeVector &toEdges, std::vector< int > &fromLanes) const
Collects the edges for each tlIndex.
void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
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
bool hasValidIndices() const
return whether all tls link indices are valid
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
~NBLoadedSUMOTLDef()
Destructor.
NBConnectionVector myControlledLinks
The list of controlled links.
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
void closeBuilding(bool checkVarDurations=true)
closes the building process
NBEdge * getFrom() const
returns the from-edge (start of the connection)
void guessMinMaxDuration()
heuristically add minDur and maxDur when switching from tlType fixed to actuated
SUMOTime myOffset
The offset in the program.
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
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
static const int InvalidTlIndex
NBEdge * getTo() const
returns the to-edge (end of the connection)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void addPhase(SUMOTime duration, const std::string &state, SUMOTime minDur, SUMOTime maxDur, const std::vector< int > &next, const std::string &name)
Adds a phase to the logic the new phase is inserted at the end of the list of already added phases.
A traffic light logics which must be computed (only nodes/edges are given)
class for identifying connections
static OptionsCont & getOptions()
Retrieves the options.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
static const std::string DummyID
id for temporary definitions
SUMOTime getOffset()
Returns the offset.
TrafficLightType myType
The algorithm type for the traffic light.
int getMaxIndex()
return the highest known tls link index used by any controlled connection or crossing
void initNeedsContRelation() const
TrafficLightType getType() const
get the algorithm type (static etc..)
void setOffset(SUMOTime offset)
Sets the offset of this tls.
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, int linkIndex2, bool reconstruct=true)
Adds a connection and immediately informs the edges.
void registerModifications(bool addedConnections, bool removedConnections)
register changes that necessitate recomputation
virtual void collectEdges()
Build the list of participating edges.
void setProgramID(const std::string &programID)
Sets the programID.
The representation of a single edge during network building.
void addStep(SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", int index=-1)
Adds a phase to the logic.
virtual int getMaxIndex()=0
Returns the maximum index controlled by this traffic light and assigned to a connection.
RightOnRedConflicts myRightOnRedConflicts
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
std::set< NBNode * > myOriginalNodes
The original nodes for which the loaded logic is valid.
NBNode * getToNode() const
Returns the destination node of the edge.
void updateParameters(const std::map< std::string, std::string > &mapArg)
Adds or updates all given parameters from the map.
TrafficLightType getType() const
get the algorithm type (static etc..)
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
static const SUMOTime UNSPECIFIED_DURATION
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light
void collectLinks()
Collects the links participating in this traffic light (only if not previously loaded)
const NBConnectionVector & getControlledLinks() const
returns the controlled links (depends on previous call to collectLinks)
bool myReconstructAddedConnections
whether the logic must be reconstructed
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
bool myRightOnRedConflictsReady
int getNumLinks()
Returns the number of participating links.
int getToLane() const
returns the to-lane
int getNumLanes() const
Returns the number of lanes.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
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...
NeedsContRelation myNeedsContRelation
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
std::set< NBEdge * > myShifted
set of edges with shifted lane indices (to avoid shifting twice)
bool myNeedsContRelationReady
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
int getMaxValidIndex()
Returns the maximum index controlled by this traffic light.
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
bool myReconstructRemovedConnections
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.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
void setType(TrafficLightType type)
set the algorithm type (static etc..)
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
NBLoadedSUMOTLDef(const std::string &id, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
const std::string & getProgramID() const
Returns the ProgramID.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
void patchIfCrossingsAdded()
repair the plan if controlled nodes received pedestrian crossings
static bool runningNetedit()
whether netbuilding takes place in the context of NETEDIT
A SUMO-compliant built logic for a traffic light.
Represents a single node (junction) during network building.
EdgeVector myIncomingEdges
The list of incoming edges.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
bool hasConnectionTo(NBEdge *destEdge, int destLane, int fromLane=-1) const
Retrieves info about a connection to a certain lane of a certain edge.
A definition of a pedestrian crossing.
void collectAllLinks()
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
const std::string & getID() const
Returns the id.
NBNode * getFromNode() const
Returns the origin node of the edge.
int getFromLane() const
returns the from-lane
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 joinLogic(NBTrafficLightDefinition *def)
join nodes and states from the given logic (append red state)
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
The base class for traffic light logic definitions.
void collectEdges()
Build the list of participating edges.
void setID(const std::string &newID)
resets the id
bool usingSignalGroups() const
whether this definition uses signal group (multiple connections with the same link index)
void setPhaseMaxDuration(int phaseIndex, SUMOTime duration)
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
void shiftTLConnectionLaneIndex(NBEdge *edge, int offset, int threshold=-1)
patches signal plans by modifying lane indices with the given offset, only indices with a value above...
const std::string & getID() const
A loaded (complete) traffic light logic.