45 #ifdef CHECK_MEMORY_LEAKS
47 #endif // CHECK_MEMORY_LEAKS
64 myConnections.push_back(c);
70 myPhases.push_back(
PhaseDef(time, color));
76 myTRedYellow = tRedYellow;
92 }
else if (forced && myTYellow < tyellow) {
93 WRITE_WARNING(
"TYellow of signal group '" +
getID() +
"' was less than the computed one; patched (was:" + toString<SUMOTime>(myTYellow) +
", is:" + toString<int>(tyellow) +
")");
102 std::vector<SUMOReal> ret;
103 for (std::vector<PhaseDef>::const_iterator i = myPhases.begin(); i != myPhases.end(); i++) {
104 ret.push_back((
SUMOReal)(*i).myTime);
108 for (std::vector<PhaseDef>::const_iterator i = myPhases.begin(); i != myPhases.end(); i++) {
111 if (time > cycleDuration) {
112 time = time - cycleDuration;
124 return (
unsigned int) myConnections.size();
130 assert(myPhases.size() != 0);
131 for (std::vector<PhaseDef>::const_reverse_iterator i = myPhases.rbegin(); i != myPhases.rend(); i++) {
133 if (time >= nextTime) {
143 bool has_red_now = !mayDrive(time);
144 bool had_green = mayDrive(time - myTYellow);
145 return has_red_now && had_green;
151 for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
152 if ((*i).getFrom() == from && (*i).getTo() == to) {
163 assert(pos < myConnections.size());
164 return myConnections[pos];
170 for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
171 if ((*i).getFrom() == from) {
182 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end();) {
183 if ((*i).getFrom() == which) {
185 i = myConnections.erase(i);
186 for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
189 throw ProcessError(
"Could not replace edge '" + which->
getID() +
"' by '" + (*j)->getID() +
"'.\nUndefined...");
191 newConns.push_back(curr);
197 copy(newConns.begin(), newConns.end(),
198 back_inserter(myConnections));
204 for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
205 if ((*i).getTo() == to) {
216 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end();) {
217 if ((*i).getTo() == which) {
219 i = myConnections.erase(i);
220 for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
223 throw ProcessError(
"Could not replace edge '" + which->
getID() +
"' by '" + (*j)->getID() +
"'.\nUndefined...");
225 newConns.push_back(curr);
231 copy(newConns.begin(), newConns.end(),
232 back_inserter(myConnections));
239 for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end(); i++) {
240 if ((*i).getTo() == removed
242 ((*i).getToLane() == removedLane
244 (*i).getToLane() == -1)) {
245 (*i).replaceTo(removed, removedLane, by, byLane);
247 }
else if ((*i).getTo() == removed && removedLane == -1) {
248 (*i).replaceTo(removed, by);
251 if ((*i).getFrom() == removed
253 ((*i).getFromLane() == removedLane
255 (*i).getFromLane() == -1)) {
256 (*i).replaceFrom(removed, removedLane, by, byLane);
258 }
else if ((*i).getFrom() == removed && removedLane == -1) {
259 (*i).replaceFrom(removed, by);
294 NBLoadedTLDef::SignalGroupCont::const_iterator i;
296 std::set<SUMOReal> tmpSwitchTimes;
307 for (std::vector<SUMOReal>::const_iterator k = gtimes.begin(); k != gtimes.end(); k++) {
308 tmpSwitchTimes.insert(*k);
311 std::vector<SUMOReal> switchTimes;
312 copy(tmpSwitchTimes.begin(), tmpSwitchTimes.end(), back_inserter(switchTimes));
313 sort(switchTimes.begin(), switchTimes.end());
316 unsigned int noSignals = 0;
318 noSignals += (*i).second->getLinkNo();
322 for (std::vector<SUMOReal>::iterator l = switchTimes.begin(); l != switchTimes.end(); l++) {
324 unsigned int duration;
325 if (l != switchTimes.end() - 1) {
327 duration = (
unsigned int)((*(l + 1)) - (*l));
330 duration = (
unsigned int)(
myCycleDuration - (*l) + * (switchTimes.begin()));
348 unsigned int pos = 0;
351 unsigned int linkNo = group->
getLinkNo();
352 for (
unsigned int j = 0; j < linkNo; j++) {
372 unsigned int pos = 0;
379 unsigned int linkNo = group->
getLinkNo();
380 bool mayDrive = group->
mayDrive(time);
389 for (
unsigned int j = 0; j < linkNo; j++) {
393 if (assConn.
check(ec)) {
403 unsigned int linkNo = group->
getLinkNo();
404 for (
unsigned int j = 0; j < linkNo; j++) {
407 if (assConn.
check(ec)) {
408 if (!
mustBrake(ec, assConn, state, pos)) {
409 if (state[pos] ==
'g') {
412 if (state[pos] ==
'y') {
427 const std::string& state,
428 unsigned int strmpos)
const {
430 if (state[strmpos] !=
'g' && state[strmpos] !=
'G') {
436 unsigned int pos = 0;
440 unsigned int linkNo = group->
getLinkNo();
441 for (
unsigned int j = 0; j < linkNo; j++) {
446 if (possProhibitor.
check(ec)) {
452 if (state[pos] ==
'g' || state[pos] ==
'G') {
468 SignalGroupCont::const_iterator m;
471 unsigned int linkNo = group->
getLinkNo();
472 for (
unsigned int j = 0; j < linkNo; j++) {
490 for (
unsigned int j = 0; j < noLanes; j++) {
492 for (std::vector<NBEdge::Connection>::iterator k = elv.begin(); k != elv.end(); k++) {
506 if ((*i).second->containsConnection(from, to)) {
539 for (NBConnectionVector::const_iterator i = connections.begin(); i != connections.end(); i++) {
596 group->
remap(removed, removedLane, by, byLane);
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.
void setTLControllingInformation(const NBEdgeCont &ec) const
Informs edges about being controlled by a tls.
std::string buildPhaseState(const NBEdgeCont &ec, unsigned int time) const
Builds the phase for a given time.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
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.
void closeBuilding()
closes the building process
A SUMO-compliant built logic for a traffic light.
EdgeVector myIncomingEdges
The list of incoming edges.
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
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.
bool mustBrake(const NBEdgeCont &ec, const NBConnection &possProhibited, const std::string &state, unsigned int strmpos) const
Returns the information whether a connection must brake, given a phase.
TLColor
An enumeration of possible tl-signal states.
std::vector< Connection > getConnectionsFromLane(unsigned int lane) const
Returns connections from a given lane.
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.
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
const std::string & getID() const
Returns the id.
bool replaceFrom(NBEdge *which, NBEdge *by)
replaces the from-edge by the one given
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
SignalGroupCont mySignalGroups
Controlled signal groups.
unsigned int myCycleDuration
The duration of a single cycle.
NBTrafficLightLogic * myCompute(const NBEdgeCont &ec, unsigned int brakingTime)
Computes the traffic light logic finally in dependence to the type.
unsigned int getNumLanes() const
Returns the number of lanes.
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.
std::vector< SUMOReal > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
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.
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.
NBLoadedTLDef(const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
void setCycleDuration(unsigned int cycleDur)
Sets the duration of a cycle.
void addSignalGroup(const std::string &id)
Adds a signal group.
std::vector< NBEdge * > EdgeVector
Sorts phases by their begin time.
unsigned int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
NBEdge * getTo() const
returns the to-edge (end of the connection)
Represents a single node (junction) during network building.
const NBConnection & getConnection(unsigned int pos) const
Returns the connection at the given index.
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.
~NBLoadedTLDef()
Destructor.
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
void patchTYellow(SUMOTime tyellow, bool forced)
Sets the yellow time.
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.
NBConnectionVector myControlledLinks
The list of controlled links.
NBNode * getFromNode() const
Returns the origin node of the edge.