47 #ifdef CHECK_MEMORY_LEAKS
49 #endif // CHECK_MEMORY_LEAKS
60 const std::vector<NBNode*>& junctions,
const std::string& programID,
63 myControlledNodes(junctions),
64 mySubID(programID), myOffset(offset),
66 myNeedsContRelationReady(false) {
79 for (std::vector<NBNode*>::const_iterator i = junctions.begin(); i != junctions.end(); i++) {
80 (*i)->addTrafficLight(
this);
91 myNeedsContRelationReady(false) {
102 myNeedsContRelationReady(false)
115 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
116 (*it)->removeTrafficLight(
this);
118 WRITE_WARNING(
"The traffic light '" +
getID() +
"' does not control any links; it will not be build.");
125 if (oc.
isSet(
"tls.yellow.time")) {
126 brakingTime = oc.
getInt(
"tls.yellow.time");
143 return (
unsigned int)(vmax / minDecel);
161 const EdgeVector& incoming = (*i)->getIncomingEdges();
162 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
163 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
164 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
172 EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge);
173 if (k != myOutgoing.end()) {
176 (*j)->setIsInnerEdge();
188 std::vector<NBNode*>::const_iterator i =
193 if (!node->hasOutgoing(to)) {
196 return node->
mustBrake(from, to, -1,
true);
202 const NBEdge*
const possProhibitedTo,
203 const NBEdge*
const possProhibitorFrom,
204 const NBEdge*
const possProhibitorTo,
205 bool regardNonSignalisedLowerPriority)
const {
206 return forbids(possProhibitorFrom, possProhibitorTo,
207 possProhibitedFrom, possProhibitedTo,
208 regardNonSignalisedLowerPriority);
215 bool regardNonSignalisedLowerPriority)
const {
218 regardNonSignalisedLowerPriority);
224 const NBEdge*
const possProhibitorTo,
225 const NBEdge*
const possProhibitedFrom,
226 const NBEdge*
const possProhibitedTo,
227 bool regardNonSignalisedLowerPriority)
const {
228 if (possProhibitorFrom == 0 || possProhibitorTo == 0 || possProhibitedFrom == 0 || possProhibitedTo == 0) {
232 std::vector<NBNode*>::const_iterator incoming =
234 std::vector<NBNode*>::const_iterator outgoing =
237 NBNode* incnode = *incoming;
238 NBNode* outnode = *outgoing;
239 EdgeVector::const_iterator i;
240 if (incnode != outnode) {
245 for (i = ev1.begin(); i != ev1.end(); ++i) {
246 std::vector<NBNode*>::const_iterator outgoing2 =
251 NBNode* outnode2 = *outgoing2;
252 if (incnode != outnode2) {
255 bool ret1 = incnode->
foes(possProhibitorTo, *i,
256 possProhibitedFrom, possProhibitedTo);
257 bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
258 possProhibitedTo, *i,
259 regardNonSignalisedLowerPriority);
260 bool ret = ret1 || ret2;
269 for (i = ev2.begin(); i != ev2.end(); ++i) {
270 std::vector<NBNode*>::const_iterator incoming2 =
275 NBNode* incnode2 = *incoming2;
276 if (incnode2 != outnode) {
279 bool ret1 = incnode2->
foes(possProhibitorTo, *i,
280 possProhibitedFrom, possProhibitedTo);
281 bool ret2 = incnode2->
forbids(possProhibitorTo, *i,
282 possProhibitedFrom, possProhibitedTo,
283 regardNonSignalisedLowerPriority);
284 bool ret = ret1 || ret2;
293 return incnode->forbids(possProhibitorFrom, possProhibitorTo,
294 possProhibitedFrom, possProhibitedTo,
295 regardNonSignalisedLowerPriority);
301 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
302 if (to1 == 0 || to2 == 0) {
306 std::vector<NBNode*>::const_iterator incoming =
309 std::vector<NBNode*>::const_iterator outgoing =
313 NBNode* incnode = *incoming;
314 NBNode* outnode = *outgoing;
315 if (incnode != outnode) {
318 return incnode->
foes(from1, to1, from2, to2);
348 std::vector<std::string>
367 for (
unsigned int j = 0; j < noLanes; j++) {
369 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
402 (*i)->removeTrafficLight(&dummy);
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
A structure which describes a connection between edges or lanes.
int toLane
The lane the connections yields in.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
void collectAllLinks()
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
NBEdge * toEdge
The edge the connections yields in.
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
A SUMO-compliant built logic for a traffic light.
EdgeVector myIncomingEdges
The list of incoming edges.
virtual ~NBTrafficLightDefinition()
Destructor.
The representation of a single edge during network building.
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
Used for sorting the cells by the begin time they describe.
bool mustBrake(const NBEdge *const from, const NBEdge *const to, int fromLane, bool includePedCrossings) const
Returns the information whether the described flow must let any other flow pass.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
std::vector< Connection > getConnectionsFromLane(unsigned int lane) const
Returns connections from a given lane.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
#define WRITE_WARNING(msg)
virtual void collectLinks()=0
Collects the links participating in this traffic light If a link could not be found.
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
const std::string & getID() const
Returns the id.
virtual void collectEdges()
Build the list of participating edges.
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
int fromLane
The lane the connections starts at.
NBTrafficLightLogic * compute(const NBEdgeCont &ec, OptionsCont &oc)
Computes the traffic light logic.
static SUMOReal maxSpeed(const EdgeVector &ev)
unsigned int getNumLanes() const
Returns the number of lanes.
Storage for edges, including some functionality operating on multiple edges.
static const std::string DefaultProgramID
unsigned int computeBrakingTime(SUMOReal minDecel) const
Computes the time vehicles may need to brake.
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
bool mustBrake(const NBEdge *const from, const NBEdge *const to) const
Returns the information whether the described flow must let any other flow pass.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
Base class for objects which have an id.
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
bool needsCont(const NBEdge *fromE, const NBEdge *toE, const NBEdge *otherFromE, const NBEdge *otherToE) const
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
bool myNeedsContRelationReady
std::vector< NBEdge * > EdgeVector
A storage for options typed value containers)
NBEdge * getTo() const
returns the to-edge (end of the connection)
NeedsContRelation myNeedsContRelation
Represents a single node (junction) during network building.
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
virtual NBTrafficLightLogic * myCompute(const NBEdgeCont &ec, unsigned int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
void initNeedsContRelation() const
data structure for caching needsCont information
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
NBTrafficLightDefinition(const std::string &id, const std::vector< NBNode * > &junctions, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
A traffic light logics which must be computed (only nodes/edges are given)
virtual bool amInvalid() const
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
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.
NBConnectionVector myControlledLinks
The list of controlled links.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
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.
virtual void initNeedsContRelation() const