46 #define DEBUGCOND (myJunction->getID() == "C") 67 myOutgoing(outgoing) {
72 myDone.reserve(variations);
73 for (
int i = 0; i < variations; i++) {
78 for (NBConnectionProhibits::const_iterator j = loadedProhibits.begin(); j != loadedProhibits.end(); j++) {
80 bool ok1 = prohibited.
check(ec);
95 for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
97 bool ok2 = sprohibiting.
check(ec);
110 myDone[idx2][idx1] =
true;
111 myDone[idx1][idx2] =
true;
116 std::string ptID = prohibited.
getTo() != 0 ? prohibited.
getTo()->
getID() :
"UNKNOWN";
117 std::string bfID = sprohibiting.
getFrom() != 0 ? sprohibiting.
getFrom()->
getID() :
"UNKNOWN";
118 std::string btID = sprohibiting.
getTo() != 0 ? sprohibiting.
getTo()->
getID() :
"UNKNOWN";
119 WRITE_WARNING(
"could not prohibit " + pfID +
"->" + ptID +
" by " + bfID +
"->" + btID);
126 for (
int s1 = 0; s1 < variations; s1++) {
127 for (
int s2 = s1 + 1; s2 < variations; s2++) {
148 EdgeVector::const_iterator i, j;
164 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
165 while (*pfrom != to) {
168 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
169 while (*pto != from) {
182 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
183 while (*pfrom != to) {
186 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
187 while (*pto != from) {
202 if (to1 == 0 || to2 == 0) {
208 if (idx1 < 0 || idx2 < 0) {
217 myDone[idx1][idx2] =
true;
218 myDone[idx2][idx1] =
true;
260 if (from1p > from2p) {
264 if (from2p > from1p) {
311 EdgeVector::const_iterator c1 = find(
myAll.begin(),
myAll.end(), from1);
314 while (*c1 != from1 && *c1 != from2) {
323 EdgeVector::const_iterator c2 = find(
myAll.begin(),
myAll.end(), from2);
326 while (*c2 != from2 && *c2 != from1) {
339 EdgeVector::const_iterator p = find(
myAll.begin(),
myAll.end(), from);
343 if (p ==
myAll.begin()) {
355 EdgeVector::const_iterator i;
359 int noLanes = (*i)->getNumLanes();
360 for (
int k = 0; k < noLanes; k++) {
366 for (
auto c : crossings) {
376 int noLanesEdge1 = (*i11)->getNumLanes();
377 for (
int j1 = 0; j1 < noLanesEdge1; j1++) {
378 std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
379 for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) {
380 int idx1 =
getIndex((*i11), (*i12).toEdge);
386 int noLanesEdge2 = (*i21)->getNumLanes();
387 for (
int j2 = 0; j2 < noLanesEdge2; j2++) {
388 std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
389 for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) {
390 int idx2 =
getIndex((*i21), (*i22).toEdge);
396 if ((*i11) == (*i21)) {
403 if (((*i12).tlID ==
"" && (*i22).tlID ==
"")
405 ((*i12).tlID !=
"" && (*i22).tlID !=
"")) {
411 if (!
foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
416 if ((*i12).tlID !=
"") {
436 for (EdgeVector::const_iterator i =
myIncoming.begin();
438 int noLanesEdge = (*i)->getNumLanes();
439 for (
int j = 0; j < noLanesEdge; j++) {
440 int numConnections = (int)(*i)->getConnectionsFromLane(j).size();
441 noLinks += numConnections;
442 if (numConnections > 0) {
447 return std::make_pair(noLanes, noLinks);
453 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
455 if (to1 == 0 || to2 == 0) {
461 if (idx1 < 0 || idx2 < 0) {
472 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo,
473 bool regardNonSignalisedLowerPriority)
const {
475 if (possProhibitorTo == 0 || possProhibitedTo == 0) {
479 int possProhibitorIdx =
getIndex(possProhibitorFrom, possProhibitorTo);
480 int possProhibitedIdx =
getIndex(possProhibitedFrom, possProhibitedTo);
481 if (possProhibitorIdx < 0 || possProhibitedIdx < 0) {
487 if (!regardNonSignalisedLowerPriority) {
488 return myForbids[possProhibitorIdx][possProhibitedIdx];
491 if (!
myForbids[possProhibitorIdx][possProhibitedIdx]) {
504 int fromLane,
int pos,
const bool checkLaneFoes,
bool padding)
const {
506 assert(c.toEdge != 0);
509 if (padding && pos <= 10) {
512 const std::string
foes =
getFoesString(from, c.toEdge, fromLane, c.toLane, checkLaneFoes);
534 for (
int j = noLanes; j-- > 0;) {
536 int size = (int) connected.size();
537 for (
int k = size; k-- > 0;) {
538 const NBEdge* to = connected[k].toEdge;
540 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
541 if ((*it_e) == from || (*it_e) == to) {
546 foes += foe ?
'1' :
'0';
566 const int toLane = c.
toLane;
574 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
581 int noLanes = (*i)->getNumLanes();
582 for (
int j = noLanes; j-- > 0;) {
583 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
584 int size = (int) connected.size();
585 for (
int k = size; k-- > 0;) {
588 }
else if ((*i) == from && fromLane == j) {
592 assert(connected[k].toEdge != 0);
593 const int idx2 =
getIndex(*i, connected[k].toEdge);
594 assert(k < (
int) connected.size());
598 #ifdef DEBUG_RESPONSE 600 std::cout <<
" c=" << queryCon.
getDescription(from) <<
" prohibitC=" << connected[k].getDescription(*i)
602 <<
" clf=" << checkLaneFoes
604 <<
" lc=" <<
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)
606 <<
" mc=" <<
mergeConflict(from, queryCon, *i, connected[k],
false)
613 const bool hasLaneConflict = (!(checkLaneFoes ||
checkLaneFoesByClass(queryCon, *i, connected[k]))
614 ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane));
615 if ((
myForbids[idx2][idx] && hasLaneConflict)
644 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
646 for (EdgeVector::const_iterator it_e = (**i).edges.begin(); it_e != (**i).edges.end(); ++it_e) {
647 if ((*it_e) == from || (*it_e) == to) {
652 result += foes ?
'1' :
'0';
656 for (EdgeVector::const_reverse_iterator i =
myIncoming.rbegin();
659 for (
int j = (
int)(*i)->getNumLanes() - 1; j >= 0; --j) {
660 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
661 int size = (int) connected.size();
662 for (
int k = size; k-- > 0;) {
663 const bool hasLaneConflict = (!(checkLaneFoes ||
checkLaneFoesByClass(queryCon, *i, connected[k]))
664 ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane));
665 if ((
foes(from, to, (*i), connected[k].toEdge) && hasLaneConflict)
667 ||
myJunction->
turnFoes(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane, lefthand)
685 if (from == prohibitorFrom
747 if (shape.size() == 0 || otherShape.size() == 0) {
754 return foes || from->
getID() < prohibitorFrom->
getID();
775 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorToLane)
const {
776 if (to != prohibitorTo) {
791 return rightOfProhibitor ? toLane >= prohibitorToLane : toLane <= prohibitorToLane;
809 for (
int i = 0; i < variations; i++) {
811 for (
int j = 0; j < variations; j++) {
839 for (
int idx1 = 0; idx1 <
numLinks(); idx1++) {
846 if (includePedCrossings) {
848 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
858 const std::vector<NBEdge::Connection>& cons = from->
getConnections();
859 for (std::vector<NBEdge::Connection>::const_iterator i = cons.begin(); i != cons.end(); i++) {
861 from, (*i).toEdge, (*i).fromLane)) {
869 int noLanes = (*i)->getNumLanes();
870 for (
int j = noLanes; j-- > 0;) {
871 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
872 const int size = (int) connected.size();
873 for (
int k = size; k-- > 0;) {
874 if ((*i) == from && fromLane != j
889 if (crossing.
priority || mustYield) {
890 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
892 if (((*it_e) == from && crossing.
priority) || (*it_e) == to) {
903 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo)
const {
905 int idx1 =
getIndex(possProhibitorFrom, possProhibitorTo);
906 int idx2 =
getIndex(possProhibitedFrom, possProhibitedTo);
923 std::map<NBEdge*, int> incomingCount;
925 std::map<NBEdge*, std::set<int> > approachedLanes;
927 std::map<NBEdge*, EdgeVector> incomingEdges;
929 const std::vector<NBEdge::Connection> connections = (*it_e)->getConnections();
930 for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); ++it_c) {
931 incomingCount[it_c->toEdge]++;
932 approachedLanes[it_c->toEdge].insert(it_c->toLane);
933 incomingEdges[it_c->toEdge].push_back(*it_e);
936 for (std::map<NBEdge*, int>::iterator it = incomingCount.begin(); it != incomingCount.end(); ++it) {
939 if ((
int)approachedLanes[to].size() >= it->second) {
942 for (EdgeVector::iterator it_e1 = incoming.begin(); it_e1 != incoming.end(); ++it_e1) {
943 for (EdgeVector::iterator it_e2 = incoming.begin(); it_e2 != incoming.end(); ++it_e2) {
static double relAngle(double angle1, double angle2)
computes the relative angle between the two angles
std::pair< int, int > getSizes() const
returns the number of the junction's lanes and the number of the junction's links in respect...
The link is a partial left direction.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
void computeLeftOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing left of the given link
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
A structure which describes a connection between edges or lanes.
int toLane
The lane the connections yields in.
std::vector< bool > LinkInfoCont
definition of a container to store boolean informations about a link into
void append(const PositionVector &v, double sameThreshold=2.0)
NBEdge * toEdge
The edge the connections yields in.
bool isConnectedTo(const NBEdge *e) const
Returns the information whethe a connection to the given edge has been added (or computed) ...
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
bool hasSignalisedConnectionTo(const NBEdge *const e) const
Check if edge has signalised connections.
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
std::vector< Crossing * > getCrossings() const
return this junctions pedestrian crossings
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
The representation of a single edge during network building.
NBNode * myJunction
the node the request is assigned to
std::string getResponseString(const NBEdge *const from, const NBEdge::Connection &c, const bool checkLaneFoes) const
Writes the response of a certain link.
void buildBitfieldLogic()
builds the bitset-representation of the logic
const EdgeVector & myOutgoing
edges outgoing from the junction
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
NBEdge * getFrom() const
returns the from-edge (start of the connection)
void setBlocking(NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
bool checkLaneFoesByClass(const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections must be check for lane conflicts due to the vClasses involved ...
std::string getDescription(const NBEdge *parent) const
get string describing this connection
The link is a (hard) left direction.
#define WRITE_WARNING(msg)
int writeLaneResponse(OutputDevice &od, NBEdge *from, int lane, int pos, const bool checkLaneFoes, bool padding) const
writes the response of a certain lane Returns the next link index within the junction ...
const EdgeVector & myIncoming
edges incoming to the junction
static OptionsCont & getOptions()
Retrieves the options.
int numLinks() const
return to total number of edge-to-edge connections of this request-logic
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane, bool lefthand=false)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
CombinationsCont myDone
the link X link is done-checks
bool priority
whether the pedestrians have priority
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
int getIndex(const NBEdge *const from, const NBEdge *const to) const
Returns the index to the internal combination container for the given edge combination.
The link is a straight direction.
PositionVector shape
shape of Connection
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.
static void reportWarnings()
reports warnings if any occurred
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 ...
std::vector< Connection > getConnectionsFromLane(int lane) const
Returns connections from a given lane.
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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
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.
int getNumLanes() const
Returns the number of lanes.
int fromLane
The lane the connections starts at.
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 ...
void computeRightOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing right of the given link */
static double firstIntersection(const PositionVector &v1, const PositionVector &v2, double width2)
compute the first intersection point between the given lane geometries considering their rspective wi...
Storage for edges, including some functionality operating on multiple edges.
The link is a (hard) right direction.
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
int writeCrossingResponse(OutputDevice &od, const NBNode::Crossing &crossing, int pos) const
writes the response of a certain crossing Returns the next link index within the junction ...
The link is a partial right direction.
description of a logic request within the junction
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
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.
const EdgeVector & myAll
all (icoming and outgoing) of the junctions edges
int tlLinkIndex
The index of this connection within the controlling traffic light.
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
bool oppositeLeftTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether opposite left turns intersect
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
NBEdge * getTo() const
returns the to-edge (end of the connection)
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...
Connection getConnection(int fromLane, const NBEdge *to, int toLane) const
Returns the specified connection This method goes through "myConnections" and returns the specified o...
double getLaneWidth() const
Returns the default width of lanes of this edge.
bool isBentPriority()
return whether a priority road turns at this node
double length() const
Returns the length.
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
PositionVector viaShape
shape of via
const std::vector< Connection > & getConnections() const
Returns the connections.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
void writeLogic(std::string key, OutputDevice &into, const bool checkLaneFoes) const
writes the XML-representation of the logic as a bitset-logic XML representation
friend std::ostream & operator<<(std::ostream &os, const NBRequest &r)
prints the request
SumoXMLNodeType getType() const
Returns the type of this node.
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
EdgeVector edges
The edges being crossed.
Represents a single node (junction) during network building.
A definition of a pedestrian crossing.
Static storage of an output device and its base (abstract) implementation.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
NBNode * getFromNode() const
Returns the origin node of the edge.
int distanceCounterClockwise(NBEdge *from, NBEdge *to)
returns the distance between the incoming (from) and the outgoing (to) edge clockwise in edges ...
OutputDevice & writePadding(const std::string &val)
writes padding (ignored for binary output)
NBNode * getToNode() const
Returns the destination node of the edge.
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge...
static void nextCCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
CombinationsCont myForbids
the link X link blockings
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.