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-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:
59  static void computeTurnDirections(NBNodeCont& nc, bool warn = true);
60 
66  static void computeTurnDirectionsForNode(NBNode* node, bool warn);
67 
68 private:
75  struct Combination {
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  size_t getMinRank(const EdgeVector& e) const {
131  size_t result = myOrdering.size();
132  for (EdgeVector::const_iterator it = e.begin(); it != e.end(); ++it) {
133  size_t rank = 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  };
147 private:
153  static void swapWhenReversed(const NBNode* const n,
154  const std::vector<NBEdge*>::iterator& i1,
155  const std::vector<NBEdge*>::iterator& i2);
156 
157 
162  public:
163  explicit edge_by_junction_angle_sorter(NBNode* n) : myNode(n) {}
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:120
int operator()(const Combination &c1, const Combination &c2) const
Definition: NBAlgorithms.h:88
The representation of a single edge during network building.
Definition: NBEdge.h:70
SUMOReal getConvAngle(NBEdge *e) const
Converts the angle of the edge if it is an incoming edge.
Definition: NBAlgorithms.h:170
Stores the information about the angle between an incoming ("from") and an outgoing ("to") edge...
Definition: NBAlgorithms.h:75
const std::string & getID() const
Returns the id.
Definition: Named.h:65
size_t getMinRank(const EdgeVector &e) const
retrieves the minimum index in myAllEdges
Definition: NBAlgorithms.h:130
T MIN2(T a, T b)
Definition: StdDefs.h:73
int operator()(const NBNode::Crossing &c1, const NBNode::Crossing &c2) const
Definition: NBAlgorithms.h:124
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:191
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:139
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:132
#define SUMOReal
Definition: config.h:214
Sorts "Combination"s by decreasing angle.
Definition: NBAlgorithms.h:85
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
A storage for available types of edges.
Definition: NBTypeCont.h:62
SUMOReal getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge&#39;s geometry at the given node.
Definition: NBEdge.cpp:1281
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:361