57 const std::vector<NBNode*>& junctions,
const std::string& programID,
60 myControlledNodes(junctions),
61 mySubID(programID), myOffset(offset),
63 myNeedsContRelationReady(false),
64 myRightOnRedConflictsReady(false) {
77 for (std::vector<NBNode*>::const_iterator i = junctions.begin(); i != junctions.end(); i++) {
78 (*i)->addTrafficLight(
this);
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.");
126 brakingTime = oc.
getInt(
"tls.yellow.time");
143 return (
int)(vmax / minDecel);
156 std::set<NBEdge*> reachable;
157 while (outer.size() > 0) {
158 NBEdge* from = outer.back();
161 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
163 if (reachable.count(to) == 0 &&
164 (find(within.begin(), within.end(), to) != within.end()) &&
166 reachable.insert(to);
182 const EdgeVector& incoming = (*i)->getIncomingEdges();
183 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
184 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
185 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
193 EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge);
194 if (k != myOutgoing.end()) {
197 outer.push_back(edge);
210 if (reachable.count(edge) == 1) {
227 std::vector<NBNode*>::const_iterator i =
232 if (!node->hasOutgoing(to)) {
236 return node->
mustBrake(from, to, -1, -1,
true);
242 const NBEdge*
const possProhibitedTo,
243 const NBEdge*
const possProhibitorFrom,
244 const NBEdge*
const possProhibitorTo,
245 bool regardNonSignalisedLowerPriority)
const {
246 return forbids(possProhibitorFrom, possProhibitorTo,
247 possProhibitedFrom, possProhibitedTo,
248 regardNonSignalisedLowerPriority);
255 bool regardNonSignalisedLowerPriority)
const {
258 regardNonSignalisedLowerPriority);
264 const NBEdge*
const possProhibitorTo,
265 const NBEdge*
const possProhibitedFrom,
266 const NBEdge*
const possProhibitedTo,
267 bool regardNonSignalisedLowerPriority,
268 bool sameNodeOnly)
const {
269 if (possProhibitorFrom == 0 || possProhibitorTo == 0 || possProhibitedFrom == 0 || possProhibitedTo == 0) {
273 std::vector<NBNode*>::const_iterator incoming =
275 std::vector<NBNode*>::const_iterator outgoing =
278 NBNode* incnode = *incoming;
279 NBNode* outnode = *outgoing;
280 EdgeVector::const_iterator i;
282 if (incnode != outnode) {
290 for (i = ev1.begin(); i != ev1.end(); ++i) {
291 std::vector<NBNode*>::const_iterator outgoing2 =
296 NBNode* outnode2 = *outgoing2;
297 if (incnode != outnode2) {
303 bool ret1 = incnode->
foes(possProhibitorFrom, possProhibitorTo,
304 possProhibitedTo, *i);
305 bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
306 possProhibitedTo, *i,
307 regardNonSignalisedLowerPriority);
308 bool ret = ret1 || ret2;
317 for (i = ev2.begin(); i != ev2.end(); ++i) {
318 std::vector<NBNode*>::const_iterator incoming2 =
323 NBNode* incnode2 = *incoming2;
324 if (incnode2 != outnode) {
330 bool ret1 = incnode2->
foes(possProhibitorTo, *i,
331 possProhibitedFrom, possProhibitedTo);
332 bool ret2 = incnode2->
forbids(possProhibitorTo, *i,
333 possProhibitedFrom, possProhibitedTo,
334 regardNonSignalisedLowerPriority);
335 bool ret = ret1 || ret2;
344 return incnode->forbids(possProhibitorFrom, possProhibitorTo,
345 possProhibitedFrom, possProhibitedTo,
346 regardNonSignalisedLowerPriority);
352 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
353 if (to1 == 0 || to2 == 0) {
357 std::vector<NBNode*>::const_iterator incoming =
360 std::vector<NBNode*>::const_iterator outgoing =
364 NBNode* incnode = *incoming;
365 NBNode* outnode = *outgoing;
366 if (incnode != outnode) {
369 return incnode->
foes(from1, to1, from2, to2);
399 std::vector<std::string>
419 for (
int j = 0; j < noLanes; j++) {
421 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
460 (*i)->removeTrafficLight(&dummy);
476 (*i)->removeTrafficLight(&dummy);
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
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.
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.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static double maxSpeed(const EdgeVector &ev)
virtual bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
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
RightOnRedConflicts myRightOnRedConflicts
A SUMO-compliant built logic for a traffic light.
EdgeVector myIncomingEdges
The list of incoming edges.
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.
virtual ~NBTrafficLightDefinition()
Destructor.
The representation of a single edge during network building.
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
Used for sorting the cells by the begin time they describe.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
bool needsCont(const NBEdge *fromE, const NBEdge *toE, const NBEdge *otherFromE, const NBEdge *otherToE) const
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
NBTrafficLightDefinition(const std::string &id, const std::vector< NBNode *> &junctions, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
SUMOTime myOffset
The offset in the program.
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
virtual void collectLinks()=0
Collects the links participating in this traffic light.
virtual void initNeedsContRelation() const
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
The link is a straight direction.
std::vector< Connection > getConnectionsFromLane(int lane) const
Returns connections from a given lane.
virtual void collectEdges()
Build the list of participating edges.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
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 getNumLanes() const
Returns the number of lanes.
int fromLane
The lane the connections starts at.
virtual NBTrafficLightLogic * myCompute(int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
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.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
Base class for objects which have an id.
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
NBEdge * getTo() const
returns the to-edge (end of the connection)
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
bool myRightOnRedConflictsReady
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
virtual bool amInvalid() const
const std::vector< Connection > & getConnections() const
Returns the connections.
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.
bool myNeedsContRelationReady
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
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.
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
A storage for options typed value containers)
SumoXMLNodeType getType() const
Returns the type of this node.
void setIsInnerEdge()
Marks this edge being within an intersection.
NeedsContRelation myNeedsContRelation
Represents a single node (junction) during network building.
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
data structure for caching needsCont information
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
A traffic light logics which must be computed (only nodes/edges are given)
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 initNeedsContRelation() const
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.
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::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
NBNode * getToNode() const
Returns the destination node of the edge.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
std::string mySubID
The tls program's subid.