SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
NBAlgorithms.h
Go to the documentation of this file.
1
/****************************************************************************/
8
// Algorithms for network computation
9
/****************************************************************************/
10
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11
// Copyright (C) 2012-2014 DLR (http://www.dlr.de/) and contributors
12
/****************************************************************************/
13
//
14
// This file is part of SUMO.
15
// SUMO is free software: you can redistribute it and/or modify
16
// it under the terms of the GNU General Public License as published by
17
// the Free Software Foundation, either version 3 of the License, or
18
// (at your option) any later version.
19
//
20
/****************************************************************************/
21
#ifndef NBAlgorithms_h
22
#define NBAlgorithms_h
23
24
25
// ===========================================================================
26
// included modules
27
// ===========================================================================
28
#ifdef _MSC_VER
29
#include <
windows_config.h
>
30
#else
31
#include <
config.h
>
32
#endif
33
34
#include <map>
35
36
37
// ===========================================================================
38
// class declarations
39
// ===========================================================================
40
class
NBEdge
;
41
class
NBNodeCont
;
42
class
NBTypeCont
;
43
44
// ===========================================================================
45
// class definitions
46
// ===========================================================================
47
// ---------------------------------------------------------------------------
48
// NBTurningDirectionsComputer
49
// ---------------------------------------------------------------------------
50
/* @class NBTurningDirectionsComputer
51
* @brief Computes turnaround destinations for all edges (if exist)
52
*/
53
class
NBTurningDirectionsComputer
{
54
public
:
58
static
void
computeTurnDirections
(
NBNodeCont
& nc);
59
64
static
void
computeTurnDirectionsForNode
(
NBNode
* node);
65
66
private
:
73
struct
Combination
{
74
NBEdge
*
from
;
75
NBEdge
*
to
;
76
SUMOReal
angle
;
77
};
78
79
83
class
combination_by_angle_sorter
{
84
public
:
85
explicit
combination_by_angle_sorter
() { }
86
int
operator()
(
const
Combination
& c1,
const
Combination
& c2)
const
{
87
if
(c1.
angle
!= c2.
angle
) {
88
return
c1.
angle
> c2.
angle
;
89
}
90
if
(c1.
from
!= c2.
from
) {
91
return
c1.
from
->
getID
() < c2.
from
->
getID
();
92
}
93
return
c1.
to
->
getID
() < c2.
to
->
getID
();
94
}
95
};
96
};
97
98
99
100
// ---------------------------------------------------------------------------
101
// NBNodesEdgesSorter
102
// ---------------------------------------------------------------------------
103
/* @class NBNodesEdgesSorter
104
* @brief Sorts a node's edges clockwise regarding driving direction
105
*/
106
class
NBNodesEdgesSorter
{
107
public
:
112
static
void
sortNodesEdges
(
NBNodeCont
& nc,
bool
leftHand);
113
118
class
crossing_by_junction_angle_sorter
{
119
public
:
120
explicit
crossing_by_junction_angle_sorter
(
const
EdgeVector
& ordering) :
myOrdering
(ordering) {}
121
int
operator()
(
const
NBNode::Crossing
& c1,
const
NBNode::Crossing
& c2)
const
{
122
return
(
int
)(
getMinRank
(c1.
edges
) <
getMinRank
(c2.
edges
));
123
}
124
125
private
:
127
size_t
getMinRank
(
const
EdgeVector
& e)
const
{
128
size_t
result =
myOrdering
.size();
129
for
(EdgeVector::const_iterator it = e.begin(); it != e.end(); ++it) {
130
size_t
rank = std::distance(
myOrdering
.begin(), std::find(
myOrdering
.begin(),
myOrdering
.end(), *it));
131
result =
MIN2
(result, rank);
132
}
133
return
result;
134
}
135
136
private
:
137
const
EdgeVector
&
myOrdering
;
138
139
private
:
141
crossing_by_junction_angle_sorter
&
operator=
(
const
crossing_by_junction_angle_sorter
& s);
142
143
};
144
private
:
151
static
void
swapWhenReversed
(
const
NBNode
*
const
n,
bool
leftHand,
152
const
std::vector<NBEdge*>::iterator& i1,
153
const
std::vector<NBEdge*>::iterator& i2);
154
155
159
class
edge_by_junction_angle_sorter
{
160
public
:
161
explicit
edge_by_junction_angle_sorter
(
NBNode
* n) :
myNode
(n) {}
162
int
operator()
(
NBEdge
* e1,
NBEdge
* e2)
const
{
163
return
getConvAngle
(e1) <
getConvAngle
(e2);
164
}
165
166
protected
:
168
SUMOReal
getConvAngle
(
NBEdge
* e)
const
{
169
SUMOReal
angle = e->
getAngleAtNode
(
myNode
);
170
if
(angle < 0.) {
171
angle = 360. + angle;
172
}
173
// convert angle if the edge is an outgoing edge
174
if
(e->
getFromNode
() ==
myNode
) {
175
angle += (
SUMOReal
) 180.;
176
if
(angle >= (
SUMOReal
) 360.) {
177
angle -= (
SUMOReal
) 360.;
178
}
179
}
180
if
(angle < 0.1 || angle > 359.9) {
181
angle = (
SUMOReal
) 0.;
182
}
183
assert(angle >= (
SUMOReal
)0 && angle < (
SUMOReal
)360);
184
return
angle;
185
}
186
187
private
:
189
NBNode
*
myNode
;
190
191
};
192
193
};
194
195
196
197
// ---------------------------------------------------------------------------
198
// NBNodeTypeComputer
199
// ---------------------------------------------------------------------------
200
/* @class NBNodeTypeComputer
201
* @brief Computes node types
202
*/
203
class
NBNodeTypeComputer
{
204
public
:
208
static
void
computeNodeTypes
(
NBNodeCont
& nc);
209
210
};
211
212
213
214
// ---------------------------------------------------------------------------
215
// NBEdgePriorityComputer
216
// ---------------------------------------------------------------------------
217
/* @class NBEdgePriorityComputer
218
* @brief Computes edge priorities within a node
219
*/
220
class
NBEdgePriorityComputer
{
221
public
:
225
static
void
computeEdgePriorities
(
NBNodeCont
& nc);
226
227
private
:
231
static
void
setPriorityJunctionPriorities
(
NBNode
& n);
232
238
static
NBEdge
*
extractAndMarkFirst
(
NBNode
& n, std::vector<NBEdge*>& s);
239
245
static
bool
samePriority
(
const
NBEdge
*
const
e1,
const
NBEdge
*
const
e2);
246
247
};
248
249
#endif
250
251
/****************************************************************************/
252
tmp
buildd
sumo-0.21.0+dfsg
src
netbuild
NBAlgorithms.h
Generated on Thu Nov 20 2014 19:49:56 for SUMO - Simulation of Urban MObility by
1.8.1.2