56 const std::vector<NBNode*>& junctions,
const std::string& programID,
59 myControlledNodes(junctions),
60 mySubID(programID), myOffset(offset),
62 myNeedsContRelationReady(false),
63 myExtraConflictsReady(false) {
77 node->addTrafficLight(
this);
88 myNeedsContRelationReady(false),
89 myExtraConflictsReady(false) {
100 myNeedsContRelationReady(false),
101 myExtraConflictsReady(false) {
114 for (
auto it : nodes) {
115 it->removeTrafficLight(
this);
117 WRITE_WARNINGF(
TL(
"The traffic light '%' does not control any links; it will not be build."),
getID());
125 brakingTime = oc.
getInt(
"tls.yellow.time");
130 for (
const std::string& param : {
131 "jam-threshold",
"passing-time",
"detector-gap",
"detector-length",
"inactive-threshold"
159 if (vmax < 71 / 3.6) {
167 return (
int)(1.8 + vmax / 2 / minDecel);
181 std::set<NBEdge*> reachable;
182 while (outer.size() > 0) {
183 NBEdge* from = outer.back();
186 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
188 if (reachable.count(to) == 0 &&
189 (find(within.begin(), within.end(), to) != within.end()) &&
191 reachable.insert(to);
208 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
209 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
210 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
216 edge->setInsideTLS(
false);
218 EdgeVector::iterator k = std::find(myOutgoing.begin(), myOutgoing.end(), edge);
219 if (k != myOutgoing.end()) {
222 outer.push_back(edge);
235 if (reachable.count(edge) == 1) {
252 std::vector<NBNode*>::const_iterator i =
257 if (!
node->hasOutgoing(to)) {
267 const NBEdge*
const possProhibitedTo,
268 const NBEdge*
const possProhibitorFrom,
269 const NBEdge*
const possProhibitorTo,
270 bool regardNonSignalisedLowerPriority)
const {
271 return forbids(possProhibitorFrom, possProhibitorTo,
272 possProhibitedFrom, possProhibitedTo,
273 regardNonSignalisedLowerPriority);
280 bool regardNonSignalisedLowerPriority)
const {
283 regardNonSignalisedLowerPriority);
289 const NBEdge*
const possProhibitorTo,
290 const NBEdge*
const possProhibitedFrom,
291 const NBEdge*
const possProhibitedTo,
292 bool regardNonSignalisedLowerPriority,
293 bool sameNodeOnly)
const {
294 if (possProhibitorFrom ==
nullptr || possProhibitorTo ==
nullptr || possProhibitedFrom ==
nullptr || possProhibitedTo ==
nullptr) {
298 std::vector<NBNode*>::const_iterator incoming =
300 std::vector<NBNode*>::const_iterator outgoing =
303 NBNode* incnode = *incoming;
304 NBNode* outnode = *outgoing;
305 EdgeVector::const_iterator i;
307#ifdef DEBUG_RIGHT_OF_WAY
309 std::cout <<
"forbids tls=" <<
getID() <<
" from=" << possProhibitedFrom->
getID() <<
" to=" << possProhibitedTo->
getID() <<
" foeFrom=" << possProhibitorFrom->
getID() <<
" foeTo=" << possProhibitorTo->
getID() <<
" rnslp=" << regardNonSignalisedLowerPriority <<
" sameNodeOnly=" << sameNodeOnly;
312 if (incnode != outnode) {
314#ifdef DEBUG_RIGHT_OF_WAY
316 std::cout <<
" differentNodes: allows (no check)\n";
325 for (i = ev1.begin(); i != ev1.end(); ++i) {
326 std::vector<NBNode*>::const_iterator outgoing2 =
331 NBNode* outnode2 = *outgoing2;
332 if (incnode != outnode2) {
338 bool ret1 = incnode->
foes(possProhibitorFrom, possProhibitorTo,
339 possProhibitedTo, *i);
340 bool ret2 = incnode->
forbids(possProhibitorFrom, possProhibitorTo,
341 possProhibitedTo, *i,
342 regardNonSignalisedLowerPriority);
343 bool ret = ret1 || ret2;
345#ifdef DEBUG_RIGHT_OF_WAY
347 std::cout <<
" differentNodes: forbids\n";
357 for (i = ev2.begin(); i != ev2.end(); ++i) {
358 std::vector<NBNode*>::const_iterator incoming2 =
363 NBNode* incnode2 = *incoming2;
364 if (incnode2 != outnode) {
370 bool ret1 = incnode2->
foes(possProhibitorTo, *i,
371 possProhibitedFrom, possProhibitedTo);
372 bool ret2 = incnode2->
forbids(possProhibitorTo, *i,
373 possProhibitedFrom, possProhibitedTo,
374 regardNonSignalisedLowerPriority);
375 bool ret = ret1 || ret2;
377#ifdef DEBUG_RIGHT_OF_WAY
379 std::cout <<
" differentNodes: forbids (2)\n";
385#ifdef DEBUG_RIGHT_OF_WAY
387 std::cout <<
" differentNodes: allows\n";
394 const bool result = incnode->
forbids(possProhibitorFrom, possProhibitorTo,
395 possProhibitedFrom, possProhibitedTo,
396 regardNonSignalisedLowerPriority);
397#ifdef DEBUG_RIGHT_OF_WAY
399 std::cout <<
" sameNodes: " << (result ?
"forbids" :
"allows") <<
"\n";
408 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
409 if (to1 ==
nullptr || to2 ==
nullptr) {
413 std::vector<NBNode*>::const_iterator incoming =
416 std::vector<NBNode*>::const_iterator outgoing =
420 NBNode* incnode = *incoming;
421 NBNode* outnode = *outgoing;
422 if (incnode != outnode) {
425 return incnode->
foes(from1, to1, from2, to2);
435 node->addTrafficLight(
this);
455std::vector<std::string>
471 std::vector<int> indirectLeft;
475 for (
int j = 0; j < noLanes; j++) {
477 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
501 indirectLeft.push_back((
int)into.size() - 1);
508 if (indirectLeft.size() > 0) {
510 for (
int i : indirectLeft) {
514 if (c2.getTo() == c.
getTo() && c2.getFrom() != c.
getFrom()) {
525 if (into.size() > 0 && tlIndex == 0) {
539 WRITE_WARNINGF(
TL(
"Could not interpret rail signal direction at junction '%' due to inconsistent directions of edge '%' (%) and edge '%' (%)"),
566 (*i)->removeTrafficLight(&dummy);
582 (*i)->removeTrafficLight(&dummy);
#define WRITE_WARNINGF(...)
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a (exclusive) railway edge.
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ TURN
The link is a 180 degree turn.
@ STRAIGHT
The link is a straight direction.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
NBEdge * getFrom() const
returns the from-edge (start of the connection)
void setTLIndex2(int tlIndex)
NBEdge * getTo() const
returns the to-edge (end of the connection)
static double maxSpeed(const EdgeVector &ev)
The representation of a single edge during network building.
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
const std::vector< Connection > & getConnections() const
Returns the connections.
NBNode * getToNode() const
Returns the destination node of the edge.
void setInsideTLS(bool inside)
Marks this edge being within an intersection.
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
const std::string & getID() const
int getNumLanes() const
Returns the number of lanes.
std::vector< Connection > getConnectionsFromLane(int lane, const NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
const NBEdge * getBidiEdge() const
EdgeVector getIncomingEdges() const
Returns the list of incoming edges unsorted.
Used for sorting the cells by the begin time they describe.
Represents a single node (junction) during network building.
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
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.
SumoXMLNodeType getType() const
Returns the type of this node.
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.
static const int FORWARD
edge directions (for pedestrian related stuff)
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.
A traffic light logics which must be computed (only nodes/edges are given)
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
void initNeedsContRelation() const
virtual ~NBTrafficLightDefinition()
Destructor.
const std::string & getProgramID() const
Returns the ProgramID.
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
bool needsCont(const NBEdge *fromE, const NBEdge *toE, const NBEdge *otherFromE, const NBEdge *otherToE) const
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
EdgeVector myIncomingEdges
The list of incoming edges.
ExtraConflicts myExtraConflicts
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
NBTrafficLightLogic * compute(const OptionsCont &oc)
Computes the traffic light logic.
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
virtual void initExtraConflicts() const
bool myExtraConflictsReady
virtual NBTrafficLightLogic * myCompute(int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
static std::set< NBEdge * > collectReachable(EdgeVector outer, const EdgeVector &within, bool checkControlled)
static const std::string OSM_DIRECTION
processing parameter for rail signal edges and nodes
static const int MIN_YELLOW_SECONDS
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
static const std::string DummyID
id for temporary definitions
virtual void collectLinks()=0
Collects the links participating in this traffic light.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
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.
virtual bool amInvalid() const
NBConnectionVector myControlledLinks
The list of controlled links.
static const std::string DefaultProgramID
virtual bool extraConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex (i.e. while turning right on a red light)
bool mustBrake(const NBEdge *const from, const NBEdge *const to) const
Returns the information whether the described flow must let any other flow pass.
bool myNeedsContRelationReady
virtual void initNeedsContRelation() const
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
void collectAllLinks(NBConnectionVector &into)
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
NBTrafficLightDefinition(const std::string &id, const std::vector< NBNode * > &junctions, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
static const SUMOTime UNSPECIFIED_DURATION
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 const std::string OSM_SIGNAL_DIRECTION
std::string getDescription() const
get ID and programID together (for convenient debugging)
static bool railSignalUncontrolled(const NBEdge *in, const NBEdge *out)
NeedsContRelation myNeedsContRelation
virtual void collectEdges()
Build the list of participating edges.
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
A SUMO-compliant built logic for a traffic light.
TrafficLightType getType() const
get the algorithm type (static etc..)
Base class for objects which have an id.
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
static OptionsCont & getOptions()
Retrieves the options.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
void updateParameters(const Parameterised::Map &mapArg)
Adds or updates all given parameters from the map.
A structure which describes a connection between edges or lanes.
bool indirectLeft
Whether this connection is an indirect left turn.
int fromLane
The lane the connections starts at.
int toLane
The lane the connections yields in.
NBEdge * toEdge
The edge the connections yields in.
data structure for caching needsCont information