SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBContHelper.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Some methods for traversing lists of edges
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef NBContHelper_h
23 #define NBContHelper_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <iostream>
37 #include <cmath>
38 #include <algorithm>
39 #include <cassert>
40 #include "NBHelpers.h"
41 #include "NBCont.h"
42 #include "NBEdge.h"
43 #include "NBNode.h"
44 #include <utils/common/StdDefs.h>
45 #include <utils/geom/GeomHelper.h>
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
56 class NBContHelper {
57 public:
60  static void nextCW(const EdgeVector& edges,
61  EdgeVector::const_iterator& from);
62 
65  static void nextCCW(const EdgeVector& edges,
66  EdgeVector::const_iterator& from);
67 
68  static SUMOReal getMaxSpeed(const EdgeVector& edges);
69 
70  static SUMOReal getMinSpeed(const EdgeVector& edges);
71 
73  static std::ostream& out(std::ostream& os, const std::vector<bool>& v);
74 
75 
85  public:
88 
89  public:
91  int operator()(NBEdge* e1, NBEdge* e2) const;
92 
93  private:
96  };
97 
98 
107  public:
110 
111  public:
113  int operator()(NBEdge* e1, NBEdge* e2) const;
114 
115  private:
118  };
119 
120 
126  public:
128  int operator()(NBEdge* e1, NBEdge* e2) const {
129  if (e1->getPriority() != e2->getPriority()) {
130  return e1->getPriority() > e2->getPriority();
131  }
132  if (e1->getSpeed() != e2->getSpeed()) {
133  return e1->getSpeed() > e2->getSpeed();
134  }
135  return e1->getNumLanes() > e2->getNumLanes();
136  }
137  };
138 
139  // ---------------------------
140 
149  public:
154  explicit edge_opposite_direction_sorter(const NBEdge* const e, const NBNode* const n)
155  : myNode(n) {
156  myAngle = getEdgeAngleAt(e, n);
157  }
158 
164  int operator()(NBEdge* e1, NBEdge* e2) const {
165  SUMOReal d1 = getDiff(e1);
166  SUMOReal d2 = getDiff(e2);
167  return d1 > d2;
168  }
169 
170  protected:
175  SUMOReal getDiff(const NBEdge* const e) const {
178  }
179 
186  SUMOReal getEdgeAngleAt(const NBEdge* const e, const NBNode* const n) const {
187  if (e->getFromNode() == n) {
188  return e->getGeometry().getBegLine().atan2DegreeAngle();
189  } else {
191  }
192  }
193 
194  private:
197 
199  const NBNode* const myNode;
200 
201  private:
204 
205  };
206 
207  // ---------------------------
208 
216  public:
218  explicit edge_similar_direction_sorter(const NBEdge* const e)
219  : myAngle(e->getTotalAngle()) {}
220 
222  int operator()(NBEdge* e1, NBEdge* e2) const {
225  return d1 < d2;
226  }
227 
228  private:
231  };
232 
233 
238  public:
240  node_with_incoming_finder(const NBEdge* const e);
241 
242  bool operator()(const NBNode* const n) const;
243 
244  private:
245  const NBEdge* const myEdge;
246 
247  private:
250 
251  };
252 
253 
258  public:
260  node_with_outgoing_finder(const NBEdge* const e);
261 
262  bool operator()(const NBNode* const n) const;
263 
264  private:
265  const NBEdge* const myEdge;
266 
267  private:
270 
271  };
272 
273 
274 
275 
277  public:
280 
281  bool operator()(NBEdge* e) const;
282 
283  private:
285 
286  private:
289 
290  };
291 
292 
295  static NBEdge* findConnectingEdge(const EdgeVector& edges,
296  NBNode* from, NBNode* to);
297 
298 
300  static SUMOReal maxSpeed(const EdgeVector& ev);
301 
309  public:
312 
314  int operator()(NBEdge* e1, NBEdge* e2) const {
315  std::pair<SUMOReal, SUMOReal> mm1 = getMinMaxRelAngles(e1);
316  std::pair<SUMOReal, SUMOReal> mm2 = getMinMaxRelAngles(e2);
317  if (mm1.first == mm2.first && mm1.second == mm2.second) {
318  // ok, let's simply sort them arbitrarily
319  return e1->getID() < e2->getID();
320  }
321 
322  assert(
323  (mm1.first <= mm2.first && mm1.second <= mm2.second)
324  ||
325  (mm1.first >= mm2.first && mm1.second >= mm2.second));
326  return (mm1.first >= mm2.first && mm1.second >= mm2.second);
327  }
328 
332  std::pair<SUMOReal, SUMOReal> getMinMaxRelAngles(NBEdge* e) const {
333  SUMOReal min = 360;
334  SUMOReal max = 360;
335  const EdgeVector& ev = e->getConnectedEdges();
336  for (EdgeVector::const_iterator i = ev.begin(); i != ev.end(); ++i) {
338  e->getTotalAngle(), (*i)->getTotalAngle());
339  if (min == 360 || min > angle) {
340  min = angle;
341  }
342  if (max == 360 || max < angle) {
343  max = angle;
344  }
345  }
346  return std::pair<SUMOReal, SUMOReal>(min, max);
347  }
348  };
349 
350 
351  friend std::ostream& operator<<(std::ostream& os, const EdgeVector& ev);
352 
354  public:
356  opposite_finder(NBEdge* edge, const NBNode* n)
357  : myReferenceEdge(edge), myAtNode(n) { }
358 
359  bool operator()(NBEdge* e) const {
362  }
363 
364  private:
366  const NBNode* myAtNode;
367 
368  };
369 
370 
371 };
372 
373 
374 #endif
375 
376 /****************************************************************************/
377