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
MSCFModel_Krauss.cpp
Go to the documentation of this file.
1
/****************************************************************************/
11
// Krauss car-following model, with acceleration decrease and faster start
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 <
microsim/MSVehicle.h
>
36
#include <
microsim/MSLane.h
>
37
#include <
microsim/MSGlobals.h
>
38
#include "
MSCFModel_Krauss.h
"
39
#include <
microsim/MSAbstractLaneChangeModel.h
>
40
#include <
utils/common/RandHelper.h
>
41
42
43
// ===========================================================================
44
// method definitions
45
// ===========================================================================
46
MSCFModel_Krauss::MSCFModel_Krauss
(
const
MSVehicleType
* vtype,
SUMOReal
accel,
SUMOReal
decel,
47
SUMOReal
dawdle,
SUMOReal
headwayTime)
48
:
MSCFModel_KraussOrig1
(vtype, accel, decel, dawdle, headwayTime) {
49
}
50
51
52
MSCFModel_Krauss::~MSCFModel_Krauss
() {}
53
54
55
SUMOReal
56
MSCFModel_Krauss::followSpeed
(
const
MSVehicle
*
const
veh,
const
SUMOReal
speed,
SUMOReal
gap,
SUMOReal
predSpeed,
SUMOReal
predMaxDecel)
const
{
57
return
MIN2
(
_vsafe
(gap, predSpeed, predMaxDecel),
maxNextSpeed
(speed, veh));
58
}
59
60
61
SUMOReal
62
MSCFModel_Krauss::stopSpeed
(
const
MSVehicle
*
const
veh,
const
SUMOReal
speed,
SUMOReal
gap)
const
{
63
return
MIN2
(
_vsafe
(gap, 0, 0),
maxNextSpeed
(speed, veh));
64
}
65
66
67
SUMOReal
68
MSCFModel_Krauss::dawdle
(
SUMOReal
speed)
const
{
69
// generate random number out of [0,1]
70
SUMOReal
random =
RandHelper::rand
();
71
// Dawdle.
72
if
(speed <
myAccel
) {
73
// we should not prevent vehicles from driving just due to dawdling
74
// if someone is starting, he should definitely start
75
// (but what about slow-to-start?)!!!
76
speed -=
ACCEL2SPEED
(
myDawdle
* speed * random);
77
}
else
{
78
speed -=
ACCEL2SPEED
(
myDawdle
*
myAccel
* random);
79
}
80
return
MAX2
(
SUMOReal
(0), speed);
81
}
82
83
85
SUMOReal
86
MSCFModel_Krauss::_vsafe
(
SUMOReal
gap,
SUMOReal
predSpeed,
SUMOReal
predMaxDecel)
const
{
87
if
(predSpeed < predMaxDecel) {
88
// avoid discretization error at low speeds
89
predSpeed = 0;
90
}
91
if
(predSpeed == 0) {
92
if
(gap < 0.01) {
93
return
0;
94
}
95
// g = t * x + x^2 / (2 * b)
96
const
SUMOReal
result = (
SUMOReal
)(-
myTauDecel
+ sqrt(
myTauDecel
*
myTauDecel
+ 2. *
myDecel
* gap));
97
assert(result >= 0);
98
return
result;
99
}
100
if
(gap < 0) {
101
gap = 0;
102
}
103
// follow the leader
104
// g=gap, t=myHeadwayTime, a=predMaxDecel, b=myDecel, v=predSpeed, x=vSafe
105
// Solution approach: equal distances after leader and follower have stopped (partly discretized).
106
// g + (v^2 - a*v)/(2*a) = x*t + (x^2 - b*x)/(2*b) + 0.5
107
// The term (+ 0.5) gives an upper bound for the follower stopping distance to handle discretization errors.
108
// Unfortunately, the solution approach is not correct when b > a since the
109
// follower path may cross the leader path even with equal stopping distances.
110
// As a workaround we lower the value of b to get a collision free model
111
// This approach should be refined to get a higher (still safe) following speed.
112
const
SUMOReal
egoDecel =
MIN2
(
myDecel
, predMaxDecel);
113
const
SUMOReal
result = (
SUMOReal
)(0.5 * sqrt(
114
4.0 * egoDecel * (2.0 * gap + predSpeed * predSpeed / predMaxDecel - predSpeed - 1.0)
115
+ (egoDecel * (2.0 *
myHeadwayTime
- 1.0))
116
* (egoDecel * (2.0 *
myHeadwayTime
- 1.0)))
117
+ egoDecel * (0.5 -
myHeadwayTime
));
118
// XXX recheck use of both branches of the quadratic forumula
119
if
(
ISNAN
(result)) {
120
return
0;
121
}
else
{
122
return
MAX2
((
SUMOReal
)0, result);
123
}
124
}
125
126
127
MSCFModel
*
128
MSCFModel_Krauss::duplicate
(
const
MSVehicleType
* vtype)
const
{
129
return
new
MSCFModel_Krauss
(vtype,
myAccel
,
myDecel
,
myDawdle
,
myHeadwayTime
);
130
}
131
132
133
//void MSCFModel::saveState(std::ostream &os) {}
134
home
delphi
sumo
src
microsim
cfmodels
MSCFModel_Krauss.cpp
Generated by
1.8.2