44 #define DEBUGCOND (myJunction->getID() == "F")
65 myOutgoing(outgoing) {
70 myDone.reserve(variations);
71 for (
int i = 0; i < variations; i++) {
76 for (NBConnectionProhibits::const_iterator j = loadedProhibits.begin(); j != loadedProhibits.end(); j++) {
78 bool ok1 = prohibited.
check(ec);
93 for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
95 bool ok2 = sprohibiting.
check(ec);
108 myDone[idx2][idx1] =
true;
109 myDone[idx1][idx2] =
true;
113 std::string pfID = prohibited.
getFrom() !=
nullptr ? prohibited.
getFrom()->
getID() :
"UNKNOWN";
114 std::string ptID = prohibited.
getTo() !=
nullptr ? prohibited.
getTo()->
getID() :
"UNKNOWN";
115 std::string bfID = sprohibiting.
getFrom() !=
nullptr ? sprohibiting.
getFrom()->
getID() :
"UNKNOWN";
116 std::string btID = sprohibiting.
getTo() !=
nullptr ? sprohibiting.
getTo()->
getID() :
"UNKNOWN";
117 WRITE_WARNING(
"could not prohibit " + pfID +
"->" + ptID +
" by " + bfID +
"->" + btID);
124 for (
int s1 = 0; s1 < variations; s1++) {
125 for (
int s2 = s1 + 1; s2 < variations; s2++) {
146 EdgeVector::const_iterator i, j;
162 EdgeVector::const_iterator pfrom = std::find(
myAll.begin(),
myAll.end(), from);
163 while (*pfrom != to) {
166 EdgeVector::const_iterator pto = std::find(
myAll.begin(),
myAll.end(), to);
167 while (*pto != from) {
180 EdgeVector::const_iterator pfrom = std::find(
myAll.begin(),
myAll.end(), from);
181 while (*pfrom != to) {
184 EdgeVector::const_iterator pto = std::find(
myAll.begin(),
myAll.end(), to);
185 while (*pto != from) {
200 if (to1 ==
nullptr || to2 ==
nullptr) {
206 if (idx1 < 0 || idx2 < 0) {
215 myDone[idx1][idx2] =
true;
216 myDone[idx2][idx1] =
true;
252 #ifdef DEBUG_SETBLOCKING
255 <<
" 1:" << from1->
getID() <<
"->" << to1->
getID()
256 <<
" 2:" << from2->
getID() <<
"->" << to2->
getID() <<
"\n";
262 #ifdef DEBUG_SETBLOCKING
264 std::cout <<
" p1=" << from1p <<
" p2=" << from2p <<
"\n";
269 if (from1p > from2p) {
273 if (from2p > from1p) {
283 #ifdef DEBUG_SETBLOCKING
284 if (
DEBUGCOND) std::cout <<
"setBlocking"
285 <<
" 1:" << from1->
getID() <<
"->" << to1->
getID()
286 <<
" 2:" << from2->
getID() <<
"->" << to2->
getID()
326 EdgeVector::const_iterator c1 = std::find(
myAll.begin(),
myAll.end(), from1);
329 while (*c1 != from1 && *c1 != from2) {
338 EdgeVector::const_iterator c2 = std::find(
myAll.begin(),
myAll.end(), from2);
341 while (*c2 != from2 && *c2 != from1) {
349 #ifdef DEBUG_SETBLOCKING
350 if (
DEBUGCOND) std::cout <<
"setBlocking"
351 <<
" 1:" << from1->
getID() <<
"->" << to1->
getID()
352 <<
" 2:" << from2->
getID() <<
"->" << to2->
getID()
360 EdgeVector::const_iterator p = std::find(
myAll.begin(),
myAll.end(), from);
364 if (p ==
myAll.begin()) {
374 assert(linkIndex >= 0);
375 assert(linkIndex < (
int)
myFoes.size());
382 assert(linkIndex >= 0);
394 for (
int i = 0; i <
numLinks; i++) {
397 if (padding && i < 10) {
416 EdgeVector::const_iterator i;
419 int noLanes = (*i)->getNumLanes();
420 for (
int k = 0; k < noLanes; k++) {
426 for (
auto c : crossings) {
435 int noLanesEdge1 = (*i11)->getNumLanes();
436 for (
int j1 = 0; j1 < noLanesEdge1; j1++) {
437 std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
438 for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) {
439 int idx1 =
getIndex((*i11), (*i12).toEdge);
445 int noLanesEdge2 = (*i21)->getNumLanes();
446 for (
int j2 = 0; j2 < noLanesEdge2; j2++) {
447 std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
448 for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) {
449 int idx2 =
getIndex((*i21), (*i22).toEdge);
455 if ((*i11) == (*i21)) {
462 if (((*i12).tlID ==
"" && (*i22).tlID ==
"")
464 ((*i12).tlID !=
"" && (*i22).tlID !=
"")) {
470 if (!
foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
475 if ((*i12).tlID !=
"") {
495 for (EdgeVector::const_iterator i =
myIncoming.begin();
497 int noLanesEdge = (*i)->getNumLanes();
498 for (
int j = 0; j < noLanesEdge; j++) {
499 int numConnections = (int)(*i)->getConnectionsFromLane(j).size();
500 noLinks += numConnections;
501 if (numConnections > 0) {
506 return std::make_pair(noLanes, noLinks);
512 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
514 if (to1 ==
nullptr || to2 ==
nullptr) {
520 if (idx1 < 0 || idx2 < 0) {
531 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo,
532 bool regardNonSignalisedLowerPriority)
const {
534 if (possProhibitorTo ==
nullptr || possProhibitedTo ==
nullptr) {
538 int possProhibitorIdx =
getIndex(possProhibitorFrom, possProhibitorTo);
539 int possProhibitedIdx =
getIndex(possProhibitedFrom, possProhibitedTo);
540 if (possProhibitorIdx < 0 || possProhibitedIdx < 0) {
546 if (!regardNonSignalisedLowerPriority) {
547 return myForbids[possProhibitorIdx][possProhibitedIdx];
550 if (!
myForbids[possProhibitorIdx][possProhibitedIdx]) {
563 assert(c.toEdge != 0);
565 const std::string
foes =
getFoesString(from, c.toEdge, fromLane, c.toLane, checkLaneFoes);
584 for (
int j = noLanes; j-- > 0;) {
586 int size = (int) connected.size();
587 for (
int k = size; k-- > 0;) {
588 const NBEdge* to = connected[k].toEdge;
590 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
591 if ((*it_e) == from || (*it_e) == to) {
596 foes += foe ?
'1' :
'0';
613 const int toLane = c.
toLane;
622 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
629 int noLanes = (*i)->getNumLanes();
630 for (
int j = noLanes; j-- > 0;) {
631 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
632 int size = (int) connected.size();
633 for (
int k = size; k-- > 0;) {
636 #ifdef DEBUG_RESPONSE
641 }
else if ((*i) == from && fromLane == j) {
645 assert(connected[k].toEdge != 0);
646 const int idx2 =
getIndex(*i, connected[k].toEdge);
647 assert(k < (
int) connected.size());
651 #ifdef DEBUG_RESPONSE
653 std::cout <<
" c=" << queryCon.
getDescription(from) <<
" prohibitC=" << connected[k].getDescription(*i)
655 <<
" clf=" << checkLaneFoes
658 <<
" lc=" <<
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)
661 <<
" mc=" <<
mergeConflict(from, queryCon, *i, connected[k],
false)
668 const bool hasLaneConflict = (!(checkLaneFoes ||
checkLaneFoesByClass(queryCon, *i, connected[k])
670 ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane));
701 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
703 for (EdgeVector::const_iterator it_e = (**i).edges.begin(); it_e != (**i).edges.end(); ++it_e) {
704 if ((*it_e) == from || (*it_e) == to) {
709 result +=
foes ?
'1' :
'0';
713 for (EdgeVector::const_reverse_iterator i =
myIncoming.rbegin();
716 for (
int j = (
int)(*i)->getNumLanes() - 1; j >= 0; --j) {
717 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
718 int size = (int) connected.size();
719 for (
int k = size; k-- > 0;) {
720 const bool hasLaneConflict = (!(checkLaneFoes ||
checkLaneFoesByClass(queryCon, *i, connected[k])
722 ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane));
723 if ((
foes(from, to, (*i), connected[k].toEdge) && hasLaneConflict)
725 ||
myJunction->
turnFoes(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane, lefthand)
756 if (from == prohibitorFrom
820 if (shape.size() == 0 || otherShape.size() == 0) {
825 if (minDV < shape.
length() - POSITION_EPS && minDV > POSITION_EPS) {
856 std::set<int> fromTargetLanes;
858 if (c.toEdge == con.
toEdge) {
859 fromTargetLanes.insert(c.toLane);
863 if (c.toEdge == con.
toEdge && fromTargetLanes.count(c.toLane) != 0) {
875 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorToLane)
const {
876 if (to != prohibitorTo) {
891 return rightOfProhibitor ? toLane >= prohibitorToLane : toLane <= prohibitorToLane;
909 for (
int i = 0; i < variations; i++) {
911 for (
int j = 0; j < variations; j++) {
929 if (linkIndex >= 0 && (
int)
myResponse.size() > linkIndex) {
931 if (!includePedCrossings) {
934 if (response.find_first_of(
"1") == std::string::npos) {
951 for (
int idx1 = 0; idx1 <
numLinks(); idx1++) {
958 if (includePedCrossings) {
960 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
979 int noLanes = (*i)->getNumLanes();
980 for (
int j = noLanes; j-- > 0;) {
981 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
982 const int size = (int) connected.size();
983 for (
int k = size; k-- > 0;) {
984 if ((*i) == from && fromLane != j
993 for (
int idx1 = 0; idx1 <
numLinks(); idx1++) {
1008 if (crossing.
priority || mustYield) {
1009 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
1011 if (((*it_e) == from && crossing.
priority) || (*it_e) == to) {
1022 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo)
const {
1024 int idx1 =
getIndex(possProhibitorFrom, possProhibitorTo);
1025 int idx2 =
getIndex(possProhibitedFrom, possProhibitedTo);
1042 std::map<NBEdge*, int> incomingCount;
1044 std::map<NBEdge*, std::set<int> > approachedLanes;
1046 std::map<NBEdge*, EdgeVector> incomingEdges;
1048 const std::vector<NBEdge::Connection> connections = (*it_e)->getConnections();
1049 for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); ++it_c) {
1050 incomingCount[it_c->toEdge]++;
1051 approachedLanes[it_c->toEdge].insert(it_c->toLane);
1052 incomingEdges[it_c->toEdge].push_back(*it_e);
1055 for (std::map<NBEdge*, int>::iterator it = incomingCount.begin(); it != incomingCount.end(); ++it) {
1058 if ((
int)approachedLanes[to].size() >= it->second) {
1061 for (EdgeVector::iterator it_e1 = incoming.begin(); it_e1 != incoming.end(); ++it_e1) {
1062 for (EdgeVector::iterator it_e2 = incoming.begin(); it_e2 != incoming.end(); ++it_e2) {
1073 for (
int i = 0; i < (int)
myFoes.size(); i++) {
1083 return myFoes[linkIndex].find_first_of(
"1") != std::string::npos;
#define WRITE_WARNING(msg)
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
std::ostream & operator<<(std::ostream &os, const NBRequest &r)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PEDESTRIAN
pedestrian
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_REQUEST
description of a logic request within the junction
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ PARTLEFT
The link is a partial left direction.
@ RIGHT
The link is a (hard) right direction.
@ LEFT
The link is a (hard) left direction.
@ STRAIGHT
The link is a straight direction.
@ PARTRIGHT
The link is a partial right 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)
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
static void nextCCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
Storage for edges, including some functionality operating on multiple edges.
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
double getLaneWidth() const
Returns the default width of lanes of this edge.
const std::string & getID() const
NBNode * getToNode() const
Returns the destination node of the edge.
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
bool hasSignalisedConnectionTo(const NBEdge *const e) const
Check if edge has signalised connections.
int getNumLanes() const
Returns the number of lanes.
bool isConnectedTo(const NBEdge *e, const bool ignoreTurnaround=false) const
Returns the information whethe a connection to the given edge has been added (or computed)
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
const std::vector< Connection > & getConnections() const
Returns the connections.
Connection getConnection(int fromLane, const NBEdge *to, int toLane) const
Returns the specified connection This method goes through "myConnections" and returns the specified o...
NBNode * getFromNode() const
Returns the origin node of the edge.
static double firstIntersection(const PositionVector &v1, const PositionVector &v2, double width2, const std::string &error="")
compute the first intersection point between the given lane geometries considering their rspective wi...
static double relAngle(double angle1, double angle2)
computes the relative angle between the two angles
A definition of a pedestrian crossing.
bool priority
whether the pedestrians have priority
EdgeVector edges
The edges being crossed.
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.
int getConnectionIndex(const NBEdge *from, const NBEdge::Connection &con) const
return the index of the given connection
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light
SumoXMLNodeType getType() const
Returns the type of this node.
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
std::vector< Crossing * > getCrossings() const
return this junctions pedestrian crossings
bool isBentPriority() const
return whether a priority road turns at this node
bool turnFoes(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *from2, const NBEdge *to2, int fromLane2, bool lefthand=false) const
return whether the given laneToLane connection originate from the same edge and are in conflict due t...
bool isConstantWidthTransition() const
detects whether a given junction splits or merges lanes while keeping constant road width
bool tlsContConflict(const NBEdge *from, const NBEdge::Connection &c, const NBEdge *foeFrom, const NBEdge::Connection &foe) const
whether the connection must yield if the foe remains on the intersection after its phase ends
bool isTLControlled() const
Returns whether this node is controlled by any tls.
std::vector< std::string > myResponse
const EdgeVector & myOutgoing
edges outgoing from the junction
CombinationsCont myForbids
the link X link blockings
int computeLaneResponse(NBEdge *from, int lane, int pos, const bool checkLaneFoes)
computes the response of a certain lane Returns the next link index within the junction
CombinationsCont myDone
the link X link is done-checks
const EdgeVector & myAll
all (icoming and outgoing) of the junctions edges
bool checkLaneFoesByCooperation(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections must be checked for lane conflicts due to disjunct target lanes
std::vector< std::string > myFoes
precomputed right-of-way matrices for each lane-to-lane link
int distanceCounterClockwise(NBEdge *from, NBEdge *to)
returns the distance between the incoming (from) and the outgoing (to) edge clockwise in 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.
bool hasConflictAtLink(int linkIndex) const
whether there are conflicting streams of traffic for the given link index
const EdgeVector & myIncoming
edges incoming to the junction
NBNode * myJunction
the node the request is assigned to
int numLinks() const
return to total number of edge-to-edge connections of this request-logic
const std::string & getFoes(int linkIndex) const
bool hasConflict() const
whether there are conflicting streams of traffic at this node
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
void buildBitfieldLogic()
builds the bitset-representation of the logic
bool oppositeLeftTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether opposite left turns intersect
bool laneConflict(const NBEdge *from, const NBEdge *to, int toLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorToLane) const
return whether the given laneToLane connections prohibit each other under the assumption that the edg...
int getIndex(const NBEdge *const from, const NBEdge *const to) const
Returns the index to the internal combination container for the given edge combination.
static bool mustBrakeForCrossing(const NBNode *node, const NBEdge *const from, const NBEdge *const to, const NBNode::Crossing &crossing)
Returns the information whether the described flow must brake for the given crossing.
void computeRightOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing right of the given link */
bool mergeConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether multple connections from the same edge target the same lane
void writeLogic(OutputDevice &into) const
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
void computeLogic(const bool checkLaneFoes)
writes the XML-representation of the logic as a bitset-logic XML representation
std::string getResponseString(const NBEdge *const from, const NBEdge::Connection &c, const bool checkLaneFoes) const
Writes the response of a certain link.
std::pair< int, int > getSizes() const
returns the number of the junction's lanes and the number of the junction's links in respect.
bool mustBrake(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
const std::string & getResponse(int linkIndex) const
int computeCrossingResponse(const NBNode::Crossing &crossing, int pos)
computes the response of a certain crossing Returns the next link index within the junction
void setBlocking(NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
void computeLeftOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing left of the given link
bool checkLaneFoesByClass(const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections must be checked for lane conflicts due to the vClasses involved
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge
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.
bool rightTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections crosses the foe connection from the same lane and must yield
static void reportWarnings()
reports warnings if any occurred
std::vector< bool > LinkInfoCont
definition of a container to store boolean informations about a link into
std::vector< bool > myHaveVia
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.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
OutputDevice & writePadding(const std::string &val)
writes padding (ignored for binary output)
void append(const PositionVector &v, double sameThreshold=2.0)
double length() const
Returns the length.
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.
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
PositionVector viaShape
shape of via
std::string getDescription(const NBEdge *parent) const
get string describing this connection
PositionVector shape
shape of Connection
int tlLinkIndex
The index of this connection within the controlling traffic light.