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
MSVehicleType.cpp
Go to the documentation of this file.
1
/****************************************************************************/
11
// The car-following model and parameter
12
/****************************************************************************/
13
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
14
// Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
15
/****************************************************************************/
16
//
17
// This file is part of SUMO.
18
// SUMO is free software: you can redistribute it and/or modify
19
// it under the terms of the GNU General Public License as published by
20
// the Free Software Foundation, either version 3 of the License, or
21
// (at your option) any later version.
22
//
23
/****************************************************************************/
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 <cassert>
36
#include <
utils/iodevices/BinaryInputDevice.h
>
37
#include <
utils/common/FileHelpers.h
>
38
#include <
utils/common/RandHelper.h
>
39
#include <
utils/common/SUMOVTypeParameter.h
>
40
#include "
MSNet.h
"
41
#include "
cfmodels/MSCFModel_IDM.h
"
42
#include "
cfmodels/MSCFModel_Kerner.h
"
43
#include "
cfmodels/MSCFModel_Krauss.h
"
44
#include "
cfmodels/MSCFModel_KraussOrig1.h
"
45
#include "
cfmodels/MSCFModel_KraussPS.h
"
46
#include "
cfmodels/MSCFModel_SmartSK.h
"
47
#include "
cfmodels/MSCFModel_Daniel1.h
"
48
#include "
cfmodels/MSCFModel_PWag2009.h
"
49
#include "
cfmodels/MSCFModel_Wiedemann.h
"
50
#include "
MSVehicleType.h
"
51
52
#ifdef CHECK_MEMORY_LEAKS
53
#include <
foreign/nvwa/debug_new.h
>
54
#endif // CHECK_MEMORY_LEAKS
55
56
57
// ===========================================================================
58
// static members
59
// ===========================================================================
60
int
MSVehicleType::myNextIndex
= 0;
61
62
63
// ===========================================================================
64
// method definitions
65
// ===========================================================================
66
MSVehicleType::MSVehicleType
(
const
SUMOVTypeParameter
& parameter)
67
: myParameter(parameter), myIndex(myNextIndex++), myOriginalType(0) {
68
assert(
getLength
() > 0);
69
assert(
getMaxSpeed
() > 0);
70
}
71
72
73
MSVehicleType::~MSVehicleType
() {
74
delete
myCarFollowModel
;
75
}
76
77
78
SUMOReal
79
MSVehicleType::computeChosenSpeedDeviation
(
MTRand
& rng,
const
SUMOReal
minDevFactor)
const
{
80
// for speedDev = 0.1, most 95% of the vehicles will drive between 80% and 120% of speedLimit * speedFactor
81
const
SUMOReal
devA =
MIN2
(
SUMOReal
(2.),
RandHelper::randNorm
(0, 1., rng));
82
// avoid voluntary speeds below 20% of the requested speedFactor
83
return
MAX2
(minDevFactor,
SUMOReal
(devA *
myParameter
.
speedDev
+ 1.)) *
myParameter
.
speedFactor
;
84
}
85
86
87
// ------------ Setter methods
88
void
89
MSVehicleType::setLength
(
const
SUMOReal
& length) {
90
if
(
myOriginalType
!= 0 && length < 0) {
91
myParameter
.
length
=
myOriginalType
->
getLength
();
92
}
else
{
93
myParameter
.
length
= length;
94
}
95
}
96
97
98
void
99
MSVehicleType::setMinGap
(
const
SUMOReal
& minGap) {
100
if
(
myOriginalType
!= 0 && minGap < 0) {
101
myParameter
.
minGap
=
myOriginalType
->
getMinGap
();
102
}
else
{
103
myParameter
.
minGap
= minGap;
104
}
105
}
106
107
108
void
109
MSVehicleType::setMaxSpeed
(
const
SUMOReal
& maxSpeed) {
110
if
(
myOriginalType
!= 0 && maxSpeed < 0) {
111
myParameter
.
maxSpeed
=
myOriginalType
->
getMaxSpeed
();
112
}
else
{
113
myParameter
.
maxSpeed
= maxSpeed;
114
}
115
}
116
117
118
void
119
MSVehicleType::setVClass
(
SUMOVehicleClass
vclass) {
120
myParameter
.
vehicleClass
= vclass;
121
}
122
123
124
void
125
MSVehicleType::setDefaultProbability
(
const
SUMOReal
& prob) {
126
if
(
myOriginalType
!= 0 && prob < 0) {
127
myParameter
.
defaultProbability
=
myOriginalType
->
getDefaultProbability
();
128
}
else
{
129
myParameter
.
defaultProbability
= prob;
130
}
131
}
132
133
134
void
135
MSVehicleType::setSpeedFactor
(
const
SUMOReal
& factor) {
136
if
(
myOriginalType
!= 0 && factor < 0) {
137
myParameter
.
speedFactor
=
myOriginalType
->
getSpeedFactor
();
138
}
else
{
139
myParameter
.
speedFactor
= factor;
140
}
141
}
142
143
144
void
145
MSVehicleType::setSpeedDeviation
(
const
SUMOReal
& dev) {
146
if
(
myOriginalType
!= 0 && dev < 0) {
147
myParameter
.
speedDev
=
myOriginalType
->
getSpeedDeviation
();
148
}
else
{
149
myParameter
.
speedDev
= dev;
150
}
151
}
152
153
154
void
155
MSVehicleType::setEmissionClass
(
SUMOEmissionClass
eclass) {
156
myParameter
.
emissionClass
= eclass;
157
}
158
159
160
void
161
MSVehicleType::setColor
(
const
RGBColor
& color) {
162
myParameter
.
color
= color;
163
}
164
165
166
void
167
MSVehicleType::setWidth
(
const
SUMOReal
& width) {
168
if
(
myOriginalType
!= 0 && width < 0) {
169
myParameter
.
width
=
myOriginalType
->
getWidth
();
170
}
else
{
171
myParameter
.
width
= width;
172
}
173
}
174
175
176
void
177
MSVehicleType::setImpatience
(
const
SUMOReal
impatience) {
178
if
(
myOriginalType
!= 0 && impatience < 0) {
179
myParameter
.
impatience
=
myOriginalType
->
getImpatience
();
180
}
else
{
181
myParameter
.
impatience
= impatience;
182
}
183
}
184
185
186
void
187
MSVehicleType::setShape
(
SUMOVehicleShape
shape) {
188
myParameter
.
shape
= shape;
189
}
190
191
192
193
// ------------ Static methods for building vehicle types
194
MSVehicleType
*
195
MSVehicleType::build
(
SUMOVTypeParameter
& from) {
196
MSVehicleType
* vtype =
new
MSVehicleType
(from);
197
const
SUMOReal
accel = from.
get
(
SUMO_ATTR_ACCEL
,
SUMOVTypeParameter::getDefaultAccel
(from.
vehicleClass
));
198
const
SUMOReal
decel = from.
get
(
SUMO_ATTR_DECEL
,
SUMOVTypeParameter::getDefaultDecel
(from.
vehicleClass
));
199
const
SUMOReal
sigma = from.
get
(
SUMO_ATTR_SIGMA
,
SUMOVTypeParameter::getDefaultImperfection
(from.
vehicleClass
));
200
const
SUMOReal
tau = from.
get
(
SUMO_ATTR_TAU
, 1.);
201
switch
(from.
cfModel
) {
202
case
SUMO_TAG_CF_IDM
:
203
vtype->
myCarFollowModel
=
new
MSCFModel_IDM
(vtype, accel, decel, tau,
204
from.
get
(
SUMO_ATTR_CF_IDM_DELTA
, 4.),
205
from.
get
(
SUMO_ATTR_CF_IDM_STEPPING
, .25));
206
break
;
207
case
SUMO_TAG_CF_IDMM
:
208
vtype->
myCarFollowModel
=
new
MSCFModel_IDM
(vtype, accel, decel, tau,
209
from.
get
(
SUMO_ATTR_CF_IDMM_ADAPT_FACTOR
, 1.8),
210
from.
get
(
SUMO_ATTR_CF_IDMM_ADAPT_TIME
, 600.),
211
from.
get
(
SUMO_ATTR_CF_IDM_STEPPING
, .25));
212
break
;
213
case
SUMO_TAG_CF_BKERNER
:
214
vtype->
myCarFollowModel
=
new
MSCFModel_Kerner
(vtype, accel, decel, tau,
215
from.
get
(
SUMO_ATTR_K
, .5),
216
from.
get
(
SUMO_ATTR_CF_KERNER_PHI
, 5.));
217
break
;
218
case
SUMO_TAG_CF_KRAUSS_ORIG1
:
219
vtype->
myCarFollowModel
=
new
MSCFModel_KraussOrig1
(vtype, accel, decel, sigma, tau);
220
break
;
221
case
SUMO_TAG_CF_KRAUSS_PLUS_SLOPE
:
222
vtype->
myCarFollowModel
=
new
MSCFModel_KraussPS
(vtype, accel, decel, sigma, tau);
223
break
;
224
case
SUMO_TAG_CF_SMART_SK
:
225
vtype->
myCarFollowModel
=
new
MSCFModel_SmartSK
(vtype, accel, decel, sigma, tau,
226
from.
get
(
SUMO_ATTR_TMP1
, 1.),
227
from.
get
(
SUMO_ATTR_TMP2
, 1.),
228
from.
get
(
SUMO_ATTR_TMP3
, 1.),
229
from.
get
(
SUMO_ATTR_TMP4
, 1.),
230
from.
get
(
SUMO_ATTR_TMP5
, 1.));
231
break
;
232
case
SUMO_TAG_CF_DANIEL1
:
233
vtype->
myCarFollowModel
=
new
MSCFModel_Daniel1
(vtype, accel, decel, sigma, tau,
234
from.
get
(
SUMO_ATTR_TMP1
, 1.),
235
from.
get
(
SUMO_ATTR_TMP2
, 1.),
236
from.
get
(
SUMO_ATTR_TMP3
, 1.),
237
from.
get
(
SUMO_ATTR_TMP4
, 1.),
238
from.
get
(
SUMO_ATTR_TMP5
, 1.));
239
break
;
240
case
SUMO_TAG_CF_PWAGNER2009
:
241
vtype->
myCarFollowModel
=
new
MSCFModel_PWag2009
(vtype, accel, decel, sigma, tau,
242
from.
get
(
SUMO_ATTR_CF_PWAGNER2009_TAULAST
, 0.3),
243
from.
get
(
SUMO_ATTR_CF_PWAGNER2009_APPROB
, 0.5));
244
break
;
245
case
SUMO_TAG_CF_WIEDEMANN
:
246
vtype->
myCarFollowModel
=
new
MSCFModel_Wiedemann
(vtype, accel, decel,
247
from.
get
(
SUMO_ATTR_CF_WIEDEMANN_SECURITY
, 0.5),
248
from.
get
(
SUMO_ATTR_CF_WIEDEMANN_ESTIMATION
, 0.5));
249
break
;
250
case
SUMO_TAG_CF_KRAUSS
:
251
default
:
252
vtype->
myCarFollowModel
=
new
MSCFModel_Krauss
(vtype, accel, decel, sigma, tau);
253
break
;
254
}
255
return
vtype;
256
}
257
258
259
MSVehicleType
*
260
MSVehicleType::build
(
const
std::string&
id
,
const
MSVehicleType
* from) {
261
MSVehicleType
* vtype =
new
MSVehicleType
(from->
myParameter
);
262
vtype->
myParameter
.
id
= id;
263
vtype->
myCarFollowModel
= from->
myCarFollowModel
->
duplicate
(vtype);
264
vtype->
myOriginalType
= from->
myOriginalType
!= 0 ? from->
myOriginalType
: from;
265
return
vtype;
266
}
267
268
269
/****************************************************************************/
270
tmp
buildd
sumo-0.21.0+dfsg
src
microsim
MSVehicleType.cpp
Generated on Thu Nov 20 2014 19:49:56 for SUMO - Simulation of Urban MObility by
1.8.1.2