52 myConnections.push_back(c);
58 myPhases.push_back(
PhaseDef(time, color));
64 myTRedYellow = tRedYellow;
71 std::sort(myPhases.begin(), myPhases.end(), [](
const PhaseDef & p1,
const PhaseDef & p2) {
72 return p1.myTime < p2.myTime;
82 }
else if (forced && myTYellow < tyellow) {
92 std::vector<SUMOTime> ret;
94 ret.push_back(p.myTime);
100 ret.push_back((p.myTime + myTYellow) % cycleDuration);
110 return (
int) myConnections.size();
116 assert(myPhases.size() != 0);
117 for (std::vector<PhaseDef>::const_reverse_iterator i = myPhases.rbegin(); i != myPhases.rend(); i++) {
119 if (time >= nextTime) {
129 bool has_red_now = !mayDrive(time);
130 bool had_green = mayDrive(time - myTYellow);
131 return has_red_now && had_green;
137 assert(pos < (
int)myConnections.size());
138 return myConnections[pos];
144 for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
145 if ((*i).getFrom() == from) {
156 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end();) {
157 if ((*i).getFrom() == which) {
159 i = myConnections.erase(i);
160 for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
163 throw ProcessError(
"Could not replace edge '" + which->
getID() +
"' by '" + (*j)->getID() +
"'.\nUndefined...");
165 newConns.push_back(curr);
171 copy(newConns.begin(), newConns.end(),
172 back_inserter(myConnections));
178 for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
179 if ((*i).getTo() == to) {
190 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end();) {
191 if ((*i).getTo() == which) {
193 i = myConnections.erase(i);
194 for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
197 throw ProcessError(
"Could not replace edge '" + which->
getID() +
"' by '" + (*j)->getID() +
"'.\nUndefined...");
199 newConns.push_back(curr);
205 copy(newConns.begin(), newConns.end(),
206 back_inserter(myConnections));
213 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end(); i++) {
214 if ((*i).getTo() == removed
216 ((*i).getToLane() == removedLane
218 (*i).getToLane() == -1)) {
219 (*i).replaceTo(removed, removedLane, by, byLane);
221 }
else if ((*i).getTo() == removed && removedLane == -1) {
222 (*i).replaceTo(removed, by);
225 if ((*i).getFrom() == removed
227 ((*i).getFromLane() == removedLane
229 (*i).getFromLane() == -1)) {
230 (*i).replaceFrom(removed, removedLane, by, byLane);
232 }
else if ((*i).getFrom() == removed && removedLane == -1) {
233 (*i).replaceFrom(removed, by);
272 std::set<SUMOTime> switchTimes;
284 switchTimes.insert(gtimes.begin(), gtimes.end());
291 for (
const SUMOTime l : switchTimes) {
307 const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = logic->
getPhases();
308 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
309 const std::string state = (*it).state;
321 && (state[i2] ==
'G' || state[i2] ==
'g')
360 bool mayDrive = group->
mayDrive(time);
369 for (
int j = 0; j < linkNo; j++) {
384 for (
int j = 0; j < linkNo; j++) {
389 if (state[pos] ==
'g') {
392 if (state[pos] ==
'y') {
406 const std::string& state,
409 if (state[strmpos] !=
'g' && state[strmpos] !=
'G') {
420 for (
int j = 0; j < linkNo; j++) {
431 if (state[pos] ==
'g' || state[pos] ==
'G') {
456 SignalGroupCont::const_iterator m;
460 for (
int j = 0; j < linkNo; j++) {
478 for (
int j = 0; j < noLanes; j++) {
480 for (std::vector<NBEdge::Connection>::iterator k = elv.begin(); k != elv.end(); k++) {
482 if (el.
toEdge !=
nullptr) {
494 for (
int j = 0; j < linkNo; j++) {
546 for (NBConnectionVector::const_iterator i = connections.begin(); i != connections.end(); i++) {
599 NBEdge* by,
int byLane,
bool incoming) {
603 group->
remap(removed, removedLane, by, byLane);
612 throw ProcessError(
TL(
"myNeedsContRelation was not properly initialized\n"));
621 if (logic !=
nullptr) {
#define WRITE_WARNINGF(...)
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool wasInformed() const
Returns the information whether any messages were added.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
virtual void clear(bool resetInformed=true)
Clears information whether an error occurred previously and print aggregated message summary.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
int getFromLane() const
returns the from-lane
bool replaceTo(NBEdge *which, NBEdge *by)
replaces the to-edge by the one given
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled
static const int InvalidTlIndex
bool replaceFrom(NBEdge *which, NBEdge *by)
replaces the from-edge by the one given
void setTLIndex(int tlIndex)
int getToLane() const
returns the to-lane
NBEdge * getTo() const
returns the to-edge (end of the connection)
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
Storage for edges, including some functionality operating on multiple edges.
The representation of a single edge during network building.
NBNode * getToNode() const
Returns the destination node of the edge.
const std::string & getID() const
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
int getNumLanes() const
Returns the number of lanes.
std::vector< Connection > getConnectionsFromLane(int lane, const NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition of a single, loaded phase.
A single signal group, may control several connections.
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
SignalGroup(const std::string &id)
Constructor.
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
void addConnection(const NBConnection &c)
Inserts a controlled connection.
std::vector< SUMOTime > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
void patchTYellow(SUMOTime tyellow, bool forced)
Sets the yellow time.
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.
const NBConnection & getConnection(int pos) const
Returns the connection at the given index.
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
void sortPhases()
Sorts the phases.
~SignalGroup()
Destructor.
bool containsOutgoing(NBEdge *to) const
Returns whether this signal controls a connection where the given edge is the destination.
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
void collectNodes()
Collects the nodes participating in this traffic light.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane, bool incoming)
Replaces a removed edge/lane.
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
std::string buildPhaseState(const SUMOTime time) const
Builds the phase for a given time.
~NBLoadedTLDef()
Destructor.
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
SUMOTime myCycleDuration
The duration of a single cycle.
const NBEdgeCont * myEdgeCont
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
void addSignalGroup(const std::string &id)
Adds a signal group.
void setCycleDuration(SUMOTime cycleDur)
Sets the duration of a cycle.
SignalGroupCont mySignalGroups
Controlled signal groups.
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
void collectLinks()
Collects the links participating in this traffic light.
bool mustBrake(const NBConnection &possProhibited, const std::string &state, int strmpos) const
Returns the information whether a connection must brake, given a phase.
void initNeedsContRelation() const
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurrences of the removed edge in incoming/outgoing edges of all definitions.
Used for sorting the cells by the begin time they describe.
Represents a single node (junction) during network building.
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
The base class for traffic light logic definitions.
const std::string & getProgramID() const
Returns the ProgramID.
TLColor
An enumeration of possible tl-signal states.
@ TLCOLOR_GREEN
Signal shows green.
@ TLCOLOR_RED
Signal shows red.
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
EdgeVector myIncomingEdges
The list of incoming edges.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
NBTrafficLightLogic * compute(const OptionsCont &oc)
Computes the traffic light logic.
TrafficLightType myType
The algorithm type for the traffic light.
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.
NBConnectionVector myControlledLinks
The list of controlled links.
static const std::string DefaultProgramID
bool mustBrake(const NBEdge *const from, const NBEdge *const to) const
Returns the information whether the described flow must let any other flow pass.
bool myNeedsContRelationReady
SUMOTime myOffset
The offset in the program.
NeedsContRelation myNeedsContRelation
virtual void collectEdges()
Build the list of participating edges.
A SUMO-compliant built logic for a traffic light.
void closeBuilding(bool checkVarDurations=true)
closes the building process
int getNumLinks()
Returns the number of participating links.
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
void addStep(const SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", const int index=-1)
Adds a phase to the logic (static)
Base class for objects which have an id.
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.
A structure which describes a connection between edges or lanes.
int toLane
The lane the connections yields in.
NBEdge * toEdge
The edge the connections yields in.
data structure for caching needsCont information