SUMO - Simulation of Urban MObility
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-2014 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 
375  public:
378 
379  public:
381  int operator()(const NBEdge* e1, const NBEdge* e2) const;
382 
383  private:
386  };
387 
388 };
389 
390 
391 #endif
392 
393 /****************************************************************************/
394 
SUMOReal atan2DegreeAngle() const
Definition: Line.cpp:143
node_with_outgoing_finder(const NBEdge *const e)
constructor
#define min(a, b)
Definition: polyfonts.c:66
NBEdge * myEdge
the edge to compute the relative angle of
Definition: NBContHelper.h:95
static SUMOReal normRelAngle(SUMOReal angle1, SUMOReal angle2)
ensure that reverse relAngles (>=179.999) always count as turnarounds (-180)
Definition: NBHelpers.cpp:76
SUMOReal myAngle
the angle to find the edge with the opposite direction
Definition: NBContHelper.h:230
const NBNode *const myNode
The related node.
Definition: NBContHelper.h:199
friend std::ostream & operator<<(std::ostream &os, const EdgeVector &ev)
The representation of a single edge during network building.
Definition: NBEdge.h:71
Line getEndLine() const
Class to sort edges by their angle in relation to the given edge.
Definition: NBContHelper.h:148
bool operator()(const NBNode *const n) const
node_with_outgoing_finder & operator=(const node_with_outgoing_finder &s)
invalidated assignment operator
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
SUMOReal getDiff(const NBEdge *const e) const
Computes the angle difference between the related and the given edge.
Definition: NBContHelper.h:175
int operator()(const NBEdge *e1, const NBEdge *e2) const
comparing operation
bool isTurningDirectionAt(const NBNode *n, const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:1655
relative_outgoing_edge_sorter(NBEdge *e)
constructor
Definition: NBContHelper.h:87
opposite_finder(NBEdge *edge, const NBNode *n)
constructor
Definition: NBContHelper.h:356
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
Definition: NBEdge.cpp:785
edge_similar_direction_sorter(const NBEdge *const e)
constructor
Definition: NBContHelper.h:218
edge_opposite_direction_sorter(const NBEdge *const e, const NBNode *const n)
Constructor.
Definition: NBContHelper.h:154
const std::string & getID() const
Returns the id.
Definition: Named.h:60
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operation
Definition: NBContHelper.h:222
#define max(a, b)
Definition: polyfonts.c:65
int getPriority() const
Returns the priority of the edge.
Definition: NBEdge.h:352
static std::ostream & out(std::ostream &os, const std::vector< bool > &v)
bool operator()(const NBNode *const n) const
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operation
Definition: NBContHelper.h:314
static SUMOReal maxSpeed(const EdgeVector &ev)
NBEdge * myEdge
the edge to compute the relative angle of
Definition: NBContHelper.h:117
unsigned int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:344
int operator()(NBEdge *e1, NBEdge *e2) const
Comparing operation.
Definition: NBContHelper.h:164
Line & reverse()
Definition: Line.cpp:211
edge_with_destination_finder & operator=(const edge_with_destination_finder &s)
invalidated assignment operator
edge_with_destination_finder(NBNode *dest)
constructor
std::pair< SUMOReal, SUMOReal > getMinMaxRelAngles(NBEdge *e) const
Definition: NBContHelper.h:332
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operator
Definition: NBContHelper.h:128
static SUMOReal getMaxSpeed(const EdgeVector &edges)
NBNode * myNode
the edge to compute the relative angle of
Definition: NBContHelper.h:385
edge_opposite_direction_sorter & operator=(const edge_opposite_direction_sorter &s)
Invalidated assignment operator.
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:38
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:521
static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:395
node_with_incoming_finder & operator=(const node_with_incoming_finder &s)
invalidated assignment operator
Line getBegLine() const
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operation
node_with_incoming_finder(const NBEdge *const e)
constructor
SUMOReal getTotalAngle() const
get the angle as measure from the start to the end of this edge
Definition: NBEdge.h:396
Represents a single node (junction) during network building.
Definition: NBNode.h:75
#define SUMOReal
Definition: config.h:215
SUMOReal getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:428
relative_incoming_edge_sorter(NBEdge *e)
constructor
Definition: NBContHelper.h:109
bool operator()(NBEdge *e) const
Definition: NBContHelper.h:359
static SUMOReal getMinSpeed(const EdgeVector &edges)
static void nextCCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
int operator()(NBEdge *e1, NBEdge *e2) const
comparing operation
SUMOReal myAngle
The angle of the related edge at the given node.
Definition: NBContHelper.h:196
static NBEdge * findConnectingEdge(const EdgeVector &edges, NBNode *from, NBNode *to)
SUMOReal getEdgeAngleAt(const NBEdge *const e, const NBNode *const n) const
Returns the given edge's angle at the given node.
Definition: NBContHelper.h:186
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:360