 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
40 #define DEBUGCOND true
53 const std::vector<NBNode*>& junctions,
const std::string& programID,
56 myControlledNodes(junctions),
57 mySubID(programID), myOffset(offset),
59 myNeedsContRelationReady(false),
60 myRightOnRedConflictsReady(false) {
73 for (std::vector<NBNode*>::const_iterator i = junctions.begin(); i != junctions.end(); i++) {
74 (*i)->addTrafficLight(
this);
85 myNeedsContRelationReady(false),
86 myRightOnRedConflictsReady(false) {
97 myNeedsContRelationReady(false),
98 myRightOnRedConflictsReady(false) {
111 for (
auto it : nodes) {
112 it->removeTrafficLight(
this);
114 WRITE_WARNING(
"The traffic light '" +
getID() +
"' does not control any links; it will not be build.");
122 brakingTime = oc.
getInt(
"tls.yellow.time");
143 if (vmax < 71 / 3.6) {
146 return 3 + (int)
MAX2(0.0, (floor((vmax - 50 / 3.6) * 0.37)));
151 return (
int)(1.8 + vmax / 2 / minDecel);
165 std::set<NBEdge*> reachable;
166 while (outer.size() > 0) {
167 NBEdge* from = outer.back();
170 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
172 if (reachable.count(to) == 0 &&
173 (find(within.begin(), within.end(), to) != within.end()) &&
175 reachable.insert(to);
191 const EdgeVector& incoming = (*i)->getIncomingEdges();
192 copy(incoming.begin(), incoming.end(), back_inserter(
myIncomingEdges));
193 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
194 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
202 EdgeVector::iterator k = std::find(myOutgoing.begin(), myOutgoing.end(), edge);
203 if (k != myOutgoing.end()) {
206 outer.push_back(edge);
219 if (reachable.count(edge) == 1) {
236 std::vector<NBNode*>::const_iterator i =
241 if (!node->hasOutgoing(to)) {
245 return node->
mustBrake(from, to, -1, -1,
true);
251 const NBEdge*
const possProhibitedTo,
252 const NBEdge*
const possProhibitorFrom,
253 const NBEdge*
const possProhibitorTo,
254 bool regardNonSignalisedLowerPriority)
const {
255 return forbids(possProhibitorFrom, possProhibitorTo,
256 possProhibitedFrom, possProhibitedTo,
257 regardNonSignalisedLowerPriority);
264 bool regardNonSignalisedLowerPriority)
const {
267 regardNonSignalisedLowerPriority);
273 const NBEdge*
const possProhibitorTo,
274 const NBEdge*
const possProhibitedFrom,
275 const NBEdge*
const possProhibitedTo,
276 bool regardNonSignalisedLowerPriority,
277 bool sameNodeOnly)
const {
278 if (possProhibitorFrom ==
nullptr || possProhibitorTo ==
nullptr || possProhibitedFrom ==
nullptr || possProhibitedTo ==
nullptr) {
282 std::vector<NBNode*>::const_iterator incoming =
284 std::vector<NBNode*>::const_iterator outgoing =
287 NBNode* incnode = *incoming;
288 NBNode* outnode = *outgoing;
289 EdgeVector::const_iterator i;
291 #ifdef DEBUG_RIGHT_OF_WAY
293 std::cout <<
"foribds tls=" <<
getID() <<
" from=" << possProhibitedFrom->
getID() <<
" to=" << possProhibitedTo->
getID() <<
" foeFrom=" << possProhibitorFrom->
getID() <<
" foeTo=" << possProhibitorTo->
getID() <<
" rnslp=" << regardNonSignalisedLowerPriority <<
" sameNodeOnly=" << sameNodeOnly;
296 if (incnode != outnode) {
298 #ifdef DEBUG_RIGHT_OF_WAY
300 std::cout <<
" differentNodes: allows (no check)\n";
309 for (i = ev1.begin(); i != ev1.end(); ++i) {
310 std::vector<NBNode*>::const_iterator outgoing2 =
315 NBNode* outnode2 = *outgoing2;
316 if (incnode != outnode2) {
322 bool ret1 = incnode->
foes(possProhibitorFrom, possProhibitorTo,
323 possProhibitedTo, *i);
324 bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
325 possProhibitedTo, *i,
326 regardNonSignalisedLowerPriority);
327 bool ret = ret1 || ret2;
329 #ifdef DEBUG_RIGHT_OF_WAY
331 std::cout <<
" differentNodes: forbids\n";
341 for (i = ev2.begin(); i != ev2.end(); ++i) {
342 std::vector<NBNode*>::const_iterator incoming2 =
347 NBNode* incnode2 = *incoming2;
348 if (incnode2 != outnode) {
354 bool ret1 = incnode2->
foes(possProhibitorTo, *i,
355 possProhibitedFrom, possProhibitedTo);
356 bool ret2 = incnode2->
forbids(possProhibitorTo, *i,
357 possProhibitedFrom, possProhibitedTo,
358 regardNonSignalisedLowerPriority);
359 bool ret = ret1 || ret2;
361 #ifdef DEBUG_RIGHT_OF_WAY
363 std::cout <<
" differentNodes: forbids (2)\n";
369 #ifdef DEBUG_RIGHT_OF_WAY
371 std::cout <<
" differentNodes: allows\n";
378 const bool result = incnode->forbids(possProhibitorFrom, possProhibitorTo,
379 possProhibitedFrom, possProhibitedTo,
380 regardNonSignalisedLowerPriority);
381 #ifdef DEBUG_RIGHT_OF_WAY
383 std::cout <<
" sameNodes: " << (result ?
"forbids" :
"allows") <<
"\n";
392 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
393 if (to1 ==
nullptr || to2 ==
nullptr) {
397 std::vector<NBNode*>::const_iterator incoming =
400 std::vector<NBNode*>::const_iterator outgoing =
404 NBNode* incnode = *incoming;
405 NBNode* outnode = *outgoing;
406 if (incnode != outnode) {
409 return incnode->
foes(from1, to1, from2, to2);
439 std::vector<std::string>
459 for (
int j = 0; j < noLanes; j++) {
461 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
506 (*i)->removeTrafficLight(&dummy);
522 (*i)->removeTrafficLight(&dummy);
data structure for caching needsCont information
static const int FORWARD
edge directions (for pedestrian related stuff)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
virtual ~NBTrafficLightDefinition()
Destructor.
NBEdge * toEdge
The edge the connections yields in.
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.
NBTrafficLightLogic * compute(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 initNeedsContRelation() const
#define WRITE_WARNING(msg)
void initNeedsContRelation() const
Base class for objects which have an id.
Used for sorting the cells by the begin time they describe.
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
NBConnectionVector myControlledLinks
The list of controlled links.
virtual bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turning right on a red light
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
bool mustBrake(const NBEdge *const from, const NBEdge *const to) const
Returns the information whether the described flow must let any other flow pass.
virtual void collectLinks()=0
Collects the links participating in this traffic light.
NBEdge * getTo() const
returns the to-edge (end of the connection)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
A traffic light logics which must be computed (only nodes/edges are given)
static OptionsCont & getOptions()
Retrieves the options.
SumoXMLNodeType getType() const
Returns the type of this node.
static const std::string DummyID
id for temporary definitions
#define WRITE_WARNINGF(...)
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
virtual void collectEdges()
Build the list of participating edges.
void setInsideTLS()
Marks this edge being within an intersection.
int fromLane
The lane the connections starts at.
The representation of a single edge during network building.
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
int toLane
The lane the connections yields in.
The link is a 180 degree turn.
RightOnRedConflicts myRightOnRedConflicts
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
The link is a straight direction.
NBNode * getToNode() const
Returns the destination node of the edge.
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
void updateParameters(const std::map< std::string, std::string > &mapArg)
Adds or updates all given parameters from the map.
virtual NBTrafficLightLogic * myCompute(int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
static const SUMOTime UNSPECIFIED_DURATION
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
bool myRightOnRedConflictsReady
int getNumLanes() const
Returns the number of lanes.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
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.
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
static double maxSpeed(const EdgeVector &ev)
NeedsContRelation myNeedsContRelation
bool needsCont(const NBEdge *fromE, const NBEdge *toE, const NBEdge *otherFromE, const NBEdge *otherToE) const
A storage for options typed value containers)
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
bool myNeedsContRelationReady
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
NBTrafficLightDefinition(const std::string &id, const std::vector< NBNode * > &junctions, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static std::set< NBEdge * > collectReachable(EdgeVector outer, const EdgeVector &within, bool checkControlled)
std::string getDescription() const
get ID and programID together (for convenient debugging)
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
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 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.
static const std::string DefaultProgramID
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
const std::string & getProgramID() const
Returns the ProgramID.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
A SUMO-compliant built logic for a traffic light.
Represents a single node (junction) during network building.
EdgeVector myIncomingEdges
The list of incoming edges.
void collectAllLinks()
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
A structure which describes a connection between edges or lanes.
const std::string & getID() const
Returns the id.
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.
virtual bool amInvalid() const
const std::string & getID() const