39 #define DEBUGCOND true
52 const std::vector<NBNode*>& junctions,
const std::string& programID,
55 myControlledNodes(junctions),
56 mySubID(programID), myOffset(offset),
58 myNeedsContRelationReady(false),
59 myRightOnRedConflictsReady(false) {
72 for (std::vector<NBNode*>::const_iterator i = junctions.begin(); i != junctions.end(); i++) {
73 (*i)->addTrafficLight(
this);
84 myNeedsContRelationReady(false),
85 myRightOnRedConflictsReady(false) {
96 myNeedsContRelationReady(false),
97 myRightOnRedConflictsReady(false) {
110 for (
auto it : nodes) {
111 it->removeTrafficLight(
this);
113 WRITE_WARNING(
"The traffic light '" +
getID() +
"' does not control any links; it will not be build.");
121 brakingTime = oc.
getInt(
"tls.yellow.time");
142 if (vmax < 71 / 3.6) {
145 return 3 + (int)
MAX2(0.0, (floor((vmax - 50 / 3.6) * 0.37)));
150 return (
int)(1.8 + vmax / 2 / minDecel);
164 std::set<NBEdge*> reachable;
165 while (outer.size() > 0) {
166 NBEdge* from = outer.back();
169 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
171 if (reachable.count(to) == 0 &&
172 (find(within.begin(), within.end(), to) != within.end()) &&
174 reachable.insert(to);
190 const EdgeVector& incoming = (*i)->getIncomingEdges();
191 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
192 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
193 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
199 edge->setInsideTLS(
false);
201 EdgeVector::iterator k = std::find(myOutgoing.begin(), myOutgoing.end(), edge);
202 if (k != myOutgoing.end()) {
205 outer.push_back(edge);
218 if (reachable.count(edge) == 1) {
235 std::vector<NBNode*>::const_iterator i =
244 return node->
mustBrake(from, to, -1, -1,
true);
250 const NBEdge*
const possProhibitedTo,
251 const NBEdge*
const possProhibitorFrom,
252 const NBEdge*
const possProhibitorTo,
253 bool regardNonSignalisedLowerPriority)
const {
254 return forbids(possProhibitorFrom, possProhibitorTo,
255 possProhibitedFrom, possProhibitedTo,
256 regardNonSignalisedLowerPriority);
263 bool regardNonSignalisedLowerPriority)
const {
266 regardNonSignalisedLowerPriority);
272 const NBEdge*
const possProhibitorTo,
273 const NBEdge*
const possProhibitedFrom,
274 const NBEdge*
const possProhibitedTo,
275 bool regardNonSignalisedLowerPriority,
276 bool sameNodeOnly)
const {
277 if (possProhibitorFrom ==
nullptr || possProhibitorTo ==
nullptr || possProhibitedFrom ==
nullptr || possProhibitedTo ==
nullptr) {
281 std::vector<NBNode*>::const_iterator incoming =
283 std::vector<NBNode*>::const_iterator outgoing =
286 NBNode* incnode = *incoming;
287 NBNode* outnode = *outgoing;
288 EdgeVector::const_iterator i;
290 #ifdef DEBUG_RIGHT_OF_WAY
292 std::cout <<
"foribds tls=" <<
getID() <<
" from=" << possProhibitedFrom->
getID() <<
" to=" << possProhibitedTo->
getID() <<
" foeFrom=" << possProhibitorFrom->
getID() <<
" foeTo=" << possProhibitorTo->
getID() <<
" rnslp=" << regardNonSignalisedLowerPriority <<
" sameNodeOnly=" << sameNodeOnly;
295 if (incnode != outnode) {
297 #ifdef DEBUG_RIGHT_OF_WAY
299 std::cout <<
" differentNodes: allows (no check)\n";
308 for (i = ev1.begin(); i != ev1.end(); ++i) {
309 std::vector<NBNode*>::const_iterator outgoing2 =
314 NBNode* outnode2 = *outgoing2;
315 if (incnode != outnode2) {
321 bool ret1 = incnode->
foes(possProhibitorFrom, possProhibitorTo,
322 possProhibitedTo, *i);
323 bool ret2 = incnode->
forbids(possProhibitorFrom, possProhibitorTo,
324 possProhibitedTo, *i,
325 regardNonSignalisedLowerPriority);
326 bool ret = ret1 || ret2;
328 #ifdef DEBUG_RIGHT_OF_WAY
330 std::cout <<
" differentNodes: forbids\n";
340 for (i = ev2.begin(); i != ev2.end(); ++i) {
341 std::vector<NBNode*>::const_iterator incoming2 =
346 NBNode* incnode2 = *incoming2;
347 if (incnode2 != outnode) {
353 bool ret1 = incnode2->
foes(possProhibitorTo, *i,
354 possProhibitedFrom, possProhibitedTo);
355 bool ret2 = incnode2->
forbids(possProhibitorTo, *i,
356 possProhibitedFrom, possProhibitedTo,
357 regardNonSignalisedLowerPriority);
358 bool ret = ret1 || ret2;
360 #ifdef DEBUG_RIGHT_OF_WAY
362 std::cout <<
" differentNodes: forbids (2)\n";
368 #ifdef DEBUG_RIGHT_OF_WAY
370 std::cout <<
" differentNodes: allows\n";
377 const bool result = incnode->
forbids(possProhibitorFrom, possProhibitorTo,
378 possProhibitedFrom, possProhibitedTo,
379 regardNonSignalisedLowerPriority);
380 #ifdef DEBUG_RIGHT_OF_WAY
382 std::cout <<
" sameNodes: " << (result ?
"forbids" :
"allows") <<
"\n";
391 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
392 if (to1 ==
nullptr || to2 ==
nullptr) {
396 std::vector<NBNode*>::const_iterator incoming =
399 std::vector<NBNode*>::const_iterator outgoing =
403 NBNode* incnode = *incoming;
404 NBNode* outnode = *outgoing;
405 if (incnode != outnode) {
408 return incnode->
foes(from1, to1, from2, to2);
438 std::vector<std::string>
457 for (
int j = 0; j < noLanes; j++) {
459 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
480 if (into.size() > 0 && tlIndex == 0) {
504 (*i)->removeTrafficLight(&dummy);
520 (*i)->removeTrafficLight(&dummy);
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
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 permission is a railway edge.
@ 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)
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
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
NBNode * getToNode() const
Returns the destination node of the edge.
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
int getNumLanes() const
Returns the number of lanes.
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 std::vector< Connection > & getConnections() const
Returns the connections.
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.
bool hasOutgoing(const NBEdge *const e) const
Returns whether the given edge starts at this node.
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.
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
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 bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turning right on a red light
const std::string & getProgramID() const
Returns the ProgramID.
virtual ~NBTrafficLightDefinition()
Destructor.
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 NBTrafficLightLogic * myCompute(int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
EdgeVector myIncomingEdges
The list of incoming edges.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
static std::set< NBEdge * > collectReachable(EdgeVector outer, const EdgeVector &within, bool checkControlled)
RightOnRedConflicts myRightOnRedConflicts
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.
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
virtual bool amInvalid() const
NBConnectionVector myControlledLinks
The list of controlled links.
static const std::string DefaultProgramID
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.
std::string getDescription() const
get ID and programID together (for convenient debugging)
bool myRightOnRedConflictsReady
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.
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)
static OptionsCont & getOptions()
Retrieves the options.
void updateParameters(const std::map< std::string, std::string > &mapArg)
Adds or updates all given parameters from the map.
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
A structure which describes a connection between edges or lanes.
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