88 }
else if (forced &&
myTYellow < tyellow) {
98 std::vector<double> ret;
99 for (std::vector<PhaseDef>::const_iterator i =
myPhases.begin(); i !=
myPhases.end(); i++) {
100 ret.push_back((
double)(*i).myTime);
104 for (std::vector<PhaseDef>::const_iterator i =
myPhases.begin(); i !=
myPhases.end(); i++) {
107 if (time > cycleDuration) {
108 time = time - cycleDuration;
110 ret.push_back((
double) time);
127 for (std::vector<PhaseDef>::const_reverse_iterator i =
myPhases.rbegin(); i !=
myPhases.rend(); i++) {
129 if (time >= nextTime) {
141 return has_red_now && had_green;
148 if ((*i).getFrom() == from && (*i).getTo() == to) {
167 if ((*i).getFrom() == from) {
179 if ((*i).getFrom() == which) {
182 for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
185 throw ProcessError(
"Could not replace edge '" + which->
getID() +
"' by '" + (*j)->getID() +
"'.\nUndefined...");
187 newConns.push_back(curr);
193 copy(newConns.begin(), newConns.end(),
201 if ((*i).getTo() == to) {
213 if ((*i).getTo() == which) {
216 for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
219 throw ProcessError(
"Could not replace edge '" + which->
getID() +
"' by '" + (*j)->getID() +
"'.\nUndefined...");
221 newConns.push_back(curr);
227 copy(newConns.begin(), newConns.end(),
236 if ((*i).getTo() == removed
238 ((*i).getToLane() == removedLane
240 (*i).getToLane() == -1)) {
241 (*i).replaceTo(removed, removedLane, by, byLane);
243 }
else if ((*i).getTo() == removed && removedLane == -1) {
244 (*i).replaceTo(removed, by);
247 if ((*i).getFrom() == removed
249 ((*i).getFromLane() == removedLane
251 (*i).getFromLane() == -1)) {
252 (*i).replaceFrom(removed, removedLane, by, byLane);
254 }
else if ((*i).getFrom() == removed && removedLane == -1) {
255 (*i).replaceFrom(removed, by);
293 NBLoadedTLDef::SignalGroupCont::const_iterator i;
295 std::set<double> tmpSwitchTimes;
306 for (std::vector<double>::const_iterator k = gtimes.begin(); k != gtimes.end(); k++) {
307 tmpSwitchTimes.insert(*k);
310 std::vector<double> switchTimes;
311 copy(tmpSwitchTimes.begin(), tmpSwitchTimes.end(), back_inserter(switchTimes));
312 sort(switchTimes.begin(), switchTimes.end());
317 noSignals += (*i).second->getLinkNo();
321 for (std::vector<double>::iterator l = switchTimes.begin(); l != switchTimes.end(); l++) {
324 if (l != switchTimes.end() - 1) {
326 duration = (int)((*(l + 1)) - (*l));
344 const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = logic->
getPhases();
345 for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
346 const std::string state = (*it).state;
358 && (state[i2] ==
'G' || state[i2] ==
'g')
397 bool mayDrive = group->
mayDrive(time);
406 for (
int j = 0; j < linkNo; j++) {
421 for (
int j = 0; j < linkNo; j++) {
426 if (state[pos] ==
'g') {
429 if (state[pos] ==
'y') {
443 const std::string& state,
446 if (state[strmpos] !=
'g' && state[strmpos] !=
'G') {
457 for (
int j = 0; j < linkNo; j++) {
468 if (state[pos] ==
'g' || state[pos] ==
'G') {
493 SignalGroupCont::const_iterator m;
497 for (
int j = 0; j < linkNo; j++) {
515 for (
int j = 0; j < noLanes; j++) {
517 for (std::vector<NBEdge::Connection>::iterator k = elv.begin(); k != elv.end(); k++) {
531 for (
int j = 0; j < linkNo; j++) {
537 if (tst.getFrom()->mayBeTLSControlled(tst.getFromLane(), tst.getTo(), tst.getToLane())) {
541 && tst.getFrom() == c.
getFrom() && tst.getTo() == c.
getTo()
542 && (tst.getFromLane() < 0 || tst.getFromLane() == c.
getFromLane())
543 && (tst.getToLane() < 0 || tst.getToLane() == c.
getToLane())) {
561 if ((*i).second->containsConnection(from, to)) {
594 for (NBConnectionVector::const_iterator i = connections.begin(); i != connections.end(); i++) {
651 group->
remap(removed, removedLane, by, byLane);
660 throw ProcessError(
"myNeedsContRelation was not propperly initialized\n");
SignalGroup * findGroup(NBEdge *from, NBEdge *to) const
Returns the signal group which is responsible for the given connection.
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
A structure which describes a connection between edges or lanes.
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
int toLane
The lane the connections yields in.
TrafficLightType myType
The algorithm type for the traffic light.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled ...
void initNeedsContRelation() const
NBEdge * toEdge
The edge the connections yields in.
~SignalGroup()
Destructor.
A single signal group, may control several connections.
SignalGroup(const std::string &id)
Constructor.
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
std::vector< Connection > getConnectionsFromLane(int lane) const
Returns connections from a given lane.
A SUMO-compliant built logic for a traffic light.
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.
void sortPhases()
Sorts the phases.
bool replaceTo(NBEdge *which, NBEdge *by)
replaces the to-edge by the one given
std::vector< double > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
int getFromLane() const
returns the from-lane
void collectNodes()
Collects the nodes participating in this traffic light.
Used for sorting the cells by the begin time they describe.
bool containsOutgoing(NBEdge *to) const
Returns whether this signal controls a connection where the given edge is the destination.
The base class for traffic light logic definitions.
std::string buildPhaseState(int time) const
Builds the phase for a given time.
TLColor
An enumeration of possible tl-signal states.
SUMOTime myOffset
The offset in the program.
Definition of a single, loaded phase.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
#define WRITE_WARNING(msg)
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)
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
const std::string & getID() const
Returns the id.
virtual void collectEdges()
Build the list of participating edges.
static const int InvalidTlIndex
bool replaceFrom(NBEdge *which, NBEdge *by)
replaces the from-edge by the one given
int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
SignalGroupCont mySignalGroups
Controlled signal groups.
void setCycleDuration(int cycleDur)
Sets the duration of a cycle.
int getNumLanes() const
Returns the number of lanes.
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
std::vector< PhaseDef > myPhases
The phases of this signal.
Storage for edges, including some functionality operating on multiple edges.
bool containsConnection(NBEdge *from, NBEdge *to) const
Returns whether the given connection is controlled by this signal.
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
void collectLinks()
Collects the links participating in this traffic light If a link could not be found.
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.
void addConnection(const NBConnection &c)
Inserts a controlled connection.
Base class for objects which have an id.
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
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
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
NBNode * getToNode() const
Returns the destination node of the edge.
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
void patchTYellow(int tyellow, bool forced)
Sets the yellow time.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
SUMOTime myTRedYellow
The times of redyellow and yellow.
const NBConnection & getConnection(int pos) const
Returns the connection at the given index.
void addSignalGroup(const std::string &id)
Adds a signal group.
bool myNeedsContRelationReady
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Sorts phases by their begin time.
int getToLane() const
returns the to-lane
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
NBEdge * getTo() const
returns the to-edge (end of the connection)
int myCycleDuration
The duration of a single cycle.
NeedsContRelation myNeedsContRelation
Represents a single node (junction) during network building.
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
NBConnectionVector myConnections
Connections controlled by this signal.
data structure for caching needsCont information
~NBLoadedTLDef()
Destructor.
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
void clear()
Clears information whether an error occured previously.
const NBEdgeCont * myEdgeCont
NBConnectionVector myControlledLinks
The list of controlled links.
bool mustBrake(const NBConnection &possProhibited, const std::string &state, int strmpos) const
Returns the information whether a connection must brake, given a phase.
NBNode * getFromNode() const
Returns the origin node of the edge.