Eclipse SUMO - Simulation of Urban MObility
NBAlgorithms.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Algorithms for network computation
17 /****************************************************************************/
18 #ifndef NBAlgorithms_h
19 #define NBAlgorithms_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <map>
28 #include "NBEdgeCont.h"
29 #include "NBNodeCont.h"
30 
31 // ===========================================================================
32 // class declarations
33 // ===========================================================================
34 class NBEdge;
35 class NBNode;
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
40 // ---------------------------------------------------------------------------
41 // NBTurningDirectionsComputer
42 // ---------------------------------------------------------------------------
43 /* @class NBTurningDirectionsComputer
44  * @brief Computes turnaround destinations for all edges (if exist)
45  */
47 public:
52  static void computeTurnDirections(NBNodeCont& nc, bool warn = true);
53 
59  static void computeTurnDirectionsForNode(NBNode* node, bool warn);
60 
61 private:
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  return c1.from->getID() < c2.from->getID();
87  }
88  return c1.to->getID() < c2.to->getID();
89  }
90  };
91 };
92 
93 
94 
95 // ---------------------------------------------------------------------------
96 // NBNodesEdgesSorter
97 // ---------------------------------------------------------------------------
98 /* @class NBNodesEdgesSorter
99  * @brief Sorts a node's edges clockwise regarding driving direction
100  */
102 public:
107  static void sortNodesEdges(NBNodeCont& nc, bool useNodeShape = false);
108 
114  public:
115  explicit crossing_by_junction_angle_sorter(const NBNode* node, const EdgeVector& ordering);
116 
117  int operator()(const NBNode::Crossing* c1, const NBNode::Crossing* c2) const {
118  const int r1 = getMinRank(c1->edges);
119  const int r2 = getMinRank(c2->edges);
120  if (r1 == r2) {
121  return c1->edges.size() > c2->edges.size();
122  } else {
123  return (int)(r1 < r2);
124  }
125  }
126 
127  private:
129  int getMinRank(const EdgeVector& e) const {
130  int result = (int)myOrdering.size();
131  for (EdgeVector::const_iterator it = e.begin(); it != e.end(); ++it) {
132  int rank = (int)std::distance(myOrdering.begin(), std::find(myOrdering.begin(), myOrdering.end(), *it));
133  result = MIN2(result, rank);
134  }
135  return result;
136  }
137 
138  private:
140 
141  private:
144 
145  };
151  static void swapWhenReversed(const NBNode* const n,
152  const std::vector<NBEdge*>::iterator& i1,
153  const std::vector<NBEdge*>::iterator& i2);
154 
155 
160  public:
162  int operator()(NBEdge* e1, NBEdge* e2) const {
163  return getConvAngle(e1) < getConvAngle(e2);
164  }
165 
166  protected:
168  double getConvAngle(NBEdge* e) const {
169  double angle = e->getAngleAtNode(myNode);
170  if (angle < 0.) {
171  angle = 360. + angle;
172  }
173  // convert angle if the edge is an outgoing edge
174  if (e->getFromNode() == myNode) {
175  angle += (double) 180.;
176  if (angle >= (double) 360.) {
177  angle -= (double) 360.;
178  }
179  }
180  if (angle < 0.1 || angle > 359.9) {
181  angle = (double) 0.;
182  }
183  assert(angle >= 0 && angle < (double)360);
184  return angle;
185  }
186 
187  private:
190 
191  };
192 
193 };
194 
195 
196 
197 // ---------------------------------------------------------------------------
198 // NBNodeTypeComputer
199 // ---------------------------------------------------------------------------
200 /* @class NBNodeTypeComputer
201  * @brief Computes node types
202  */
204 public:
208  static void computeNodeTypes(NBNodeCont& nc, NBTrafficLightLogicCont& tlc);
209 
214 
216  static bool isRailwayNode(const NBNode* n);
217 };
218 
219 
220 
221 // ---------------------------------------------------------------------------
222 // NBEdgePriorityComputer
223 // ---------------------------------------------------------------------------
224 /* @class NBEdgePriorityComputer
225  * @brief Computes edge priorities within a node
226  */
228 public:
232  static void computeEdgePriorities(NBNodeCont& nc);
233 
234 private:
238  static void setPriorityJunctionPriorities(NBNode& n);
239 
241  static void markBestParallel(const NBNode& n, NBEdge* bestFirst, NBEdge* bestSecond);
242 
249  static NBEdge* extractAndMarkFirst(NBNode& n, std::vector<NBEdge*>& s, int prio = 1);
250 
256  static bool samePriority(const NBEdge* const e1, const NBEdge* const e2);
257 
259  static bool hasDifferentPriorities(const EdgeVector& edges, const NBEdge* excluded);
260 
261 };
262 
263 #endif
264 
265 /****************************************************************************/
266 
NBNodeTypeComputer::validateRailCrossings
static void validateRailCrossings(NBNodeCont &nc, NBTrafficLightLogicCont &tlc)
Checks rail_crossing for validity.
Definition: NBAlgorithms.cpp:225
NBNodesEdgesSorter::crossing_by_junction_angle_sorter::operator()
int operator()(const NBNode::Crossing *c1, const NBNode::Crossing *c2) const
Definition: NBAlgorithms.h:117
NBTurningDirectionsComputer::Combination::to
NBEdge * to
Definition: NBAlgorithms.h:70
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:74
NBNodesEdgesSorter
Definition: NBAlgorithms.h:101
NBTurningDirectionsComputer::Combination::from
NBEdge * from
Definition: NBAlgorithms.h:69
NBEdgePriorityComputer::extractAndMarkFirst
static NBEdge * extractAndMarkFirst(NBNode &n, std::vector< NBEdge * > &s, int prio=1)
Sets the priorites in case of a priority junction.
Definition: NBAlgorithms.cpp:459
NBEdgePriorityComputer::samePriority
static bool samePriority(const NBEdge *const e1, const NBEdge *const e2)
Returns whether both edges have the same priority.
Definition: NBAlgorithms.cpp:471
NBNodesEdgesSorter::crossing_by_junction_angle_sorter::crossing_by_junction_angle_sorter
crossing_by_junction_angle_sorter(const NBNode *node, const EdgeVector &ordering)
Definition: NBAlgorithms.cpp:500
NBTrafficLightLogicCont
A container for traffic light definitions and built programs.
Definition: NBTrafficLightLogicCont.h:58
NBEdgePriorityComputer::setPriorityJunctionPriorities
static void setPriorityJunctionPriorities(NBNode &n)
Sets the priorites in case of a priority junction.
Definition: NBAlgorithms.cpp:314
NBNodesEdgesSorter::swapWhenReversed
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.
Definition: NBAlgorithms.cpp:145
EdgeVector
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
NBTurningDirectionsComputer
Definition: NBAlgorithms.h:46
NBNodesEdgesSorter::crossing_by_junction_angle_sorter::getMinRank
int getMinRank(const EdgeVector &e) const
retrieves the minimum index in myAllEdges
Definition: NBAlgorithms.h:129
NBEdgeCont.h
NBNodesEdgesSorter::crossing_by_junction_angle_sorter::myOrdering
EdgeVector myOrdering
Definition: NBAlgorithms.h:139
NBEdgePriorityComputer::markBestParallel
static void markBestParallel(const NBNode &n, NBEdge *bestFirst, NBEdge *bestSecond)
set priority for edges that are parallel to the best edges
Definition: NBAlgorithms.cpp:439
NBEdgePriorityComputer::computeEdgePriorities
static void computeEdgePriorities(NBNodeCont &nc)
Computes edge priorities within a node.
Definition: NBAlgorithms.cpp:288
NBEdgePriorityComputer
Definition: NBAlgorithms.h:227
NBNodesEdgesSorter::sortNodesEdges
static void sortNodesEdges(NBNodeCont &nc, bool useNodeShape=false)
Sorts a node's edges clockwise regarding driving direction.
Definition: NBAlgorithms.cpp:137
NBNodeCont
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
NBTurningDirectionsComputer::combination_by_angle_sorter
Sorts "Combination"s by decreasing angle.
Definition: NBAlgorithms.h:78
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
NBTurningDirectionsComputer::Combination::angle
double angle
Definition: NBAlgorithms.h:71
NBTurningDirectionsComputer::computeTurnDirectionsForNode
static void computeTurnDirectionsForNode(NBNode *node, bool warn)
Computes turnaround destinations for all incoming edges of the given nodes (if any)
Definition: NBAlgorithms.cpp:55
NBNodeTypeComputer
Definition: NBAlgorithms.h:203
NBTurningDirectionsComputer::Combination
Stores the information about the angle between an incoming ("from") and an outgoing ("to") edge.
Definition: NBAlgorithms.h:68
NBTurningDirectionsComputer::combination_by_angle_sorter::combination_by_angle_sorter
combination_by_angle_sorter()
Definition: NBAlgorithms.h:80
NBNodesEdgesSorter::edge_by_junction_angle_sorter::edge_by_junction_angle_sorter
edge_by_junction_angle_sorter(NBNode *n)
Definition: NBAlgorithms.h:161
NBNodesEdgesSorter::edge_by_junction_angle_sorter::getConvAngle
double getConvAngle(NBEdge *e) const
Converts the angle of the edge if it is an incoming edge.
Definition: NBAlgorithms.h:168
NBNodesEdgesSorter::edge_by_junction_angle_sorter::operator()
int operator()(NBEdge *e1, NBEdge *e2) const
Definition: NBAlgorithms.h:162
NBNodeCont.h
NBEdgePriorityComputer::hasDifferentPriorities
static bool hasDifferentPriorities(const EdgeVector &edges, const NBEdge *excluded)
return whether the priorite attribute can be used to distinguish the edges
Definition: NBAlgorithms.cpp:486
NBTurningDirectionsComputer::combination_by_angle_sorter::operator()
int operator()(const Combination &c1, const Combination &c2) const
Definition: NBAlgorithms.h:81
NBNode::Crossing::edges
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:138
NBNodeTypeComputer::isRailwayNode
static bool isRailwayNode(const NBNode *n)
whether the given node only has rail edges
Definition: NBAlgorithms.cpp:271
config.h
NBNodesEdgesSorter::crossing_by_junction_angle_sorter::operator=
crossing_by_junction_angle_sorter & operator=(const crossing_by_junction_angle_sorter &s)
invalidated assignment operator
NBNodesEdgesSorter::edge_by_junction_angle_sorter
Sorts incoming and outgoing edges clockwise around the given node.
Definition: NBAlgorithms.h:159
NBNodesEdgesSorter::edge_by_junction_angle_sorter::myNode
NBNode * myNode
The node to compute the relative angle of.
Definition: NBAlgorithms.h:189
NBTurningDirectionsComputer::computeTurnDirections
static void computeTurnDirections(NBNodeCont &nc, bool warn=true)
Computes turnaround destinations for all edges (if exist)
Definition: NBAlgorithms.cpp:48
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:68
NBNode::Crossing
A definition of a pedestrian crossing.
Definition: NBNode.h:132
NBEdge::getAngleAtNode
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
Definition: NBEdge.cpp:1863
NBNodeTypeComputer::computeNodeTypes
static void computeNodeTypes(NBNodeCont &nc, NBTrafficLightLogicCont &tlc)
Computes node types.
Definition: NBAlgorithms.cpp:164
NBEdge::getFromNode
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:479
NBNodesEdgesSorter::crossing_by_junction_angle_sorter
Sorts crossings by minimum clockwise clockwise edge angle. Use the ordering found in myAllEdges of th...
Definition: NBAlgorithms.h:113
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1364