SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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:
113  static void sortNodesEdges(NBNodeCont& nc, bool leftHand, 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  size_t getMinRank(const EdgeVector& e) const {
130  size_t result = myOrdering.size();
131  for (EdgeVector::const_iterator it = e.begin(); it != e.end(); ++it) {
132  size_t rank = 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  };
146 private:
153  static void swapWhenReversed(const NBNode* const n, bool leftHand,
154  const std::vector<NBEdge*>::iterator& i1,
155  const std::vector<NBEdge*>::iterator& i2);
156 
157 
162  public:
164  int operator()(NBEdge* e1, NBEdge* e2) const {
165  return getConvAngle(e1) < getConvAngle(e2);
166  }
167 
168  protected:
171  SUMOReal angle = e->getAngleAtNode(myNode);
172  if (angle < 0.) {
173  angle = 360. + angle;
174  }
175  // convert angle if the edge is an outgoing edge
176  if (e->getFromNode() == myNode) {
177  angle += (SUMOReal) 180.;
178  if (angle >= (SUMOReal) 360.) {
179  angle -= (SUMOReal) 360.;
180  }
181  }
182  if (angle < 0.1 || angle > 359.9) {
183  angle = (SUMOReal) 0.;
184  }
185  assert(angle >= (SUMOReal)0 && angle < (SUMOReal)360);
186  return angle;
187  }
188 
189  private:
192 
193  };
194 
195 };
196 
197 
198 
199 // ---------------------------------------------------------------------------
200 // NBNodeTypeComputer
201 // ---------------------------------------------------------------------------
202 /* @class NBNodeTypeComputer
203  * @brief Computes node types
204  */
206 public:
210  static void computeNodeTypes(NBNodeCont& nc);
211 
212 };
213 
214 
215 
216 // ---------------------------------------------------------------------------
217 // NBEdgePriorityComputer
218 // ---------------------------------------------------------------------------
219 /* @class NBEdgePriorityComputer
220  * @brief Computes edge priorities within a node
221  */
223 public:
227  static void computeEdgePriorities(NBNodeCont& nc);
228 
229 private:
233  static void setPriorityJunctionPriorities(NBNode& n);
234 
241  static NBEdge* extractAndMarkFirst(NBNode& n, std::vector<NBEdge*>& s, int prio = 1);
242 
248  static bool samePriority(const NBEdge* const e1, const NBEdge* const e2);
249 
250 };
251 
252 #endif
253 
254 /****************************************************************************/
255 
int operator()(NBEdge *e1, NBEdge *e2) const
Definition: NBAlgorithms.h:164
Sorts incoming and outgoing edges clockwise around the given node.
Definition: NBAlgorithms.h:161
Sorts crossings by minimum clockwise clockwise edge angle. Use the ordering found in myAllEdges of th...
Definition: NBAlgorithms.h:119
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:170
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:129
static NBEdge * extractAndMarkFirst(NBNode &n, std::vector< NBEdge * > &s, int prio=1)
Sets the priorites in case of a priority junction.
static void computeTurnDirections(NBNodeCont &nc)
Computes turnaround destinations for all edges (if exist)
T MIN2(T a, T b)
Definition: StdDefs.h:68
crossing_by_junction_angle_sorter(const NBNode *node, const EdgeVector &ordering)
int operator()(const NBNode::Crossing &c1, const NBNode::Crossing &c2) const
Definition: NBAlgorithms.h:123
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:191
static void computeNodeTypes(NBNodeCont &nc)
Computes node types.
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:141
Represents a single node (junction) during network building.
Definition: NBNode.h:75
A definition of a pedestrian crossing.
Definition: NBNode.h:134
#define SUMOReal
Definition: config.h:218
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
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:1245
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:363
static void sortNodesEdges(NBNodeCont &nc, bool leftHand, bool useNodeShape=false)
Sorts a node's edges clockwise regarding driving direction.