51 #ifdef CHECK_MEMORY_LEAKS
53 #endif // CHECK_MEMORY_LEAKS
76 myCrossings(junction->getCrossings()) {
77 const size_t variations =
numLinks();
81 myDone.reserve(variations);
82 for (
size_t i = 0; i < variations; i++) {
87 for (NBConnectionProhibits::const_iterator j = loadedProhibits.begin(); j != loadedProhibits.end(); j++) {
89 bool ok1 = prohibited.
check(ec);
104 for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
106 bool ok2 = sprohibiting.
check(ec);
119 myDone[idx2][idx1] =
true;
120 myDone[idx1][idx2] =
true;
125 std::string ptID = prohibited.
getTo() != 0 ? prohibited.
getTo()->
getID() :
"UNKNOWN";
126 std::string bfID = sprohibiting.
getFrom() != 0 ? sprohibiting.
getFrom()->
getID() :
"UNKNOWN";
127 std::string btID = sprohibiting.
getTo() != 0 ? sprohibiting.
getTo()->
getID() :
"UNKNOWN";
128 WRITE_WARNING(
"could not prohibit " + pfID +
"->" + ptID +
" by " + bfID +
"->" + btID);
135 for (
size_t s1 = 0; s1 < variations; s1++) {
136 for (
size_t s2 = s1 + 1; s2 < variations; s2++) {
157 EdgeVector::const_iterator i, j;
173 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
174 while (*pfrom != to) {
177 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
178 while (*pto != from) {
191 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
192 while (*pfrom != to) {
195 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
196 while (*pto != from) {
212 if (to1 == 0 || to2 == 0) {
218 if (idx1 < 0 || idx2 < 0) {
227 myDone[idx1][idx2] =
true;
228 myDone[idx2][idx1] =
true;
252 if (from1p > from2p) {
256 if (from2p > from1p) {
284 EdgeVector::const_iterator c1 = find(
myAll.begin(),
myAll.end(), from1);
287 while (*c1 != from1 && *c1 != from2) {
300 EdgeVector::const_iterator c2 = find(
myAll.begin(),
myAll.end(), from2);
303 while (*c2 != from2 && *c2 != from1) {
320 EdgeVector::const_iterator p = find(
myAll.begin(),
myAll.end(), from);
324 if (p ==
myAll.begin()) {
336 EdgeVector::const_iterator i;
339 unsigned int noLanes = (*i)->getNumLanes();
340 for (
unsigned int k = 0; k < noLanes; k++) {
345 for (std::vector<NBNode::Crossing>::const_iterator i =
myCrossings.begin(); i !=
myCrossings.end(); i++) {
355 unsigned int noLanesEdge1 = (*i11)->getNumLanes();
356 for (
unsigned int j1 = 0; j1 < noLanesEdge1; j1++) {
357 std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
358 for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) {
359 int idx1 =
getIndex((*i11), (*i12).toEdge);
365 unsigned int noLanesEdge2 = (*i21)->getNumLanes();
366 for (
unsigned int j2 = 0; j2 < noLanesEdge2; j2++) {
367 std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
368 for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) {
369 int idx2 =
getIndex((*i21), (*i22).toEdge);
375 if ((*i11) == (*i21)) {
382 if (((*i12).tlID ==
"" && (*i22).tlID ==
"")
384 ((*i12).tlID !=
"" && (*i22).tlID !=
"")) {
390 if (!
foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
395 if ((*i12).tlID !=
"") {
411 std::pair<unsigned int, unsigned int>
413 unsigned int noLanes = 0;
414 unsigned int noLinks = 0;
415 for (EdgeVector::const_iterator i =
myIncoming.begin();
417 unsigned int noLanesEdge = (*i)->getNumLanes();
418 for (
unsigned int j = 0; j < noLanesEdge; j++) {
419 unsigned int numConnections = (
unsigned int)(*i)->getConnectionsFromLane(j).size();
420 noLinks += numConnections;
421 if (numConnections > 0) {
426 return std::make_pair(noLanes, noLinks);
432 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
434 if (to1 == 0 || to2 == 0) {
440 if (idx1 < 0 || idx2 < 0) {
451 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo,
452 bool regardNonSignalisedLowerPriority)
const {
454 if (possProhibitorTo == 0 || possProhibitedTo == 0) {
458 int possProhibitorIdx =
getIndex(possProhibitorFrom, possProhibitorTo);
459 int possProhibitedIdx =
getIndex(possProhibitedFrom, possProhibitedTo);
460 if (possProhibitorIdx < 0 || possProhibitedIdx < 0) {
466 if (!regardNonSignalisedLowerPriority) {
467 return myForbids[possProhibitorIdx][possProhibitedIdx];
470 if (!
myForbids[possProhibitorIdx][possProhibitedIdx]) {
483 int fromLane,
int pos,
const bool checkLaneFoes)
const {
485 for (std::vector<NBEdge::Connection>::iterator j = connected.begin(); j != connected.end(); j++) {
486 assert((*j).toEdge != 0);
509 for (
int j = noLanes; j-- > 0;) {
511 int size = (int) connected.size();
512 for (
int k = size; k-- > 0;) {
513 const NBEdge* to = connected[k].toEdge;
515 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
516 if ((*it_e) == from || (*it_e) == to) {
521 foes += foe ?
'1' :
'0';
538 int fromLane,
int toLane,
bool mayDefinitelyPass,
const bool checkLaneFoes)
const {
545 for (std::vector<NBNode::Crossing>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
551 unsigned int noLanes = (*i)->getNumLanes();
552 for (
int j = noLanes; j-- > 0;) {
553 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
554 int size = (int) connected.size();
555 for (
int k = size; k-- > 0;) {
556 if (mayDefinitelyPass) {
558 }
else if ((*i) == from && fromLane == j) {
562 assert(k < (
int) connected.size());
564 assert(connected[k].toEdge != 0);
568 (!checkLaneFoes ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)))
569 ||
rightTurnConflict(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane)) {
590 for (std::vector<NBNode::Crossing>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
592 for (EdgeVector::const_iterator it_e = (*i).edges.begin(); it_e != (*i).edges.end(); ++it_e) {
593 if ((*it_e) == from || (*it_e) == to) {
598 result += foes ?
'1' :
'0';
601 for (EdgeVector::const_reverse_iterator i =
myIncoming.rbegin();
604 for (
int j = (
int)(*i)->getNumLanes() - 1; j >= 0; --j) {
605 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
606 int size = (int) connected.size();
607 for (
int k = size; k-- > 0;) {
608 if ((
foes(from, to, (*i), connected[k].toEdge) &&
609 (!checkLaneFoes ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)))
610 ||
rightTurnConflict(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane)) {
624 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorToLane)
const {
625 if (to != prohibitorTo) {
640 return rightOfProhibitor ? toLane >= prohibitorToLane : toLane <= prohibitorToLane;
646 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorFromLane)
const {
647 if (from != prohibitorFrom) {
656 if ((!lefthand && fromLane <= prohibitorFromLane) ||
657 (lefthand && fromLane >= prohibitorFromLane)) {
687 for (
size_t i = 0; i < variations; i++) {
689 for (
size_t j = 0; j < variations; j++) {
717 for (
size_t idx1 = 0; idx1 <
numLinks(); idx1++) {
724 if (includePedCrossings) {
725 for (std::vector<NBNode::Crossing>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
735 const std::vector<NBEdge::Connection>& cons = from->
getConnections();
736 for (std::vector<NBEdge::Connection>::const_iterator i = cons.begin(); i != cons.end(); i++) {
738 from, (*i).toEdge, (*i).fromLane)) {
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*, size_t> 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*, size_t>::iterator it = incomingCount.begin(); it != incomingCount.end(); ++it) {
800 if (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) {
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
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
static SUMOReal getCWAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the distance of second angle from first angle clockwise.
void computeLeftOutgoingLinkCrossings(bool leftHanded, NBEdge *from, NBEdge *to)
std::vector< bool > LinkInfoCont
bool mustBrakeForCrossing(const NBEdge *const from, const NBEdge *const to, const NBNode::Crossing &crossing) const
Returns the information whether the described flow must brake for the given crossing.
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::ostream & operator<<(std::ostream &os, const NBRequest &r)
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.
SUMOReal getEndAngle() const
Returns the angle at the end of the edge The angle is computed in computeAngle()
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
const EdgeVector & myOutgoing
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
void writeLogic(std::string key, OutputDevice &into, const bool checkLaneFoes) const
std::vector< Connection > getConnectionsFromLane(unsigned int lane) const
Returns connections from a given lane.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
std::string getResponseString(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.
The link is a (hard) left direction.
#define WRITE_WARNING(msg)
size_t distanceCounterClockwise(NBEdge *from, NBEdge *to)
const EdgeVector & myIncoming
static OptionsCont & getOptions()
Retrieves the options.
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
const std::string & getID() const
Returns the id.
bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane) const
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
void buildBitfieldLogic(bool leftHanded)
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...
unsigned int getNumLanes() const
Returns the number of lanes.
SumoXMLNodeType getType() const
Returns the type of this node.
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Information within the junction logic which internal lanes block external.
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
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
The link is a partial right direction.
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)
void setBlocking(bool leftHanded, NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
NBNode * getToNode() const
Returns the destination node of the edge.
size_t numLinks() const
return to total number of edge-to-edge connections of this request-logic
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
NBEdge * getTo() const
returns the to-edge (end of the connection)
const std::vector< NBNode::Crossing > & myCrossings
EdgeVector edges
The edges being crossed.
Represents a single node (junction) during network building.
bool hasSignalisedConnectionTo(const NBEdge *const e) const
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.
static size_t myGoodBuilds
static SUMOReal relAngle(SUMOReal angle1, SUMOReal angle2)
SUMOReal getStartAngle() const
Returns the angle at the start of the edge The angle is computed in computeAngle() ...
Information whether the detector shall be continued on the folowing lanes.
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.
std::pair< unsigned int, unsigned int > getSizes() const
returns the number of the junction's lanes and the number of the junction's links in respect...
void computeRightOutgoingLinkCrossings(bool leftHanded, NBEdge *from, NBEdge *to)
SUMOReal getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing) const
Returns the representation of the described stream's direction.
NBNode * getFromNode() const
Returns the origin node of the edge.