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-2018 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:
161  explicit edge_by_junction_angle_sorter(NBNode* n) : myNode(n) {}
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 
213  static void validateRailCrossings(NBNodeCont& nc, NBTrafficLightLogicCont& tlc);
214 
216  static bool isRailwayNode(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 
237  static void computeEdgePrioritiesSingleNode(NBNode* node);
238 
239 private:
243  static void setPriorityJunctionPriorities(NBNode& n);
244 
246  static void markBestParallel(const NBNode& n, NBEdge* bestFirst, NBEdge* bestSecond);
247 
254  static NBEdge* extractAndMarkFirst(NBNode& n, std::vector<NBEdge*>& s, int prio = 1);
255 
261  static bool samePriority(const NBEdge* const e1, const NBEdge* const e2);
262 
264  static bool hasDifferentPriorities(const EdgeVector& edges, const NBEdge* excluded);
265 
266 };
267 
268 #endif
269 
270 /****************************************************************************/
271 
Sorts incoming and outgoing edges clockwise around the given node.
Definition: NBAlgorithms.h:159
Sorts crossings by minimum clockwise clockwise edge angle. Use the ordering found in myAllEdges of th...
Definition: NBAlgorithms.h:113
A container for traffic light definitions and built programs.
int operator()(const NBNode::Crossing *c1, const NBNode::Crossing *c2) const
Definition: NBAlgorithms.h:117
The representation of a single edge during network building.
Definition: NBEdge.h:65
const std::string & getID() const
Returns the id.
Definition: Named.h:78
Stores the information about the angle between an incoming ("from") and an outgoing ("to") edge...
Definition: NBAlgorithms.h:68
int operator()(NBEdge *e1, NBEdge *e2) const
Definition: NBAlgorithms.h:162
int operator()(const Combination &c1, const Combination &c2) const
Definition: NBAlgorithms.h:81
T MIN2(T a, T b)
Definition: StdDefs.h:70
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge&#39;s geometry at the given node.
Definition: NBEdge.cpp:1801
static void computeTurnDirectionsForNode(NBNode *node, bool warn)
Computes turnaround destinations for all incoming edges of the given nodes (if any) ...
NBNode * myNode
The node to compute the relative angle of.
Definition: NBAlgorithms.h:189
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
double getConvAngle(NBEdge *e) const
Converts the angle of the edge if it is an incoming edge.
Definition: NBAlgorithms.h:168
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:131
Represents a single node (junction) during network building.
Definition: NBNode.h:68
static void computeTurnDirections(NBNodeCont &nc, bool warn=true)
Computes turnaround destinations for all edges (if exist)
A definition of a pedestrian crossing.
Definition: NBNode.h:125
Sorts "Combination"s by decreasing angle.
Definition: NBAlgorithms.h:78
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:434
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
int getMinRank(const EdgeVector &e) const
retrieves the minimum index in myAllEdges
Definition: NBAlgorithms.h:129