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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Algorithms for network computation
19 /****************************************************************************/
20 #ifndef NBAlgorithms_h
21 #define NBAlgorithms_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <map>
34 #include "NBEdgeCont.h"
35 #include "NBNodeCont.h"
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class NBEdge;
41 class NBNode;
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // NBTurningDirectionsComputer
48 // ---------------------------------------------------------------------------
49 /* @class NBTurningDirectionsComputer
50  * @brief Computes turnaround destinations for all edges (if exist)
51  */
53 public:
58  static void computeTurnDirections(NBNodeCont& nc, bool warn = true);
59 
65  static void computeTurnDirectionsForNode(NBNode* node, bool warn);
66 
67 private:
74  struct Combination {
77  double angle;
78  };
79 
80 
85  public:
87  int operator()(const Combination& c1, const Combination& c2) const {
88  if (c1.angle != c2.angle) {
89  return c1.angle > c2.angle;
90  }
91  if (c1.from != c2.from) {
92  return c1.from->getID() < c2.from->getID();
93  }
94  return c1.to->getID() < c2.to->getID();
95  }
96  };
97 };
98 
99 
100 
101 // ---------------------------------------------------------------------------
102 // NBNodesEdgesSorter
103 // ---------------------------------------------------------------------------
104 /* @class NBNodesEdgesSorter
105  * @brief Sorts a node's edges clockwise regarding driving direction
106  */
108 public:
113  static void sortNodesEdges(NBNodeCont& nc, bool useNodeShape = false);
114 
120  public:
121  explicit crossing_by_junction_angle_sorter(const NBNode* node, const EdgeVector& ordering);
122 
123  int operator()(const NBNode::Crossing* c1, const NBNode::Crossing* c2) const {
124  return (int)(getMinRank(c1->edges) < getMinRank(c2->edges));
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);
209 
213  static void computeSingleNodeType(NBNode* node);
214 };
215 
216 
217 
218 // ---------------------------------------------------------------------------
219 // NBEdgePriorityComputer
220 // ---------------------------------------------------------------------------
221 /* @class NBEdgePriorityComputer
222  * @brief Computes edge priorities within a node
223  */
225 public:
229  static void computeEdgePriorities(NBNodeCont& nc);
230 
234  static void computeEdgePrioritiesSingleNode(NBNode* node);
235 
236 private:
240  static void setPriorityJunctionPriorities(NBNode& n);
241 
248  static NBEdge* extractAndMarkFirst(NBNode& n, std::vector<NBEdge*>& s, int prio = 1);
249 
255  static bool samePriority(const NBEdge* const e1, const NBEdge* const e2);
256 
258  static bool hasDifferentPriorities(const EdgeVector& edges, const NBEdge* excluded);
259 
260 };
261 
262 #endif
263 
264 /****************************************************************************/
265 
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:119
int operator()(const NBNode::Crossing *c1, const NBNode::Crossing *c2) const
Definition: NBAlgorithms.h:123
The representation of a single edge during network building.
Definition: NBEdge.h:70
const std::string & getID() const
Returns the id.
Definition: Named.h:65
Stores the information about the angle between an incoming ("from") and an outgoing ("to") edge...
Definition: NBAlgorithms.h:74
int operator()(NBEdge *e1, NBEdge *e2) const
Definition: NBAlgorithms.h:162
int operator()(const Combination &c1, const Combination &c2) const
Definition: NBAlgorithms.h:87
T MIN2(T a, T b)
Definition: StdDefs.h:67
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge&#39;s geometry at the given node.
Definition: NBEdge.cpp:1611
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:40
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:137
Represents a single node (junction) during network building.
Definition: NBNode.h:74
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:131
Sorts "Combination"s by decreasing angle.
Definition: NBAlgorithms.h:84
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:426
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:66
int getMinRank(const EdgeVector &e) const
retrieves the minimum index in myAllEdges
Definition: NBAlgorithms.h:129