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.sourceforge.net/
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