Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBAlgorithms.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// Algorithms for network computation
20/****************************************************************************/
21#pragma once
22#include <config.h>
23
24#include <map>
25#include "NBEdgeCont.h"
26#include "NBNodeCont.h"
27
28// ===========================================================================
29// class declarations
30// ===========================================================================
31class NBEdge;
32class NBNode;
33
34// ===========================================================================
35// class definitions
36// ===========================================================================
37// ---------------------------------------------------------------------------
38// NBTurningDirectionsComputer
39// ---------------------------------------------------------------------------
40/* @class NBTurningDirectionsComputer
41 * @brief Computes turnaround destinations for all edges (if exist)
42 */
44public:
49 static void computeTurnDirections(NBNodeCont& nc, bool warn = true);
50
56 static void computeTurnDirectionsForNode(NBNode* node, bool warn);
57
59 static double getFarAngleAtNode(const NBEdge* e, const NBNode* n, double dist = 50);
60
61private:
68 struct Combination {
71 double angle;
72 };
73
74
79 public:
81 int operator()(const Combination& c1, const Combination& c2) const {
82 if (c1.angle != c2.angle) {
83 return c1.angle > c2.angle;
84 }
85 if (c1.from != c2.from) {
86 if (c1.to == c2.to && c1.from->getPermissions() != c2.from->getPermissions()) {
87 if (c1.from->getPermissions() == c1.to->getPermissions()) {
88 return true;
89 } else if (c2.from->getPermissions() == c1.to->getPermissions()) {
90 return false;
91 }
92 }
93 return c1.from->getID() < c2.from->getID();
94 }
95 if (c1.to->getPermissions() != c2.to->getPermissions()) {
96 if (c1.to->getPermissions() == c1.from->getPermissions()) {
97 return true;
98 } else if (c2.to->getPermissions() == c1.from->getPermissions()) {
99 return false;
100 }
101 }
102 return c1.to->getID() < c2.to->getID();
103 }
104 };
105};
106
107
108
109// ---------------------------------------------------------------------------
110// NBNodesEdgesSorter
111// ---------------------------------------------------------------------------
112/* @class NBNodesEdgesSorter
113 * @brief Sorts a node's edges clockwise regarding driving direction
114 */
116public:
121 static void sortNodesEdges(NBNodeCont& nc, bool useNodeShape = false);
122
128 public:
129 explicit crossing_by_junction_angle_sorter(const NBNode* node, const EdgeVector& ordering);
130
131 int operator()(const std::unique_ptr<NBNode::Crossing>& c1, const std::unique_ptr<NBNode::Crossing>& c2) const {
132 const int r1 = getMinRank(c1->edges);
133 const int r2 = getMinRank(c2->edges);
134 if (r1 == r2) {
135 return c1->edges.size() > c2->edges.size();
136 } else {
137 return (int)(r1 < r2);
138 }
139 }
140
141 private:
143 int getMinRank(const EdgeVector& e) const {
144 int result = (int)myOrdering.size();
145 for (EdgeVector::const_iterator it = e.begin(); it != e.end(); ++it) {
146 int rank = (int)std::distance(myOrdering.begin(), std::find(myOrdering.begin(), myOrdering.end(), *it));
147 result = MIN2(result, rank);
148 }
149 return result;
150 }
151
152 private:
154 };
155
161 static void swapWhenReversed(const NBNode* const n,
162 const std::vector<NBEdge*>::iterator& i1,
163 const std::vector<NBEdge*>::iterator& i2);
164
165
170 public:
172 int operator()(NBEdge* e1, NBEdge* e2) const {
173 const double a1 = e1->getAngleAtNodeNormalized(myNode);
174 const double a2 = e2->getAngleAtNodeNormalized(myNode);
175 return a1 < a2 || (a1 == a2 && e1->getNumericalID() < e2->getNumericalID());
176 }
177
178 private:
181
182 };
183
184};
185
186
187
188// ---------------------------------------------------------------------------
189// NBNodeTypeComputer
190// ---------------------------------------------------------------------------
191/* @class NBNodeTypeComputer
192 * @brief Computes node types
193 */
195public:
200
205
207 static bool isRailwayNode(const NBNode* n);
208};
209
210
211
212// ---------------------------------------------------------------------------
213// NBEdgePriorityComputer
214// ---------------------------------------------------------------------------
215/* @class NBEdgePriorityComputer
216 * @brief Computes edge priorities within a node
217 */
219public:
223 static void computeEdgePriorities(NBNodeCont& nc);
224
225private:
229 static void setPriorityJunctionPriorities(NBNode& n, bool forceStraight = false);
230
232 static double getScore(const NBEdge* e1, const NBEdge* e2, int minPrio, int maxPrio, int maxNumLanes, double maxSpeed);
233
235 static void markBestParallel(const NBNode& n, NBEdge* bestFirst, NBEdge* bestSecond);
236
243 static NBEdge* extractAndMarkFirst(NBNode& n, std::vector<NBEdge*>& s, int prio = 1);
244
250 static bool samePriority(const NBEdge* const e1, const NBEdge* const e2);
251
253 static bool hasDifferentPriorities(const EdgeVector& edges, const NBEdge* excluded);
254
255};
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition NBCont.h:42
T MIN2(T a, T b)
Definition StdDefs.h:76
The representation of a single edge during network building.
Definition NBEdge.h:92
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition NBEdge.cpp:4379
int getNumericalID() const
Returns the index (numeric id) of the edge.
Definition NBEdge.h:1510
const std::string & getID() const
Definition NBEdge.h:1528
double getAngleAtNodeNormalized(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node and disregards edge direction.
Definition NBEdge.cpp:2169
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.
Container for nodes during the netbuilding process.
Definition NBNodeCont.h:57
Represents a single node (junction) during network building.
Definition NBNode.h:66
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.
Sorts crossings by minimum clockwise clockwise edge angle. Use the ordering found in myAllEdges of th...
int getMinRank(const EdgeVector &e) const
retrieves the minimum index in myAllEdges
int operator()(const std::unique_ptr< NBNode::Crossing > &c1, const std::unique_ptr< NBNode::Crossing > &c2) const
Sorts incoming and outgoing edges clockwise around the given node.
int operator()(NBEdge *e1, NBEdge *e2) const
NBNode * myNode
The node to compute the relative angle of.
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 container for traffic light definitions and built programs.
Sorts "Combination"s by decreasing angle.
int operator()(const Combination &c1, const Combination &c2) const
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)
Stores the information about the angle between an incoming ("from") and an outgoing ("to") edge.