71 myCrossings(junction->getCrossings()) {
76 myDone.reserve(variations);
77 for (
int i = 0; i < variations; i++) {
82 for (NBConnectionProhibits::const_iterator j = loadedProhibits.begin(); j != loadedProhibits.end(); j++) {
84 bool ok1 = prohibited.
check(ec);
99 for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
101 bool ok2 = sprohibiting.
check(ec);
114 myDone[idx2][idx1] =
true;
115 myDone[idx1][idx2] =
true;
120 std::string ptID = prohibited.
getTo() != 0 ? prohibited.
getTo()->
getID() :
"UNKNOWN";
121 std::string bfID = sprohibiting.
getFrom() != 0 ? sprohibiting.
getFrom()->
getID() :
"UNKNOWN";
122 std::string btID = sprohibiting.
getTo() != 0 ? sprohibiting.
getTo()->
getID() :
"UNKNOWN";
123 WRITE_WARNING(
"could not prohibit " + pfID +
"->" + ptID +
" by " + bfID +
"->" + btID);
130 for (
int s1 = 0; s1 < variations; s1++) {
131 for (
int s2 = s1 + 1; s2 < variations; s2++) {
152 EdgeVector::const_iterator i, j;
168 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
169 while (*pfrom != to) {
172 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
173 while (*pto != from) {
186 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
187 while (*pfrom != to) {
190 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
191 while (*pto != from) {
206 if (to1 == 0 || to2 == 0) {
212 if (idx1 < 0 || idx2 < 0) {
221 myDone[idx1][idx2] =
true;
222 myDone[idx2][idx1] =
true;
246 if (from1p > from2p) {
250 if (from2p > from1p) {
278 EdgeVector::const_iterator c1 = find(
myAll.begin(),
myAll.end(), from1);
281 while (*c1 != from1 && *c1 != from2) {
290 EdgeVector::const_iterator c2 = find(
myAll.begin(),
myAll.end(), from2);
293 while (*c2 != from2 && *c2 != from1) {
306 EdgeVector::const_iterator p = find(
myAll.begin(),
myAll.end(), from);
310 if (p ==
myAll.begin()) {
322 EdgeVector::const_iterator i;
325 int noLanes = (*i)->getNumLanes();
326 for (
int k = 0; k < noLanes; k++) {
341 int noLanesEdge1 = (*i11)->getNumLanes();
342 for (
int j1 = 0; j1 < noLanesEdge1; j1++) {
343 std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
344 for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) {
345 int idx1 =
getIndex((*i11), (*i12).toEdge);
351 int noLanesEdge2 = (*i21)->getNumLanes();
352 for (
int j2 = 0; j2 < noLanesEdge2; j2++) {
353 std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
354 for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) {
355 int idx2 =
getIndex((*i21), (*i22).toEdge);
361 if ((*i11) == (*i21)) {
368 if (((*i12).tlID ==
"" && (*i22).tlID ==
"")
370 ((*i12).tlID !=
"" && (*i22).tlID !=
"")) {
376 if (!
foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
381 if ((*i12).tlID !=
"") {
401 for (EdgeVector::const_iterator i =
myIncoming.begin();
403 int noLanesEdge = (*i)->getNumLanes();
404 for (
int j = 0; j < noLanesEdge; j++) {
405 int numConnections = (int)(*i)->getConnectionsFromLane(j).size();
406 noLinks += numConnections;
407 if (numConnections > 0) {
412 return std::make_pair(noLanes, noLinks);
418 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
420 if (to1 == 0 || to2 == 0) {
426 if (idx1 < 0 || idx2 < 0) {
437 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo,
438 bool regardNonSignalisedLowerPriority)
const {
440 if (possProhibitorTo == 0 || possProhibitedTo == 0) {
444 int possProhibitorIdx =
getIndex(possProhibitorFrom, possProhibitorTo);
445 int possProhibitedIdx =
getIndex(possProhibitedFrom, possProhibitedTo);
446 if (possProhibitorIdx < 0 || possProhibitedIdx < 0) {
452 if (!regardNonSignalisedLowerPriority) {
453 return myForbids[possProhibitorIdx][possProhibitedIdx];
456 if (!
myForbids[possProhibitorIdx][possProhibitedIdx]) {
469 int fromLane,
int pos,
const bool checkLaneFoes)
const {
471 for (std::vector<NBEdge::Connection>::iterator j = connected.begin(); j != connected.end(); j++) {
472 assert((*j).toEdge != 0);
475 const std::string
foes =
getFoesString(from, (*j).toEdge, fromLane, (*j).toLane, checkLaneFoes);
477 :
getResponseString((*j).tlLinkNo, from, (*j).toEdge, fromLane, (*j).toLane, (*j).mayDefinitelyPass, checkLaneFoes));
498 for (
int j = noLanes; j-- > 0;) {
500 int size = (int) connected.size();
501 for (
int k = size; k-- > 0;) {
502 const NBEdge* to = connected[k].toEdge;
504 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
505 if ((*it_e) == from || (*it_e) == to) {
510 foes += foe ?
'1' :
'0';
527 int fromLane,
int toLane,
bool mayDefinitelyPass,
const bool checkLaneFoes)
const {
535 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
542 int noLanes = (*i)->getNumLanes();
543 for (
int j = noLanes; j-- > 0;) {
544 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
545 int size = (int) connected.size();
546 for (
int k = size; k-- > 0;) {
547 if (mayDefinitelyPass) {
549 }
else if ((*i) == from && fromLane == j) {
553 assert(k < (
int) connected.size());
555 assert(connected[k].toEdge != 0);
559 (!checkLaneFoes ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)))
584 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
586 for (EdgeVector::const_iterator it_e = (**i).edges.begin(); it_e != (**i).edges.end(); ++it_e) {
587 if ((*it_e) == from || (*it_e) == to) {
592 result += foes ?
'1' :
'0';
596 for (EdgeVector::const_reverse_iterator i =
myIncoming.rbegin();
599 for (
int j = (
int)(*i)->getNumLanes() - 1; j >= 0; --j) {
600 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
601 int size = (int) connected.size();
602 for (
int k = size; k-- > 0;) {
603 if ((
foes(from, to, (*i), connected[k].toEdge) &&
604 (!checkLaneFoes ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)))
621 return (from == prohibitorFrom
636 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorToLane)
const {
637 if (to != prohibitorTo) {
652 return rightOfProhibitor ? toLane >= prohibitorToLane : toLane <= prohibitorToLane;
671 for (
int i = 0; i < variations; i++) {
673 for (
int j = 0; j < variations; j++) {
701 for (
int idx1 = 0; idx1 <
numLinks(); idx1++) {
708 if (includePedCrossings) {
709 for (std::vector<NBNode::Crossing*>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
719 const std::vector<NBEdge::Connection>& cons = from->
getConnections();
720 for (std::vector<NBEdge::Connection>::const_iterator i = cons.begin(); i != cons.end(); i++) {
722 from, (*i).toEdge, (*i).fromLane)) {
730 int noLanes = (*i)->getNumLanes();
731 for (
int j = noLanes; j-- > 0;) {
732 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
733 const int size = (int) connected.size();
734 for (
int k = size; k-- > 0;) {
735 if ((*i) == from && fromLane != j
750 if (crossing.
priority || mustYield) {
751 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
753 if (((*it_e) == from && crossing.
priority) || (*it_e) == to) {
764 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo)
const {
766 int idx1 =
getIndex(possProhibitorFrom, possProhibitorTo);
767 int idx2 =
getIndex(possProhibitedFrom, possProhibitedTo);
784 std::map<NBEdge*, int> incomingCount;
786 std::map<NBEdge*, std::set<int> > approachedLanes;
788 std::map<NBEdge*, EdgeVector> incomingEdges;
790 const std::vector<NBEdge::Connection> connections = (*it_e)->getConnections();
791 for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); ++it_c) {
792 incomingCount[it_c->toEdge]++;
793 approachedLanes[it_c->toEdge].insert(it_c->toLane);
794 incomingEdges[it_c->toEdge].push_back(*it_e);
797 for (std::map<NBEdge*, int>::iterator it = incomingCount.begin(); it != incomingCount.end(); ++it) {
800 if ((
int)approachedLanes[to].size() >= it->second) {
803 for (EdgeVector::iterator it_e1 = incoming.begin(); it_e1 != incoming.end(); ++it_e1) {
804 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
int getIndex(const NBEdge *const from, const NBEdge *const to) const
Returns the index to the internal combination container for the given edge combination.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
void computeLeftOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
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
NBEdge * toEdge
The edge the connections yields in.
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 ...
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
std::vector< Connection > getConnectionsFromLane(int lane) const
Returns connections from a given lane.
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 getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
The representation of a single edge during network building.
NBNode * myJunction
the node the request is assigned to
void buildBitfieldLogic()
const EdgeVector & myOutgoing
static bool mergeConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes)
whether multple connections from the same edge target the same lane
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
void setBlocking(NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
int numLinks() const
return to total number of edge-to-edge connections of this request-logic
void writeLogic(std::string key, OutputDevice &into, const bool checkLaneFoes) const
NBEdge * getFrom() const
returns the from-edge (start of the connection)
The link is a (hard) left direction.
#define WRITE_WARNING(msg)
const EdgeVector & myIncoming
static OptionsCont & getOptions()
Retrieves the options.
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...
bool priority
whether the pedestrians have priority
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
static void reportWarnings()
reports warnings if any occured
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.
const std::string & getID() const
Returns the id.
Connection getConnection(int fromLane, const NBEdge *to, int toLane) const
Returns the specified connection This method goes through "myConnections" and returns the specified o...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
int fromLane
The lane the connections starts at.
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.
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...
std::vector< NBNode::Crossing * > myCrossings
SumoXMLNodeType getType() const
Returns the type of this node.
int getNumLanes() const
Returns the number of lanes.
void computeRightOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Storage for edges, including some functionality operating on multiple edges.
The link is a (hard) right direction.
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
The link is a partial right direction.
description of a logic request within the junction
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
NBNode * getToNode() const
Returns the destination node of the edge.
std::string getResponseString(int tlIndex, const NBEdge *const from, const NBEdge *const to, int fromLane, int toLane, bool mayDefinitelyPass, const bool checkLaneFoes) const
Writes the response of a certain link.
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
int writeLaneResponse(OutputDevice &od, NBEdge *from, int lane, int pos, const bool checkLaneFoes) const
writes the response of a certain lane Returns the next link index within the junction ...
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
friend std::ostream & operator<<(std::ostream &os, const NBRequest &r)
prints the request
NBEdge * getTo() const
returns the to-edge (end of the connection)
EdgeVector edges
The edges being crossed.
Represents a single node (junction) during network building.
bool hasSignalisedConnectionTo(const NBEdge *const e) const
Check if edge has signalised connections.
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.
A definition of a pedestrian crossing.
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
int distanceCounterClockwise(NBEdge *from, NBEdge *to)
const std::vector< Connection > & getConnections() const
Returns the connections.
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
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
NBNode * getFromNode() const
Returns the origin node of the edge.