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-2013 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
// method definitions
59
// ===========================================================================
60
MSVehicleType::MSVehicleType
(
const
SUMOVTypeParameter
& parameter)
61
: myParameter(parameter), myOriginalType(0) {
62
assert(
getLength
() > 0);
63
assert(
getMaxSpeed
() > 0);
64
}
65
66
67
MSVehicleType::~MSVehicleType
() {
68
delete
myCarFollowModel
;
69
}
70
71
72
SUMOReal
73
MSVehicleType::computeChosenSpeedDeviation
(
MTRand
& rng,
const
SUMOReal
minDevFactor)
const
{
74
// for speedDev = 0.1, most 95% of the vehicles will drive between 80% and 120% of speedLimit * speedFactor
75
const
SUMOReal
devA =
MIN2
(
SUMOReal
(2.),
RandHelper::randNorm
(0, 1., rng));
76
// avoid voluntary speeds below 20% of the requested speedFactor
77
return
MAX2
(minDevFactor,
SUMOReal
(devA *
myParameter
.
speedDev
+ 1.)) *
myParameter
.
speedFactor
;
78
}
79
80
81
// ------------ Setter methods
82
void
83
MSVehicleType::setLength
(
const
SUMOReal
& length) {
84
if
(
myOriginalType
!= 0 && length < 0) {
85
myParameter
.
length
=
myOriginalType
->
getLength
();
86
}
else
{
87
myParameter
.
length
= length;
88
}
89
}
90
91
92
void
93
MSVehicleType::setMinGap
(
const
SUMOReal
& minGap) {
94
if
(
myOriginalType
!= 0 && minGap < 0) {
95
myParameter
.
minGap
=
myOriginalType
->
getMinGap
();
96
}
else
{
97
myParameter
.
minGap
= minGap;
98
}
99
}
100
101
102
void
103
MSVehicleType::setMaxSpeed
(
const
SUMOReal
& maxSpeed) {
104
if
(
myOriginalType
!= 0 && maxSpeed < 0) {
105
myParameter
.
maxSpeed
=
myOriginalType
->
getMaxSpeed
();
106
}
else
{
107
myParameter
.
maxSpeed
= maxSpeed;
108
}
109
}
110
111
112
void
113
MSVehicleType::setVClass
(
SUMOVehicleClass
vclass) {
114
myParameter
.
vehicleClass
= vclass;
115
}
116
117
118
void
119
MSVehicleType::setDefaultProbability
(
const
SUMOReal
& prob) {
120
if
(
myOriginalType
!= 0 && prob < 0) {
121
myParameter
.
defaultProbability
=
myOriginalType
->
getDefaultProbability
();
122
}
else
{
123
myParameter
.
defaultProbability
= prob;
124
}
125
}
126
127
128
void
129
MSVehicleType::setSpeedFactor
(
const
SUMOReal
& factor) {
130
if
(
myOriginalType
!= 0 && factor < 0) {
131
myParameter
.
speedFactor
=
myOriginalType
->
getSpeedFactor
();
132
}
else
{
133
myParameter
.
speedFactor
= factor;
134
}
135
}
136
137
138
void
139
MSVehicleType::setSpeedDeviation
(
const
SUMOReal
& dev) {
140
if
(
myOriginalType
!= 0 && dev < 0) {
141
myParameter
.
speedDev
=
myOriginalType
->
getSpeedDeviation
();
142
}
else
{
143
myParameter
.
speedDev
= dev;
144
}
145
}
146
147
148
void
149
MSVehicleType::setEmissionClass
(
SUMOEmissionClass
eclass) {
150
myParameter
.
emissionClass
= eclass;
151
}
152
153
154
void
155
MSVehicleType::setColor
(
const
RGBColor
& color) {
156
myParameter
.
color
= color;
157
}
158
159
160
void
161
MSVehicleType::setWidth
(
const
SUMOReal
& width) {
162
if
(
myOriginalType
!= 0 && width < 0) {
163
myParameter
.
width
=
myOriginalType
->
getWidth
();
164
}
else
{
165
myParameter
.
width
= width;
166
}
167
}
168
169
170
void
171
MSVehicleType::setImpatience
(
const
SUMOReal
impatience) {
172
if
(
myOriginalType
!= 0 && impatience < 0) {
173
myParameter
.
impatience
=
myOriginalType
->
getImpatience
();
174
}
else
{
175
myParameter
.
impatience
= impatience;
176
}
177
}
178
179
180
void
181
MSVehicleType::setShape
(
SUMOVehicleShape
shape) {
182
myParameter
.
shape
= shape;
183
}
184
185
186
187
// ------------ Static methods for building vehicle types
188
MSVehicleType
*
189
MSVehicleType::build
(
SUMOVTypeParameter
& from) {
190
MSVehicleType
* vtype =
new
MSVehicleType
(from);
191
MSCFModel
* model = 0;
192
switch
(from.
cfModel
) {
193
case
SUMO_TAG_CF_IDM
:
194
model =
new
MSCFModel_IDM
(vtype,
195
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
196
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
197
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_TAU
),
198
from.
get
(
SUMO_ATTR_CF_IDM_DELTA
, 4.),
199
from.
get
(
SUMO_ATTR_CF_IDM_STEPPING
, .25));
200
break
;
201
case
SUMO_TAG_CF_IDMM
:
202
model =
new
MSCFModel_IDM
(vtype,
203
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
204
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
205
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_TAU
),
206
from.
get
(
SUMO_ATTR_CF_IDMM_ADAPT_FACTOR
, 1.8),
207
from.
get
(
SUMO_ATTR_CF_IDMM_ADAPT_TIME
, 600.),
208
from.
get
(
SUMO_ATTR_CF_IDM_STEPPING
, .25));
209
break
;
210
case
SUMO_TAG_CF_BKERNER
:
211
model =
new
MSCFModel_Kerner
(vtype,
212
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
213
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
214
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_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
model =
new
MSCFModel_KraussOrig1
(vtype,
220
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
221
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
222
from.
get
(
SUMO_ATTR_SIGMA
,
DEFAULT_VEH_SIGMA
),
223
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_TAU
));
224
break
;
225
case
SUMO_TAG_CF_KRAUSS_PLUS_SLOPE
:
226
model =
new
MSCFModel_KraussPS
(vtype,
227
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
228
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
229
from.
get
(
SUMO_ATTR_SIGMA
,
DEFAULT_VEH_SIGMA
),
230
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_TAU
));
231
break
;
232
case
SUMO_TAG_CF_SMART_SK
:
233
model =
new
MSCFModel_SmartSK
(vtype,
234
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
235
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
236
from.
get
(
SUMO_ATTR_SIGMA
,
DEFAULT_VEH_SIGMA
),
237
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_TAU
),
238
from.
get
(
SUMO_ATTR_TMP1
,
DEFAULT_VEH_TMP1
),
239
from.
get
(
SUMO_ATTR_TMP2
,
DEFAULT_VEH_TMP2
),
240
from.
get
(
SUMO_ATTR_TMP3
,
DEFAULT_VEH_TMP3
),
241
from.
get
(
SUMO_ATTR_TMP4
,
DEFAULT_VEH_TMP4
),
242
from.
get
(
SUMO_ATTR_TMP5
,
DEFAULT_VEH_TMP5
));
243
break
;
244
case
SUMO_TAG_CF_DANIEL1
:
245
model =
new
MSCFModel_Daniel1
(vtype,
246
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
247
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
248
from.
get
(
SUMO_ATTR_SIGMA
,
DEFAULT_VEH_SIGMA
),
249
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_TAU
),
250
from.
get
(
SUMO_ATTR_TMP1
,
DEFAULT_VEH_TMP1
),
251
from.
get
(
SUMO_ATTR_TMP2
,
DEFAULT_VEH_TMP2
),
252
from.
get
(
SUMO_ATTR_TMP3
,
DEFAULT_VEH_TMP3
),
253
from.
get
(
SUMO_ATTR_TMP4
,
DEFAULT_VEH_TMP4
),
254
from.
get
(
SUMO_ATTR_TMP5
,
DEFAULT_VEH_TMP5
));
255
break
;
256
case
SUMO_TAG_CF_PWAGNER2009
:
257
model =
new
MSCFModel_PWag2009
(vtype,
258
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
259
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
260
from.
get
(
SUMO_ATTR_SIGMA
,
DEFAULT_VEH_SIGMA
),
261
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_TAU
),
262
from.
get
(
SUMO_ATTR_CF_PWAGNER2009_TAULAST
, 0.3),
263
from.
get
(
SUMO_ATTR_CF_PWAGNER2009_APPROB
, 0.5));
264
break
;
265
case
SUMO_TAG_CF_WIEDEMANN
:
266
model =
new
MSCFModel_Wiedemann
(vtype,
267
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
268
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
269
from.
get
(
SUMO_ATTR_CF_WIEDEMANN_SECURITY
, 0.5),
270
from.
get
(
SUMO_ATTR_CF_WIEDEMANN_ESTIMATION
, 0.5));
271
break
;
272
case
SUMO_TAG_CF_KRAUSS
:
273
default
:
274
model =
new
MSCFModel_Krauss
(vtype,
275
from.
get
(
SUMO_ATTR_ACCEL
,
DEFAULT_VEH_ACCEL
),
276
from.
get
(
SUMO_ATTR_DECEL
,
DEFAULT_VEH_DECEL
),
277
from.
get
(
SUMO_ATTR_SIGMA
,
DEFAULT_VEH_SIGMA
),
278
from.
get
(
SUMO_ATTR_TAU
,
DEFAULT_VEH_TAU
));
279
break
;
280
}
281
vtype->
myCarFollowModel
= model;
282
return
vtype;
283
}
284
285
286
MSVehicleType
*
287
MSVehicleType::build
(
const
std::string&
id
,
const
MSVehicleType
* from) {
288
MSVehicleType
* vtype =
new
MSVehicleType
(from->
myParameter
);
289
vtype->
myParameter
.
id
= id;
290
vtype->
myCarFollowModel
= from->
myCarFollowModel
->
duplicate
(vtype);
291
vtype->
myOriginalType
= from->
myOriginalType
!= 0 ? from->
myOriginalType
: from;
292
return
vtype;
293
}
294
295
296
/****************************************************************************/
297
home
delphi
sumo
src
microsim
MSVehicleType.cpp
Generated by
1.8.2