SUMO - Simulation of Urban MObility
NBAlgorithms.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Algorithms for network computation
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef NBAlgorithms_h
22 #define NBAlgorithms_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <map>
35 #include "NBEdgeCont.h"
36 #include "NBNodeCont.h"
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class NBEdge;
42 class NBNode;
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
47 // ---------------------------------------------------------------------------
48 // NBTurningDirectionsComputer
49 // ---------------------------------------------------------------------------
50 /* @class NBTurningDirectionsComputer
51  * @brief Computes turnaround destinations for all edges (if exist)
52  */
54 public:
59  static void computeTurnDirections(NBNodeCont& nc, bool warn = true);
60 
66  static void computeTurnDirectionsForNode(NBNode* node, bool warn);
67 
68 private:
75  struct Combination {
78  double angle;
79  };
80 
81 
86  public:
88  int operator()(const Combination& c1, const Combination& c2) const {
89  if (c1.angle != c2.angle) {
90  return c1.angle > c2.angle;
91  }
92  if (c1.from != c2.from) {
93  return c1.from->getID() < c2.from->getID();
94  }
95  return c1.to->getID() < c2.to->getID();
96  }
97  };
98 };
99 
100 
101 
102 // ---------------------------------------------------------------------------
103 // NBNodesEdgesSorter
104 // ---------------------------------------------------------------------------
105 /* @class NBNodesEdgesSorter
106  * @brief Sorts a node's edges clockwise regarding driving direction
107  */
109 public:
114  static void sortNodesEdges(NBNodeCont& nc, bool useNodeShape = false);
115 
121  public:
122  explicit crossing_by_junction_angle_sorter(const NBNode* node, const EdgeVector& ordering);
123 
124  int operator()(const NBNode::Crossing& c1, const NBNode::Crossing& c2) const {
125  return (int)(getMinRank(c1.edges) < getMinRank(c2.edges));
126  }
127 
128  private:
130  int getMinRank(const EdgeVector& e) const {
131  int result = (int)myOrdering.size();
132  for (EdgeVector::const_iterator it = e.begin(); it != e.end(); ++it) {
133  int rank = (int)std::distance(myOrdering.begin(), std::find(myOrdering.begin(), myOrdering.end(), *it));
134  result = MIN2(result, rank);
135  }
136  return result;
137  }
138 
139  private:
141 
142  private:
145 
146  };
152  static void swapWhenReversed(const NBNode* const n,
153  const std::vector<NBEdge*>::iterator& i1,
154  const std::vector<NBEdge*>::iterator& i2);
155 
156 
161  public:
162  explicit edge_by_junction_angle_sorter(NBNode* n) : myNode(n) {}
163  int operator()(NBEdge* e1, NBEdge* e2) const {
164  return getConvAngle(e1) < getConvAngle(e2);
165  }
166 
167  protected:
169  double getConvAngle(NBEdge* e) const {
170  double angle = e->getAngleAtNode(myNode);
171  if (angle < 0.) {
172  angle = 360. + angle;
173  }
174  // convert angle if the edge is an outgoing edge
175  if (e->getFromNode() == myNode) {
176  angle += (double) 180.;
177  if (angle >= (double) 360.) {
178  angle -= (double) 360.;
179  }
180  }
181  if (angle < 0.1 || angle > 359.9) {
182  angle = (double) 0.;
183  }
184  assert(angle >= 0 && angle < (double)360);
185  return angle;
186  }
187 
188  private:
191 
192  };
193 
194 };
195 
196 
197 
198 // ---------------------------------------------------------------------------
199 // NBNodeTypeComputer
200 // ---------------------------------------------------------------------------
201 /* @class NBNodeTypeComputer
202  * @brief Computes node types
203  */
205 public:
209  static void computeNodeTypes(NBNodeCont& nc);
210 
214  static void computeSingleNodeType(NBNode* node);
215 };
216 
217 
218 
219 // ---------------------------------------------------------------------------
220 // NBEdgePriorityComputer
221 // ---------------------------------------------------------------------------
222 /* @class NBEdgePriorityComputer
223  * @brief Computes edge priorities within a node
224  */
226 public:
230  static void computeEdgePriorities(NBNodeCont& nc);
231 
235  static void computeEdgePrioritiesSingleNode(NBNode* node);
236 
237 private:
241  static void setPriorityJunctionPriorities(NBNode& n);
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 
258 };
259 
260 #endif
261 
262 /****************************************************************************/
263 
Sorts incoming and outgoing edges clockwise around the given node.
Definition: NBAlgorithms.h:160
Sorts crossings by minimum clockwise clockwise edge angle. Use the ordering found in myAllEdges of th...
Definition: NBAlgorithms.h:120
The representation of a single edge during network building.
Definition: NBEdge.h:71
const std::string & getID() const
Returns the id.
Definition: Named.h:66
Stores the information about the angle between an incoming ("from") and an outgoing ("to") edge...
Definition: NBAlgorithms.h:75
int operator()(NBEdge *e1, NBEdge *e2) const
Definition: NBAlgorithms.h:163
int operator()(const Combination &c1, const Combination &c2) const
Definition: NBAlgorithms.h:88
int operator()(const NBNode::Crossing &c1, const NBNode::Crossing &c2) const
Definition: NBAlgorithms.h:124
T MIN2(T a, T b)
Definition: StdDefs.h:64
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge&#39;s geometry at the given node.
Definition: NBEdge.cpp:1576
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:190
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:41
double getConvAngle(NBEdge *e) const
Converts the angle of the edge if it is an incoming edge.
Definition: NBAlgorithms.h:169
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:147
Represents a single node (junction) during network building.
Definition: NBNode.h:75
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:135
Sorts "Combination"s by decreasing angle.
Definition: NBAlgorithms.h:85
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:427
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
int getMinRank(const EdgeVector &e) const
retrieves the minimum index in myAllEdges
Definition: NBAlgorithms.h:130