41#define DEBUGCOND (n.getID() == "C")
43#define DEBUGCOND2(obj) (true)
53 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
63 for (std::vector<NBEdge*>::const_iterator k = incoming.begin(); k != incoming.end(); ++k) {
64 (*k)->setTurningDestination(
nullptr);
66 std::vector<Combination> combinations;
68 for (
NBEdge* outedge : outgoing) {
69 for (
NBEdge* e : incoming) {
72 if (signedAngle > 0 && signedAngle < 177 && e->getGeometry().back().distanceTo2D(outedge->getGeometry().front()) < POSITION_EPS) {
75#ifdef DEBUG_TURNAROUNDS
77 std::cout <<
"incoming=" << e->getID() <<
" outgoing=" << outedge->getID() <<
" signedAngle=" << signedAngle <<
" skipped\n";
82 double angle = fabs(signedAngle);
83#ifdef DEBUG_TURNAROUNDS
85 std::cout <<
"incoming=" << e->getID() <<
" outgoing=" << outedge->getID() <<
" relAngle=" <<
NBHelpers::relAngle(e->getAngleAtNode(node), outedge->getAngleAtNode(node)) <<
"\n";
88 const bool badPermissions = ((outedge->getPermissions() & e->getPermissions() & ~SVC_PEDESTRIAN) == 0
90 && outedge->getPermissions() != e->getPermissions());
91 if (e->getFromNode() == outedge->getToNode()
92 && (angle > 120 || e->getFromNode()->getPosition() == e->getToNode()->getPosition())
113#ifdef DEBUG_TURNAROUNDS
115 std::cout <<
" inFA=" << inFA <<
" outFA=" << outFA <<
" sFA=" << signedFarAngle <<
"\n";
118 if (signedFarAngle > -160) {
125 if (badPermissions) {
133 combinations.push_back(c);
138 std::set<NBEdge*> seen;
139#ifdef DEBUG_TURNAROUNDS
141 std::cout <<
"check combinations at " << node->
getID() <<
"\n";
144 for (std::vector<Combination>::const_iterator j = combinations.begin(); j != combinations.end(); ++j) {
145#ifdef DEBUG_TURNAROUNDS
147 std::cout <<
" from=" << (*j).from->getID() <<
" to=" << (*j).to->getID() <<
" a=" << (*j).angle <<
"\n";
150 if (seen.find((*j).from) != seen.end() || seen.find((*j).to) != seen.end()) {
152 if ((*j).angle > 360 && warn) {
160 seen.insert((*j).from);
161 seen.insert((*j).to);
163 bool onlyPossible = (*j).from->getConnections().size() != 0 && !(*j).from->isConnectedTo((*j).to);
164#ifdef DEBUG_TURNAROUNDS
166 std::cout <<
" setTurningDestination from=" << (*j).from->getID() <<
" to=" << (*j).to->getID() <<
" onlyPossible=" << onlyPossible <<
"\n";
169 (*j).from->setTurningDestination((*j).to, onlyPossible);
185 if (dist <= length) {
205 if (dist <= length) {
230 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
231 i->second->sortEdges(useNodeShape);
238 const std::vector<NBEdge*>::iterator& i1,
239 const std::vector<NBEdge*>::iterator& i2) {
259 const double rightBeforeLeftSpeed = oc.
getFloat(
"junctions.right-before-left.speed-threshold");
260 for (
const auto& nodeIt : nc) {
261 NBNode*
const n = nodeIt.second;
274 bool waterway =
true;
304 for (EdgeVector::const_iterator j = i + 1; j != n->
myIncomingEdges.end(); j++) {
311 const double s1 = (*i)->getSpeed();
312 const double s2 = (*j)->getSpeed();
313 const int p1 = (*i)->getPriority();
314 const int p2 = (*j)->getPriority();
315 if (fabs(s1 - s2) > (9.5 / 3.6) ||
MAX2(s1, s2) >= rightBeforeLeftSpeed || p1 != p2) {
330 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
335 int numNonRailIn = 0;
336 int numNonRailOut = 0;
337 std::set<const NBNode*> nonRailNodes;
338 int numNonRailwayNonPed = 0;
343 numNonRailwayNonPed++;
345 nonRailNodes.insert(e->getFromNode());
353 nonRailNodes.insert(e->getToNode());
356 if (numNonRailIn == 0 || numNonRailOut == 0 || numRailway == 0) {
360 }
else if (numNonRailwayNonPed > 2 || nonRailNodes.size() > 2) {
362 WRITE_WARNINGF(
TL(
"Converting invalid rail_crossing to traffic_light at junction '%'."), n->
getID());
381 bool hasRailway =
false;
397 for (
const auto& node : nc) {
399 for (
NBEdge*
const edge : node.second->myAllEdges) {
402 node.second->markBentPriority(
false);
404 if (node.second->myIncomingEdges.size() == 1 && node.second->myOutgoingEdges.size() == 1) {
413 for (
NBEdge* e : node.second->getIncomingEdges()) {
414 e->setJunctionPriority(node.second, e->getPriority());
429 int minPrio = std::numeric_limits<int>::max();
430 int maxPrio = -std::numeric_limits<int>::max();
431 int maxNumLanes = -std::numeric_limits<int>::max();
432 double maxSpeed = -std::numeric_limits<double>::max();
437 minPrio =
MIN2(minPrio, edge->getPriority());
438 maxPrio =
MAX2(maxPrio, edge->getPriority());
439 maxNumLanes =
MAX2(maxNumLanes, edge->getNumLanes());
440 maxSpeed =
MAX2(maxSpeed, edge->getSpeed());
450 NBEdge* bestIn = incoming[0];
451 while (incoming.size() > 0 && (forceStraight ||
samePriority(bestIn, incoming[0]))) {
452 bestIncoming.push_back(*incoming.begin());
453 incoming.erase(incoming.begin());
456 assert(outgoing.size() != 0);
459 const NBEdge*
const firstOut = outgoing[0];
460 while (outgoing.size() > 0 && (forceStraight ||
samePriority(firstOut, outgoing[0]))) {
461 bestOutgoing.push_back(*outgoing.begin());
462 outgoing.erase(outgoing.begin());
465 const bool mainDirectionExplicit = (
467 && (incoming.size() == 0 || bestIncoming[0]->getPriority() > incoming[0]->getPriority())
469 && (outgoing.size() == 0 || bestOutgoing[0]->getPriority() > outgoing[0]->getPriority())
470 && !bestIncoming[0]->isTurningDirectionAt(bestOutgoing[0]));
474 EdgeVector::iterator i;
475 std::map<NBEdge*, NBEdge*> counterIncomingEdges;
476 std::map<NBEdge*, NBEdge*> counterOutgoingEdges;
479 for (i = bestIncoming.begin(); i != bestIncoming.end(); ++i) {
481 counterIncomingEdges[*i] = *incoming.begin();
483 counterOutgoingEdges[*i] = *outgoing.begin();
485#ifdef DEBUG_SETPRIORITIES
487 std::map<std::string, std::string> tmp1;
488 for (
auto item : counterIncomingEdges) {
489 tmp1[item.first->getID()] = item.second->getID();
491 std::map<std::string, std::string> tmp2;
492 for (
auto item : counterOutgoingEdges) {
493 tmp2[item.first->getID()] = item.second->getID();
495 std::cout <<
"n=" << n.
getID() <<
" bestIn=" << bestIn->
getID() <<
" bestOut=" <<
toString(bestOutgoing)
496 <<
" counterBest=" << counterIncomingEdges.find(bestIncoming[0])->second->getID()
497 <<
" mainExplicit=" << mainDirectionExplicit
498 <<
" forceStraight=" << forceStraight
499 <<
"\n bestIncoming=" <<
toString(bestIncoming) <<
" allIncoming=" <<
toString(incoming)
500 <<
"\n bestOutgoing=" <<
toString(bestOutgoing) <<
" allOutgoing=" <<
toString(outgoing)
501 <<
"\n counterIncomingEdges=" <<
toString(tmp1)
502 <<
"\n counterOutgoingEdges=" <<
toString(tmp2)
512 if (bestIncoming.size() == 1) {
515 if (!mainDirectionExplicit && counterIncomingEdges.find(best1) != counterIncomingEdges.end()) {
519 NBEdge* s = counterIncomingEdges.find(best1)->second;
521 if (minAngleDiff > 180 - 45
527 assert(bestOutgoing.size() != 0);
532 if (!mainDirectionExplicit && counterOutgoingEdges.find(bestOut) != counterOutgoingEdges.end()) {
533 NBEdge* s = counterOutgoingEdges.find(bestOut)->second;
539#ifdef DEBUG_SETPRIORITIES
541 std::cout <<
" best1=" << best1->
getID() <<
" bestOut=" << bestOut->
getID() <<
" bestOutgoing=" <<
toString(bestOutgoing) <<
" mainDirectionExplicit=" << mainDirectionExplicit <<
" isBent=" << isBent <<
"\n";
544 if (isBent && hasTLS && !forceStraight) {
557 double bestAngle = -1;
558 NBEdge* bestFirst =
nullptr;
559 NBEdge* bestSecond =
nullptr;
560 for (i = bestIncoming.begin(); i != bestIncoming.end(); ++i) {
561 EdgeVector::iterator j;
567 for (j = i + 1; j != bestIncoming.end(); ++j) {
573 double score = forceStraight ?
getScore(t1, t2, minPrio, maxPrio, maxNumLanes, maxSpeed) : 0;
575 if (angle > bestAngle) {
577 bestAngle =
MAX2(angle, bestAngle);
585#ifdef DEBUG_SETPRIORITIES
587 std::cout <<
" bestFirst=" << bestFirst->
getID() <<
" bestOutgoingFirst=" <<
toString(bestOutgoing) <<
"\n";
590 if (bestOutgoing.size() != 0) {
595#ifdef DEBUG_SETPRIORITIES
597 std::cout <<
" bestSecond=" << bestSecond->
getID() <<
" bestOutgoingSecond=" <<
toString(bestOutgoing) <<
"\n";
600 if (bestOutgoing.size() != 0) {
604 if (isBent && hasTLS && !forceStraight) {
616 double normPrio1 = 1;
617 double normPrio2 = 1;
618 if (minPrio != maxPrio) {
619 normPrio1 = ((e1->
getPriority() - minPrio) / (maxPrio - minPrio)) * 0.9 + 0.1;
620 normPrio2 = ((e2->
getPriority() - minPrio) / (maxPrio - minPrio)) * 0.9 + 0.1;
634 const double a2 = bestSecond ==
nullptr ? a1 : bestSecond->
getAngleAtNode(&n);
643 && (p1 & perm) == 0 && (p2 & perm) == 0) {
644 e->setJunctionPriority(&n, 1);
679 if (edges.size() < 2) {
682 int prio = edges[0] == excluded ? edges[1]->
getPriority() : edges[0]->getPriority();
683 for (
auto e : edges) {
#define WRITE_WARNINGF(...)
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
bool isWaterway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a waterway edge.
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SVC_RAIL_CLASSES
classes which drive on tracks
@ SVC_TAXI
vehicle is a taxi
@ SVC_PEDESTRIAN
pedestrian
@ STRAIGHT
The link is a straight direction.
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static double legacyDegree(const double angle, const bool positive=false)
static double getMinAngleDiff(double angle1, double angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Class to sort edges by their angle in relation to the given edge.
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
NBNode * getToNode() const
Returns the destination node of the edge.
const PositionVector & getGeometry() const
Returns the geometry of the edge.
double getSpeed() const
Returns the speed allowed on this edge.
const std::string & getID() const
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
int getNumLanes() const
Returns the number of lanes.
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
int getPriority() const
Returns the priority of the edge.
void setJunctionPriority(const NBNode *const node, int prio)
Sets the junction priority of the edge.
static double getScore(const NBEdge *e1, const NBEdge *e2, int minPrio, int maxPrio, int maxNumLanes, double maxSpeed)
score pair of edges for multi-criteria evaluatoin of angle, priority, laneNumber and speed
static void markBestParallel(const NBNode &n, NBEdge *bestFirst, NBEdge *bestSecond)
set priority for edges that are parallel to the best edges
static NBEdge * extractAndMarkFirst(NBNode &n, std::vector< NBEdge * > &s, int prio=1)
Sets the priorites in case of a priority junction.
static bool hasDifferentPriorities(const EdgeVector &edges, const NBEdge *excluded)
return whether the priorite attribute can be used to distinguish the edges
static void computeEdgePriorities(NBNodeCont &nc)
Computes edge priorities within a node.
static void setPriorityJunctionPriorities(NBNode &n, bool forceStraight=false)
Sets the priorites in case of a priority junction.
static bool samePriority(const NBEdge *const e1, const NBEdge *const e2)
Returns whether both edges have the same priority.
static double relAngle(double angle1, double angle2)
computes the relative angle between the two angles
static double normRelAngle(double angle1, double angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Container for nodes during the netbuilding process.
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
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.
bool isSimpleContinuation(bool checkLaneNumbers=true, bool checkWidth=false) const
check if node is a simple continuation
bool myTypeWasGuessed
whether the node type was guessed rather than loaded
SumoXMLNodeType myType
The type of the junction.
EdgeVector myOutgoingEdges
Vector of outgoing edges.
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
EdgeVector myAllEdges
Vector of incoming and outgoing edges.
bool isDistrict() const
check if node is a district
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node)
void markBentPriority(bool isBent)
mark whether a priority road turns at this node
bool geometryLike() const
whether this is structurally similar to a geometry node
bool isNearDistrict() const
@chech if node is near district
EdgeVector myIncomingEdges
Vector of incoming edges.
bool isTLControlled() const
Returns whether this node is controlled by any tls.
NBEdge * getOppositeIncoming(NBEdge *e) const
returns the opposite incoming edge of certain edge
static bool isRailwayNode(const NBNode *n)
whether the given node only has rail edges
static void computeNodeTypes(NBNodeCont &nc, NBTrafficLightLogicCont &tlc)
Computes node types.
static void validateRailCrossings(NBNodeCont &nc, NBTrafficLightLogicCont &tlc)
Checks rail_crossing for validity.
crossing_by_junction_angle_sorter(const NBNode *node, const EdgeVector &ordering)
static void swapWhenReversed(const NBNode *const n, const std::vector< NBEdge * >::iterator &i1, const std::vector< NBEdge * >::iterator &i2)
Assures correct order for same-angle opposite-direction edges.
static void sortNodesEdges(NBNodeCont &nc, bool useNodeShape=false)
Sorts a node's edges clockwise regarding driving direction.
A traffic light logics which must be computed (only nodes/edges are given)
The base class for traffic light logic definitions.
A container for traffic light definitions and built programs.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
Sorts "Combination"s by decreasing angle.
static double getFarAngleAtNode(const NBEdge *e, const NBNode *n, double dist=50)
compute angle to junction at a point further away
static void computeTurnDirections(NBNodeCont &nc, bool warn=true)
Computes turnaround destinations for all edges (if exist)
static void computeTurnDirectionsForNode(NBNode *node, bool warn)
Computes turnaround destinations for all incoming edges of the given nodes (if any)
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
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.
bool isInStringVector(const std::string &optionName, const std::string &itemName) const
Returns the named option is a list of string values containing the specified item.
A point in 2D or 3D with translation and scaling methods.
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position (in radians bet...
double length() const
Returns the length.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Stores the information about the angle between an incoming ("from") and an outgoing ("to") edge.