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-sim.org/
11 // Copyright (C) 2012-2014 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 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class NBEdge;
41 class NBNodeCont;
42 class NBTypeCont;
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:
58  static void computeTurnDirections(NBNodeCont& nc);
59 
64  static void computeTurnDirectionsForNode(NBNode* node);
65 
66 private:
73  struct Combination {
77  };
78 
79 
84  public:
86  int operator()(const Combination& c1, const Combination& c2) const {
87  if (c1.angle != c2.angle) {
88  return c1.angle > c2.angle;
89  }
90  if (c1.from != c2.from) {
91  return c1.from->getID() < c2.from->getID();
92  }
93  return c1.to->getID() < c2.to->getID();
94  }
95  };
96 };
97 
98 
99 
100 // ---------------------------------------------------------------------------
101 // NBNodesEdgesSorter
102 // ---------------------------------------------------------------------------
103 /* @class NBNodesEdgesSorter
104  * @brief Sorts a node's edges clockwise regarding driving direction
105  */
107 public:
112  static void sortNodesEdges(NBNodeCont& nc, bool leftHand);
113 
119  public:
120  explicit crossing_by_junction_angle_sorter(const EdgeVector& ordering) : myOrdering(ordering) {}
121  int operator()(const NBNode::Crossing& c1, const NBNode::Crossing& c2) const {
122  return (int)(getMinRank(c1.edges) < getMinRank(c2.edges));
123  }
124 
125  private:
127  size_t getMinRank(const EdgeVector& e) const {
128  size_t result = myOrdering.size();
129  for (EdgeVector::const_iterator it = e.begin(); it != e.end(); ++it) {
130  size_t rank = std::distance(myOrdering.begin(), std::find(myOrdering.begin(), myOrdering.end(), *it));
131  result = MIN2(result, rank);
132  }
133  return result;
134  }
135 
136  private:
138 
139  private:
142 
143  };
144 private:
151  static void swapWhenReversed(const NBNode* const n, bool leftHand,
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:
169  SUMOReal 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 += (SUMOReal) 180.;
176  if (angle >= (SUMOReal) 360.) {
177  angle -= (SUMOReal) 360.;
178  }
179  }
180  if (angle < 0.1 || angle > 359.9) {
181  angle = (SUMOReal) 0.;
182  }
183  assert(angle >= (SUMOReal)0 && angle < (SUMOReal)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 
210 };
211 
212 
213 
214 // ---------------------------------------------------------------------------
215 // NBEdgePriorityComputer
216 // ---------------------------------------------------------------------------
217 /* @class NBEdgePriorityComputer
218  * @brief Computes edge priorities within a node
219  */
221 public:
225  static void computeEdgePriorities(NBNodeCont& nc);
226 
227 private:
231  static void setPriorityJunctionPriorities(NBNode& n);
232 
238  static NBEdge* extractAndMarkFirst(NBNode& n, std::vector<NBEdge*>& s);
239 
245  static bool samePriority(const NBEdge* const e1, const NBEdge* const e2);
246 
247 };
248 
249 #endif
250 
251 /****************************************************************************/
252 
int operator()(NBEdge *e1, NBEdge *e2) const
Definition: NBAlgorithms.h:162
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:118
int operator()(const Combination &c1, const Combination &c2) const
Definition: NBAlgorithms.h:86
The representation of a single edge during network building.
Definition: NBEdge.h:71
SUMOReal getConvAngle(NBEdge *e) const
Converts the angle of the edge if it is an incoming edge.
Definition: NBAlgorithms.h:168
static void swapWhenReversed(const NBNode *const n, bool leftHand, const std::vector< NBEdge * >::iterator &i1, const std::vector< NBEdge * >::iterator &i2)
Assures correct order for same-angle opposite-direction edges.
static void computeTurnDirectionsForNode(NBNode *node)
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...
Definition: NBAlgorithms.h:73
const std::string & getID() const
Returns the id.
Definition: Named.h:60
crossing_by_junction_angle_sorter & operator=(const crossing_by_junction_angle_sorter &s)
invalidated assignment operator
static void computeEdgePriorities(NBNodeCont &nc)
Computes edge priorities within a node.
size_t getMinRank(const EdgeVector &e) const
retrieves the minimum index in myAllEdges
Definition: NBAlgorithms.h:127
static void computeTurnDirections(NBNodeCont &nc)
Computes turnaround destinations for all edges (if exist)
T MIN2(T a, T b)
Definition: StdDefs.h:66
int operator()(const NBNode::Crossing &c1, const NBNode::Crossing &c2) const
Definition: NBAlgorithms.h:121
static bool samePriority(const NBEdge *const e1, const NBEdge *const e2)
Returns whether both edges have the same priority.
NBNode * myNode
The node to compute the relative angle of.
Definition: NBAlgorithms.h:189
static void computeNodeTypes(NBNodeCont &nc)
Computes node types.
crossing_by_junction_angle_sorter(const EdgeVector &ordering)
Definition: NBAlgorithms.h:120
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:38
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:139
Represents a single node (junction) during network building.
Definition: NBNode.h:75
static NBEdge * extractAndMarkFirst(NBNode &n, std::vector< NBEdge * > &s)
Sets the priorites in case of a priority junction.
A definition of a pedestrian crossing.
Definition: NBNode.h:132
#define SUMOReal
Definition: config.h:215
Sorts "Combination"s by decreasing angle.
Definition: NBAlgorithms.h:83
static void setPriorityJunctionPriorities(NBNode &n)
Sets the priorites in case of a priority junction.
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
static void sortNodesEdges(NBNodeCont &nc, bool leftHand)
Sorts a node's edges clockwise regarding driving direction.
A storage for available types of edges.
Definition: NBTypeCont.h:56
SUMOReal getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
Definition: NBEdge.cpp:1162
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:360