44#define DEBUGCOND (myJunction->getID() == "C")
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";
263#ifdef DEBUG_SETBLOCKING
265 std::cout <<
" p1=" << from1p <<
" p2=" << from2p <<
"\n";
270 if (from1p > from2p) {
274 if (from2p > from1p) {
284#ifdef DEBUG_SETBLOCKING
285 if (
DEBUGCOND) std::cout <<
"setBlocking"
286 <<
" 1:" << from1->
getID() <<
"->" << to1->
getID()
287 <<
" 2:" << from2->
getID() <<
"->" << to2->
getID()
328 EdgeVector::const_iterator c1 = std::find(
myAll.begin(),
myAll.end(), from1);
331 while (*c1 != from1 && *c1 != from2) {
344 EdgeVector::const_iterator c2 = std::find(
myAll.begin(),
myAll.end(), from2);
347 while (*c2 != from2 && *c2 != from1) {
359#ifdef DEBUG_SETBLOCKING
360 if (
DEBUGCOND) std::cout <<
"setBlocking"
361 <<
" 1:" << from1->
getID() <<
"->" << to1->
getID()
362 <<
" 2:" << from2->
getID() <<
"->" << to2->
getID()
370 EdgeVector::const_iterator p = std::find(
myAll.begin(),
myAll.end(), from);
374 if (p ==
myAll.begin()) {
384 assert(linkIndex >= 0);
385 assert(linkIndex < (
int)
myFoes.size());
392 assert(linkIndex >= 0);
404 for (
int i = 0; i <
numLinks; i++) {
407 if (padding && i < 10) {
426 EdgeVector::const_iterator i;
429 int noLanes = (*i)->getNumLanes();
430 for (
int k = 0; k < noLanes; k++) {
436 for (
auto c : crossings) {
445 int noLanesEdge1 = (*i11)->getNumLanes();
446 for (
int j1 = 0; j1 < noLanesEdge1; j1++) {
447 std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
448 for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) {
449 int idx1 =
getIndex((*i11), (*i12).toEdge);
455 int noLanesEdge2 = (*i21)->getNumLanes();
456 for (
int j2 = 0; j2 < noLanesEdge2; j2++) {
457 std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
458 for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) {
459 int idx2 =
getIndex((*i21), (*i22).toEdge);
465 if ((*i11) == (*i21)) {
472 if (((*i12).tlID ==
"" && (*i22).tlID ==
"")
474 ((*i12).tlID !=
"" && (*i22).tlID !=
"")) {
480 if (!
foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
485 if ((*i12).tlID !=
"") {
506 const int numLanesEdge = e->getNumLanes();
507 for (
int j = 0; j < numLanesEdge; j++) {
508 int numConnections = (int)e->getConnectionsFromLane(j).size();
510 if (numConnections > 0) {
515 return std::make_pair(numLanes,
numLinks);
521 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
523 if (to1 ==
nullptr || to2 ==
nullptr) {
529 if (idx1 < 0 || idx2 < 0) {
540 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo,
541 bool regardNonSignalisedLowerPriority)
const {
543 if (possProhibitorTo ==
nullptr || possProhibitedTo ==
nullptr) {
547 int possProhibitorIdx =
getIndex(possProhibitorFrom, possProhibitorTo);
548 int possProhibitedIdx =
getIndex(possProhibitedFrom, possProhibitedTo);
549 if (possProhibitorIdx < 0 || possProhibitedIdx < 0) {
555 if (!regardNonSignalisedLowerPriority) {
556 return myForbids[possProhibitorIdx][possProhibitedIdx];
559 if (!
myForbids[possProhibitorIdx][possProhibitedIdx]) {
572 assert(c.toEdge != 0);
574 const std::string
foes =
getFoesString(from, c.toEdge, fromLane, c.toLane, checkLaneFoes);
593 const int size = (int) connected.size();
594 for (
int k = size; k-- > 0;) {
595 const NBEdge* to = connected[k].toEdge;
598 if (e == from || e == to) {
603 foes += foe ?
'1' :
'0';
620 const int toLane = c.
toLane;
629 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
636 int noLanes = (*i)->getNumLanes();
637 for (
int j = noLanes; j-- > 0;) {
638 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
639 int size = (int) connected.size();
640 for (
int k = size; k-- > 0;) {
648 }
else if ((*i) == from && fromLane == j) {
653 std::cout <<
" c=" << queryCon.
getDescription(from) <<
" prohibitC=" << connected[k].getDescription(*i)
664 assert(connected[k].toEdge != 0);
665 const int idx2 =
getIndex(*i, connected[k].toEdge);
666 assert(k < (
int) connected.size());
672 std::cout <<
" c=" << queryCon.
getDescription(from) <<
" prohibitC=" << connected[k].getDescription(*i)
674 <<
" clf=" << checkLaneFoes
677 <<
" lc=" <<
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)
680 <<
" mc=" <<
mergeConflict(from, queryCon, *i, connected[k],
false)
688 const bool hasLaneConflict = (!(checkLaneFoes ||
checkLaneFoesByClass(queryCon, *i, connected[k])
690 ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane));
722 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
724 for (EdgeVector::const_iterator it_e = (**i).edges.begin(); it_e != (**i).edges.end(); ++it_e) {
725 if ((*it_e) == from || (*it_e) == to) {
730 result +=
foes ?
'1' :
'0';
735 for (
int j = (*i)->getNumLanes() - 1; j >= 0; --j) {
736 const std::vector<NBEdge::Connection>& connected = (*i)->getConnectionsFromLane(j);
737 int size = (int) connected.size();
738 for (
int k = size; k-- > 0;) {
739 const bool hasLaneConflict = (!(checkLaneFoes ||
checkLaneFoesByClass(queryCon, *i, connected[k])
741 ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane));
742 if ((
foes(from, to, (*i), connected[k].toEdge) && hasLaneConflict)
744 ||
myJunction->
turnFoes(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane, lefthand)
776 if (from == prohibitorFrom
841 if (shape.size() == 0 || otherShape.size() == 0) {
846 if (minDV < shape.
length() - POSITION_EPS && minDV > POSITION_EPS) {
856 if (from == prohibitorFrom) {
891 std::set<int> fromTargetLanes;
893 if (c.toEdge == con.
toEdge) {
894 fromTargetLanes.insert(c.toLane);
898 if (c.toEdge == con.
toEdge && fromTargetLanes.count(c.toLane) != 0) {
910 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorToLane)
const {
911 if (to != prohibitorTo) {
926 return rightOfProhibitor ? toLane >= prohibitorToLane : toLane <= prohibitorToLane;
944 for (
int i = 0; i < variations; i++) {
946 for (
int j = 0; j < variations; j++) {
964 if (linkIndex >= 0 && (
int)
myResponse.size() > linkIndex) {
966 if (!includePedCrossings) {
969 if (response.find_first_of(
"1") == std::string::npos) {
986 for (
int idx1 = 0; idx1 <
numLinks(); idx1++) {
993 if (includePedCrossings) {
995 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
1013 for (EdgeVector::const_reverse_iterator i =
myIncoming.rbegin(); i !=
myIncoming.rend(); i++) {
1014 int noLanes = (*i)->getNumLanes();
1015 for (
int j = noLanes; j-- > 0;) {
1016 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
1017 const int size = (int) connected.size();
1018 for (
int k = size; k-- > 0;) {
1019 if ((*i) == from && fromLane != j
1028 for (
int idx1 = 0; idx1 <
numLinks(); idx1++) {
1043 if (crossing.
priority || mustYield) {
1046 if ((e == from && crossing.
priority) || e == to) {
1057 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo)
const {
1059 int idx1 =
getIndex(possProhibitorFrom, possProhibitorTo);
1060 int idx2 =
getIndex(possProhibitedFrom, possProhibitedTo);
1077 std::map<const NBEdge*, int> incomingCount;
1079 std::map<const NBEdge*, std::set<int> > approachedLanes;
1081 std::map<const NBEdge*, std::vector<const NBEdge*> > incomingEdges;
1084 incomingCount[con.toEdge]++;
1085 approachedLanes[con.toEdge].insert(con.toLane);
1086 incomingEdges[con.toEdge].push_back(e);
1089 for (std::map<const NBEdge*, int>::iterator it = incomingCount.begin(); it != incomingCount.end(); ++it) {
1090 const NBEdge*
const to = it->first;
1092 if ((
int)approachedLanes[to].size() >= it->second) {
1093 const std::vector<const NBEdge*>& incoming = incomingEdges[to];
1095 for (
const NBEdge*
const e1 : incoming) {
1096 for (
const NBEdge*
const e2 : incoming) {
1107 for (
int i = 0; i < (int)
myFoes.size(); i++) {
1117 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
const std::vector< Connection > & getConnections() const
Returns the connections.
double getLaneWidth() const
Returns the default width of lanes of this edge.
NBNode * getToNode() const
Returns the destination node of the edge.
const Connection & getConnection(int fromLane, const NBEdge *to, int toLane) const
Returns the specified connection (unmodifiable) This method goes through "myConnections" and returns ...
const std::string & getID() const
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.
static double firstIntersection(const PositionVector &v1, const PositionVector &v2, double width1, double width2, const std::string &error="", bool secondIntersection=false)
compute the first intersection point between the given lane geometries considering their rspective wi...
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)
NBNode * getFromNode() const
Returns the origin node of the edge.
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
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...
bool indirectLeftTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether straight and indirect left turn are in conflict
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
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & writePadding(const std::string &val)
writes padding (ignored for binary output)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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.
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.
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.