SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBContHelper.cpp
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.sourceforge.net/
12 // Copyright (C) 2001-2012 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 
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 <vector>
34 #include <map>
35 #include <cassert>
36 #include "NBContHelper.h"
37 #include <utils/geom/GeomHelper.h>
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 /* -------------------------------------------------------------------------
48  * utility methods
49  * ----------------------------------------------------------------------- */
50 void
51 NBContHelper::nextCW(const EdgeVector& edges, EdgeVector::const_iterator& from) {
52  from++;
53  if (from == edges.end()) {
54  from = edges.begin();
55  }
56 }
57 
58 
59 void
60 NBContHelper::nextCCW(const EdgeVector& edges, EdgeVector::const_iterator& from) {
61  if (from == edges.begin()) {
62  from = edges.end() - 1;
63  } else {
64  --from;
65  }
66 }
67 
68 
69 std::ostream&
70 NBContHelper::out(std::ostream& os, const std::vector<bool>& v) {
71  for (std::vector<bool>::const_iterator i = v.begin(); i != v.end(); i++) {
72  os << *i;
73  }
74  return os;
75 }
76 
77 
78 NBEdge*
80  NBNode* from, NBNode* to) {
81  for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); i++) {
82  if ((*i)->getToNode() == to && (*i)->getFromNode() == from) {
83  return *i;
84  }
85  }
86  return 0;
87 }
88 
89 
90 
93  assert(ev.size() > 0);
94  SUMOReal max = (*(ev.begin()))->getSpeed();
95  for (EdgeVector::const_iterator i = ev.begin() + 1; i != ev.end(); i++) {
96  max =
97  max > (*i)->getSpeed()
98  ? max : (*i)->getSpeed();
99  }
100  return max;
101 }
102 
103 
104 
105 /* -------------------------------------------------------------------------
106  * methods from node_with_incoming_finder
107  * ----------------------------------------------------------------------- */
109  : myEdge(e) {}
110 
111 
112 bool
114  const EdgeVector& incoming = n->getIncomingEdges();
115  return std::find(incoming.begin(), incoming.end(), myEdge) != incoming.end();
116 }
117 
118 
119 
120 /* -------------------------------------------------------------------------
121  * methods from node_with_outgoing_finder
122  * ----------------------------------------------------------------------- */
124  : myEdge(e) {}
125 
126 
127 bool
129  const EdgeVector& outgoing = n->getOutgoingEdges();
130  return std::find(outgoing.begin(), outgoing.end(), myEdge) != outgoing.end();
131 }
132 
133 
134 
135 /* -------------------------------------------------------------------------
136  * methods from !!!
137  * ----------------------------------------------------------------------- */
139  : myDestinationNode(dest) {}
140 
141 
142 bool
144  return e->getToNode() == myDestinationNode;
145 }
146 
147 
148 std::ostream&
149 operator<<(std::ostream& os, const EdgeVector& ev) {
150  for (EdgeVector::const_iterator i = ev.begin(); i != ev.end(); i++) {
151  if (i != ev.begin()) {
152  os << ", ";
153  }
154  os << (*i)->getID();
155  }
156  return os;
157 }
158 
159 
160 
161 
162 SUMOReal
164  if (edges.size() == 0) {
165  return -1;
166  }
167  SUMOReal ret = (*(edges.begin()))->getSpeed();
168  for (EdgeVector::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
169  if ((*i)->getSpeed() > ret) {
170  ret = (*i)->getSpeed();
171  }
172  }
173  return ret;
174 }
175 
176 
177 SUMOReal
179  if (edges.size() == 0) {
180  return -1;
181  }
182  SUMOReal ret = (*(edges.begin()))->getSpeed();
183  for (EdgeVector::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
184  if ((*i)->getSpeed() < ret) {
185  ret = (*i)->getSpeed();
186  }
187  }
188  return ret;
189 }
190 
191 
192 
193 /****************************************************************************/
194