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),
67 myRightOnRedConflictsReady(false) {
80 for (std::vector<NBNode*>::const_iterator i = junctions.begin(); i != junctions.end(); i++) {
81 (*i)->addTrafficLight(
this);
92 myNeedsContRelationReady(false) {
103 myNeedsContRelationReady(false)
116 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
117 (*it)->removeTrafficLight(
this);
119 WRITE_WARNING(
"The traffic light '" +
getID() +
"' does not control any links; it will not be build.");
126 if (oc.
isSet(
"tls.yellow.time")) {
127 brakingTime = oc.
getInt(
"tls.yellow.time");
144 return (
unsigned int)(vmax / minDecel);
163 const EdgeVector& incoming = (*i)->getIncomingEdges();
164 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
165 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
166 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
174 EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge);
175 if (k != myOutgoing.end()) {
178 outer.push_back(edge);
182 std::set<NBEdge*> reachable;
183 while (outer.size() > 0) {
184 std::vector<NBEdge::Connection>& cons = outer.back()->getConnections();
186 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
188 if (reachable.count(to) == 0) {
189 reachable.insert(to);
201 if (uncontrolledWithin) {
214 std::vector<NBNode*>::const_iterator i =
219 if (!node->hasOutgoing(to)) {
223 return node->
mustBrake(from, to, -1, -1,
true);
229 const NBEdge*
const possProhibitedTo,
230 const NBEdge*
const possProhibitorFrom,
231 const NBEdge*
const possProhibitorTo,
232 bool regardNonSignalisedLowerPriority)
const {
233 return forbids(possProhibitorFrom, possProhibitorTo,
234 possProhibitedFrom, possProhibitedTo,
235 regardNonSignalisedLowerPriority);
242 bool regardNonSignalisedLowerPriority)
const {
245 regardNonSignalisedLowerPriority);
251 const NBEdge*
const possProhibitorTo,
252 const NBEdge*
const possProhibitedFrom,
253 const NBEdge*
const possProhibitedTo,
254 bool regardNonSignalisedLowerPriority,
255 bool sameNodeOnly)
const {
256 if (possProhibitorFrom == 0 || possProhibitorTo == 0 || possProhibitedFrom == 0 || possProhibitedTo == 0) {
260 std::vector<NBNode*>::const_iterator incoming =
262 std::vector<NBNode*>::const_iterator outgoing =
265 NBNode* incnode = *incoming;
266 NBNode* outnode = *outgoing;
267 EdgeVector::const_iterator i;
268 if (incnode != outnode) {
276 for (i = ev1.begin(); i != ev1.end(); ++i) {
277 std::vector<NBNode*>::const_iterator outgoing2 =
282 NBNode* outnode2 = *outgoing2;
283 if (incnode != outnode2) {
286 bool ret1 = incnode->
foes(possProhibitorTo, *i,
287 possProhibitedFrom, possProhibitedTo);
288 bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
289 possProhibitedTo, *i,
290 regardNonSignalisedLowerPriority);
291 bool ret = ret1 || ret2;
300 for (i = ev2.begin(); i != ev2.end(); ++i) {
301 std::vector<NBNode*>::const_iterator incoming2 =
306 NBNode* incnode2 = *incoming2;
307 if (incnode2 != outnode) {
310 bool ret1 = incnode2->
foes(possProhibitorTo, *i,
311 possProhibitedFrom, possProhibitedTo);
312 bool ret2 = incnode2->
forbids(possProhibitorTo, *i,
313 possProhibitedFrom, possProhibitedTo,
314 regardNonSignalisedLowerPriority);
315 bool ret = ret1 || ret2;
324 return incnode->forbids(possProhibitorFrom, possProhibitorTo,
325 possProhibitedFrom, possProhibitedTo,
326 regardNonSignalisedLowerPriority);
332 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
333 if (to1 == 0 || to2 == 0) {
337 std::vector<NBNode*>::const_iterator incoming =
340 std::vector<NBNode*>::const_iterator outgoing =
344 NBNode* incnode = *incoming;
345 NBNode* outnode = *outgoing;
346 if (incnode != outnode) {
349 return incnode->
foes(from1, to1, from2, to2);
379 std::vector<std::string>
398 for (
unsigned int j = 0; j < noLanes; j++) {
400 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
433 (*i)->removeTrafficLight(&dummy);
448 (*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.
RightOnRedConflicts myRightOnRedConflicts
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.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
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.
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)
NBTrafficLightLogic * computeLogicAndConts(unsigned int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
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)
static OptionsCont & getOptions()
Retrieves the options.
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.
static const int FORWARD
edge directions (for pedestrian related stuff)
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.
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
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.
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 addParameter(const std::string &key, const std::string &value)
Adds a parameter.
bool myRightOnRedConflictsReady
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 mustBrake(const NBEdge *const from, const NBEdge *const to, int fromLane, int toLane, bool includePedCrossings) const
Returns the information whether the described flow must let any other flow pass.
bool myNeedsContRelationReady
std::vector< NBEdge * > EdgeVector
A storage for options typed value containers)
void setIsInnerEdge()
Marks this edge being within an intersection.
NBEdge * getTo() const
returns the to-edge (end of the connection)
NeedsContRelation myNeedsContRelation
Represents a single node (junction) during network building.
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.
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
NBConnectionVector myControlledLinks
The list of controlled links.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
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