49 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
59 for (std::vector<NBEdge*>::const_iterator k = incoming.begin(); k != incoming.end(); ++k) {
60 (*k)->setTurningDestination(
nullptr);
62 std::vector<Combination> combinations;
64 for (std::vector<NBEdge*>::const_iterator j = outgoing.begin(); j != outgoing.end(); ++j) {
66 for (std::vector<NBEdge*>::const_iterator k = incoming.begin(); k != incoming.end(); ++k) {
70 if (signedAngle > 0 && signedAngle < 177 && e->getGeometry().back().distanceTo2D(outedge->
getGeometry().front()) <
POSITION_EPS) {
75 double angle = fabs(signedAngle);
104 combinations.push_back(c);
109 std::set<NBEdge*> seen;
111 for (std::vector<Combination>::const_iterator j = combinations.begin(); j != combinations.end(); ++j) {
113 if (seen.find((*j).from) != seen.end() || seen.find((*j).to) != seen.end()) {
115 if ((*j).angle > 360 && warn) {
116 WRITE_WARNING(
"Ambiguity in turnarounds computation at junction '" + node->
getID() +
"'.");
123 seen.insert((*j).from);
124 seen.insert((*j).to);
126 bool onlyPossible = (*j).from->getConnections().size() != 0 && !(*j).from->isConnectedTo((*j).to);
128 (*j).from->setTurningDestination((*j).to, onlyPossible);
138 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
139 i->second->sortEdges(useNodeShape);
146 const std::vector<NBEdge*>::iterator& i1,
147 const std::vector<NBEdge*>::iterator& i2) {
165 validateRailCrossings(nc, tlc);
167 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
175 bool waterway =
true;
176 for (EdgeVector::const_iterator i = n->
getEdges().begin(); i != n->
getEdges().end(); ++i) {
200 for (EdgeVector::const_iterator j = i + 1; j != n->
myIncomingEdges.end(); j++) {
207 const double s1 = (*i)->getSpeed();
208 const double s2 = (*j)->getSpeed();
209 const int p1 = (*i)->getPriority();
210 const int p2 = (*j)->getPriority();
211 if (fabs(s1 - s2) > (9.5 / 3.6) ||
MAX2(s1, s2) >= rightBeforeLeftSpeed || p1 != p2) {
226 for (std::map<std::string, NBNode*>::const_iterator i = nc.
begin(); i != nc.
end(); ++i) {
231 int numNonRailway = 0;
232 int numNonRailwayNonPed = 0;
237 numNonRailwayNonPed++;
248 if (numNonRailway == 0 || numRailway == 0) {
251 }
else if (numNonRailwayNonPed > 2) {
253 WRITE_WARNING(
"Converting invalid rail_crossing to traffic_light at junction '" + n->
getID() +
"'");
273 int numNonRailway = 0;
281 return numRailway > 0 && numNonRailway == 0;
289 for (
const auto& node : nc) {
291 for (
NBEdge*
const edge : node.second->myAllEdges) {
294 node.second->markBentPriority(
false);
296 if (node.second->myIncomingEdges.size() == 1 && node.second->myOutgoingEdges.size() == 1) {
303 e->setJunctionPriority(node.second, e->getPriority());
306 setPriorityJunctionPriorities(*node.second);
325 NBEdge* best = incoming[0];
326 while (incoming.size() > 0 && samePriority(best, incoming[0])) {
327 bestIncoming.push_back(*incoming.begin());
328 incoming.erase(incoming.begin());
331 assert(outgoing.size() != 0);
335 while (outgoing.size() > 0 && samePriority(best, outgoing[0])) {
336 bestOutgoing.push_back(*outgoing.begin());
337 outgoing.erase(outgoing.begin());
340 const bool mainDirectionExplicit = (
342 && (incoming.size() == 0 || bestIncoming[0]->getPriority() > incoming[0]->getPriority())
344 && (outgoing.size() == 0 || bestOutgoing[0]->getPriority() > outgoing[0]->getPriority())
345 && !bestIncoming[0]->isTurningDirectionAt(bestOutgoing[0]));
349 EdgeVector::iterator i;
350 std::map<NBEdge*, NBEdge*> counterIncomingEdges;
351 std::map<NBEdge*, NBEdge*> counterOutgoingEdges;
354 for (i = bestIncoming.begin(); i != bestIncoming.end(); ++i) {
356 counterIncomingEdges[*i] = *incoming.begin();
358 counterOutgoingEdges[*i] = *outgoing.begin();
363 if (bestIncoming.size() == 1) {
365 NBEdge* best1 = extractAndMarkFirst(n, bestIncoming);
366 if (!mainDirectionExplicit && counterIncomingEdges.find(best1) != counterIncomingEdges.end()) {
370 NBEdge* s = counterIncomingEdges.find(best1)->second;
372 if (minAngleDiff > 180 - 45
373 || (minAngleDiff > 75 && s->
getPriority() == best1->
getPriority() && hasDifferentPriorities(incoming, best1))) {
377 markBestParallel(n, best1,
nullptr);
378 assert(bestOutgoing.size() != 0);
382 NBEdge* bestOut = extractAndMarkFirst(n, bestOutgoing);
383 if (!mainDirectionExplicit && counterOutgoingEdges.find(bestOut) != counterOutgoingEdges.end()) {
384 NBEdge* s = counterOutgoingEdges.find(bestOut)->second;
397 double bestAngle = 0;
398 NBEdge* bestFirst =
nullptr;
399 NBEdge* bestSecond =
nullptr;
400 bool hadBest =
false;
401 for (i = bestIncoming.begin(); i != bestIncoming.end(); ++i) {
402 EdgeVector::iterator j;
408 for (j = i + 1; j != bestIncoming.end(); ++j) {
415 if (!hadBest || angle > bestAngle) {
425 if (bestOutgoing.size() != 0) {
426 extractAndMarkFirst(n, bestOutgoing);
430 if (bestOutgoing.size() != 0) {
431 extractAndMarkFirst(n, bestOutgoing);
434 markBestParallel(n, bestFirst, bestSecond);
442 const double a2 = bestSecond ==
nullptr ? a1 : bestSecond->
getAngleAtNode(&n);
451 && (p1 & perm) == 0 && (p2 & perm) == 0) {
452 e->setJunctionPriority(&n, 1);
487 if (edges.size() < 2) {
490 int prio = edges[0] == excluded ? edges[1]->
getPriority() : edges[0]->getPriority();
491 for (
auto e : edges) {
502 myOrdering = ordering;
505 rotate(myOrdering.begin(), std::find(myOrdering.begin(), myOrdering.end(), ordering.front()), myOrdering.end());
static double getMinAngleDiff(double angle1, double angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
bool isSimpleContinuation(bool checkLaneNumbers=true, bool checkWidth=false) const
check if node is a simple continuation
static void validateRailCrossings(NBNodeCont &nc, NBTrafficLightLogicCont &tlc)
Checks rail_crossing for validity.
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
EdgeVector getIncomingEdges() const
Returns the list of incoming edges unsorted.
static void markBestParallel(const NBNode &n, NBEdge *bestFirst, NBEdge *bestSecond)
set priority for edges that are parallel to the best edges
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
static double normRelAngle(double angle1, double angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
SumoXMLNodeType myType
The type of the junction.
A container for traffic light definitions and built programs.
int getPriority() const
Returns the priority of the edge.
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.
Class to sort edges by their angle in relation to the given edge.
The base class for traffic light logic definitions.
void markBentPriority(bool isBent)
mark whether a priority road turns at this node
const std::string & getID() const
Returns the id.
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
static void sortNodesEdges(NBNodeCont &nc, bool useNodeShape=false)
Sorts a node's edges clockwise regarding driving direction.
Stores the information about the angle between an incoming ("from") and an outgoing ("to") edge...
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
The link is a straight direction.
static bool hasDifferentPriorities(const EdgeVector &edges, const NBEdge *excluded)
return whether the priorite attribute can be used to distinguish the edges
bool myTypeWasGuessed
whether the node type was guessed rather than loaded
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 StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
int getNumLanes() const
Returns the number of lanes.
classes which drive on tracks
static void computeEdgePriorities(NBNodeCont &nc)
Computes edge priorities within a node.
bool isWaterway(SVCPermissions permissions)
Returns whether an edge with the given permission is a waterway edge.
T get(const std::string &str) const
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node) ...
bool geometryLike() const
whether this is structurally similar to a geometry node
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
crossing_by_junction_angle_sorter(const NBNode *node, const EdgeVector &ordering)
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
EdgeVector myIncomingEdges
Vector of incoming edges.
static void computeTurnDirectionsForNode(NBNode *node, bool warn)
Computes turnaround destinations for all incoming edges of the given nodes (if any) ...
static bool samePriority(const NBEdge *const e1, const NBEdge *const e2)
Returns whether both edges have the same priority.
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
double getSpeed() const
Returns the speed allowed on this edge.
const PositionVector & getGeometry() const
Returns the geometry of the edge.
EdgeVector myOutgoingEdges
Vector of outgoing edges.
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
void setJunctionPriority(const NBNode *const node, int prio)
Sets the junction priority of the edge.
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Represents a single node (junction) during network building.
static void computeTurnDirections(NBNodeCont &nc, bool warn=true)
Computes turnaround destinations for all edges (if exist)
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
static bool isRailwayNode(const NBNode *n)
whether the given node only has rail edges
static NBEdge * extractAndMarkFirst(NBNode &n, std::vector< NBEdge *> &s, int prio=1)
Sets the priorites in case of a priority junction.
NBEdge * getOppositeIncoming(NBEdge *e) const
returns the opposite incoming edge of certain edge
Sorts "Combination"s by decreasing angle.
static void setPriorityJunctionPriorities(NBNode &n)
Sets the priorites in case of a priority junction.
NBNode * getFromNode() const
Returns the origin node of the edge.
Container for nodes during the netbuilding process.
static void computeNodeTypes(NBNodeCont &nc, NBTrafficLightLogicCont &tlc)
Computes node types.
A traffic light logics which must be computed (only nodes/edges are given)
NBNode * getToNode() const
Returns the destination node of the edge.