47 #ifdef CHECK_MEMORY_LEAKS 49 #endif // CHECK_MEMORY_LEAKS 61 const std::vector<NBNode*>& junctions,
const std::string& programID,
64 myControlledNodes(junctions),
65 mySubID(programID), myOffset(offset),
67 myNeedsContRelationReady(false),
68 myRightOnRedConflictsReady(false) {
81 for (std::vector<NBNode*>::const_iterator i = junctions.begin(); i != junctions.end(); i++) {
82 (*i)->addTrafficLight(
this);
119 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
120 (*it)->removeTrafficLight(
this);
122 WRITE_WARNING(
"The traffic light '" +
getID() +
"' does not control any links; it will not be build.");
129 if (oc.
isSet(
"tls.yellow.time")) {
130 brakingTime = oc.
getInt(
"tls.yellow.time");
147 return (
int)(vmax / minDecel);
160 std::set<NBEdge*> reachable;
161 while (outer.size() > 0) {
162 NBEdge* from = outer.back();
165 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
167 if (reachable.count(to) == 0 &&
168 (find(within.begin(), within.end(), to) != within.end()) &&
170 reachable.insert(to);
186 const EdgeVector& incoming = (*i)->getIncomingEdges();
187 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
188 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
189 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
197 EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge);
198 if (k != myOutgoing.end()) {
201 outer.push_back(edge);
214 if (reachable.count(edge) == 1) {
231 std::vector<NBNode*>::const_iterator i =
236 if (!node->hasOutgoing(to)) {
240 return node->
mustBrake(from, to, -1, -1,
true);
246 const NBEdge*
const possProhibitedTo,
247 const NBEdge*
const possProhibitorFrom,
248 const NBEdge*
const possProhibitorTo,
249 bool regardNonSignalisedLowerPriority)
const {
250 return forbids(possProhibitorFrom, possProhibitorTo,
251 possProhibitedFrom, possProhibitedTo,
252 regardNonSignalisedLowerPriority);
259 bool regardNonSignalisedLowerPriority)
const {
262 regardNonSignalisedLowerPriority);
268 const NBEdge*
const possProhibitorTo,
269 const NBEdge*
const possProhibitedFrom,
270 const NBEdge*
const possProhibitedTo,
271 bool regardNonSignalisedLowerPriority,
272 bool sameNodeOnly)
const {
273 if (possProhibitorFrom == 0 || possProhibitorTo == 0 || possProhibitedFrom == 0 || possProhibitedTo == 0) {
277 std::vector<NBNode*>::const_iterator incoming =
279 std::vector<NBNode*>::const_iterator outgoing =
282 NBNode* incnode = *incoming;
283 NBNode* outnode = *outgoing;
284 EdgeVector::const_iterator i;
286 if (incnode != outnode) {
294 for (i = ev1.begin(); i != ev1.end(); ++i) {
295 std::vector<NBNode*>::const_iterator outgoing2 =
300 NBNode* outnode2 = *outgoing2;
301 if (incnode != outnode2) {
307 bool ret1 = incnode->
foes(possProhibitorFrom, possProhibitorTo,
308 possProhibitedTo, *i);
309 bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
310 possProhibitedTo, *i,
311 regardNonSignalisedLowerPriority);
312 bool ret = ret1 || ret2;
321 for (i = ev2.begin(); i != ev2.end(); ++i) {
322 std::vector<NBNode*>::const_iterator incoming2 =
327 NBNode* incnode2 = *incoming2;
328 if (incnode2 != outnode) {
334 bool ret1 = incnode2->
foes(possProhibitorTo, *i,
335 possProhibitedFrom, possProhibitedTo);
336 bool ret2 = incnode2->
forbids(possProhibitorTo, *i,
337 possProhibitedFrom, possProhibitedTo,
338 regardNonSignalisedLowerPriority);
339 bool ret = ret1 || ret2;
348 return incnode->forbids(possProhibitorFrom, possProhibitorTo,
349 possProhibitedFrom, possProhibitedTo,
350 regardNonSignalisedLowerPriority);
356 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
357 if (to1 == 0 || to2 == 0) {
361 std::vector<NBNode*>::const_iterator incoming =
364 std::vector<NBNode*>::const_iterator outgoing =
368 NBNode* incnode = *incoming;
369 NBNode* outnode = *outgoing;
370 if (incnode != outnode) {
373 return incnode->
foes(from1, to1, from2, to2);
403 std::vector<std::string>
423 for (
int j = 0; j < noLanes; j++) {
425 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
461 (*i)->removeTrafficLight(&dummy);
477 (*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.
TrafficLightType myType
The algorithm type for the traffic light.
int computeBrakingTime(SUMOReal minDecel) const
Computes the time vehicles may need to brake.
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.
static const std::string DummyID
id for temporary definitions
std::vector< Connection > getConnectionsFromLane(int lane) const
Returns connections from a given lane.
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
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
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)
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
SUMOTime myOffset
The offset in the program.
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.
The link is a straight direction.
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.
static SUMOReal maxSpeed(const EdgeVector &ev)
SumoXMLNodeType getType() const
Returns the type of this node.
int getNumLanes() const
Returns the number of lanes.
virtual NBTrafficLightLogic * myCompute(int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
static const std::string DefaultProgramID
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.
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
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.
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
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
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.
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
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.
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.
static std::set< NBEdge * > collectReachable(EdgeVector outer, const EdgeVector &within, bool checkControlled)
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
NBConnectionVector myControlledLinks
The list of controlled links.
const std::vector< Connection > & getConnections() const
Returns the connections.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
std::string mySubID
The tls program's subid.
virtual 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