SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBAlgorithms.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // Algorithms for network computation
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
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 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class NBEdge;
40 class NBNodeCont;
41 class NBTypeCont;
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:
57  static void computeTurnDirections(NBNodeCont& nc);
58 
63  static void computeTurnDirectionsForNode(NBNode* node);
64 
65 private:
72  struct Combination {
76  };
77 
78 
83  public:
85  int operator()(const Combination& c1, const Combination& c2) const {
86  if (c1.angle != c2.angle) {
87  return c1.angle > c2.angle;
88  }
89  if (c1.from != c2.from) {
90  return c1.from->getID() < c2.from->getID();
91  }
92  return c1.to->getID() < c2.to->getID();
93  }
94  };
95 };
96 
97 
98 
99 // ---------------------------------------------------------------------------
100 // NBNodesEdgesSorter
101 // ---------------------------------------------------------------------------
102 /* @class NBNodesEdgesSorter
103  * @brief Sorts a node's edges clockwise regarding driving direction
104  */
106 public:
111  static void sortNodesEdges(NBNodeCont& nc, bool leftHand);
112 
113 private:
120  static void swapWhenReversed(const NBNode* const n, bool leftHand,
121  const std::vector<NBEdge*>::iterator& i1,
122  const std::vector<NBEdge*>::iterator& i2);
123 
124 
129  public:
131  int operator()(NBEdge* e1, NBEdge* e2) const {
132  return getConvAngle(e1) < getConvAngle(e2);
133  }
134 
135  private:
138  SUMOReal angle = e->getAngleAtNode(myNode);
139  if (angle < 0.) {
140  angle = 360. + angle;
141  }
142  // convert angle if the edge is an outgoing edge
143  if (e->getFromNode() == myNode) {
144  angle += (SUMOReal) 180.;
145  if (angle >= (SUMOReal) 360.) {
146  angle -= (SUMOReal) 360.;
147  }
148  }
149  if (angle < 0.1 || angle > 359.9) {
150  angle = (SUMOReal) 0.;
151  }
152  assert(angle >= (SUMOReal)0 && angle < (SUMOReal)360);
153  return angle;
154  }
155 
156  private:
159 
160  };
161 };
162 
163 
164 
165 // ---------------------------------------------------------------------------
166 // NBNodeTypeComputer
167 // ---------------------------------------------------------------------------
168 /* @class NBNodeTypeComputer
169  * @brief Computes node types
170  */
172 public:
176  static void computeNodeTypes(NBNodeCont& nc);
177 
178 };
179 
180 
181 
182 // ---------------------------------------------------------------------------
183 // NBEdgePriorityComputer
184 // ---------------------------------------------------------------------------
185 /* @class NBEdgePriorityComputer
186  * @brief Computes edge priorities within a node
187  */
189 public:
193  static void computeEdgePriorities(NBNodeCont& nc);
194 
195 private:
199  static void setPriorityJunctionPriorities(NBNode& n);
200 
206  static NBEdge* extractAndMarkFirst(NBNode& n, std::vector<NBEdge*>& s);
207 
213  static bool samePriority(const NBEdge* const e1, const NBEdge* const e2);
214 
215 };
216 
217 #endif
218 
219 /****************************************************************************/
220 
int operator()(NBEdge *e1, NBEdge *e2) const
Definition: NBAlgorithms.h:131
Sorts incoming and outgoing edges clockwise around the given node.
Definition: NBAlgorithms.h:128
int operator()(const Combination &c1, const Combination &c2) const
Definition: NBAlgorithms.h:85
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:137
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 (&quot;from&quot;) and an outgoing (&quot;to&quot;) edge...
Definition: NBAlgorithms.h:72
const std::string & getID() const
Returns the id.
Definition: Named.h:60
static void computeEdgePriorities(NBNodeCont &nc)
Computes edge priorities within a node.
static void computeTurnDirections(NBNodeCont &nc)
Computes turnaround destinations for all edges (if exist)
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:158
static void computeNodeTypes(NBNodeCont &nc)
Computes node types.
Represents a single node (junction) during network building.
Definition: NBNode.h:74
static NBEdge * extractAndMarkFirst(NBNode &n, std::vector< NBEdge * > &s)
Sets the priorites in case of a priority junction.
#define SUMOReal
Definition: config.h:221
Sorts &quot;Combination&quot;s by decreasing angle.
Definition: NBAlgorithms.h:82
static void setPriorityJunctionPriorities(NBNode &n)
Sets the priorites in case of a priority junction.
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
static void sortNodesEdges(NBNodeCont &nc, bool leftHand)
Sorts a node&#39;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&#39;s geometry at the given node.
Definition: NBEdge.cpp:1121
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:349