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.cpp
Go to the documentation of this file.
1
/****************************************************************************/
11
// The car-following model abstraction
12
/****************************************************************************/
13
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
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 <math.h>
36
#include "
MSCFModel.h
"
37
#include "
MSVehicleType.h
"
38
#include "
MSVehicle.h
"
39
#include "
MSLane.h
"
40
#include "
MSAbstractLaneChangeModel.h
"
41
42
43
// ===========================================================================
44
// method definitions
45
// ===========================================================================
46
MSCFModel::MSCFModel
(
const
MSVehicleType
* vtype,
const
SUMOReal
accel,
47
const
SUMOReal
decel,
const
SUMOReal
headwayTime)
48
: myType(vtype), myAccel(accel), myDecel(decel), myHeadwayTime(headwayTime) {
49
}
50
51
52
MSCFModel::~MSCFModel
() {}
53
54
55
SUMOReal
56
MSCFModel::moveHelper
(
MSVehicle
*
const
veh,
SUMOReal
vPos)
const
{
57
const
SUMOReal
oldV = veh->
getSpeed
();
// save old v for optional acceleration computation
58
const
SUMOReal
vSafe =
MIN2
(vPos, veh->
processNextStop
(vPos));
// process stops
59
// we need the acceleration for emission computation;
60
// in this case, we neglect dawdling, nonetheless, using
61
// vSafe does not incorporate speed reduction due to interaction
62
// on lane changing
63
const
SUMOReal
vMin =
getSpeedAfterMaxDecel
(oldV);
64
const
SUMOReal
vMax =
MIN3
(veh->
getLane
()->
getVehicleMaxSpeed
(veh),
maxNextSpeed
(oldV, veh), vSafe);
65
assert(vMin <= vMax);
66
return
veh->
getLaneChangeModel
().
patchSpeed
(vMin, vMax, vMax, *
this
);
67
}
68
69
70
SUMOReal
71
MSCFModel::interactionGap
(
const
MSVehicle
*
const
veh,
SUMOReal
vL)
const
{
72
// Resolve the vsafe equation to gap. Assume predecessor has
73
// speed != 0 and that vsafe will be the current speed plus acceleration,
74
// i.e that with this gap there will be no interaction.
75
const
SUMOReal
vNext =
MIN2
(
maxNextSpeed
(veh->
getSpeed
(), veh), veh->
getLane
()->
getVehicleMaxSpeed
(veh));
76
const
SUMOReal
gap = (vNext - vL) *
77
((veh->
getSpeed
() + vL) / (2.*
myDecel
) +
myHeadwayTime
) +
78
vL *
myHeadwayTime
;
79
80
// Don't allow timeHeadWay < deltaT situations.
81
return
MAX2
(gap,
SPEED2DIST
(vNext));
82
}
83
84
85
void
86
MSCFModel::leftVehicleVsafe
(
const
MSVehicle
*
const
ego,
const
MSVehicle
*
const
neigh,
SUMOReal
& vSafe)
const
{
87
if
(neigh != 0 && neigh->
getSpeed
() > 60. / 3.6) {
88
SUMOReal
mgap =
MAX2
((
SUMOReal
) 0, neigh->
getPositionOnLane
() - neigh->
getVehicleType
().
getLength
() - ego->
getPositionOnLane
() - ego->
getVehicleType
().
getMinGap
());
89
SUMOReal
nVSafe =
followSpeed
(ego, ego->
getSpeed
(), mgap, neigh->
getSpeed
(), neigh->
getCarFollowModel
().
getMaxDecel
());
90
if
(mgap - neigh->
getSpeed
() >= 0) {
91
vSafe =
MIN2
(vSafe, nVSafe);
92
}
93
}
94
}
95
96
97
SUMOReal
98
MSCFModel::maxNextSpeed
(
SUMOReal
speed,
const
MSVehicle
*
const
/*veh*/
)
const
{
99
return
MIN2
(speed + (
SUMOReal
)
ACCEL2SPEED
(
getMaxAccel
()),
myType
->
getMaxSpeed
());
100
}
101
102
103
SUMOReal
104
MSCFModel::brakeGap
(
SUMOReal
speed)
const
{
105
/* one possiblity to speed this up is to precalculate speedReduction * steps * (steps+1) / 2
106
for small values of steps (up to 10 maybe) and store them in an array */
107
const
SUMOReal
speedReduction =
ACCEL2SPEED
(
getMaxDecel
());
108
const
int
steps =
int
(speed / speedReduction);
109
return
SPEED2DIST
(steps * speed - speedReduction * steps * (steps + 1) / 2) + speed *
myHeadwayTime
;
110
}
111
112
113
SUMOReal
114
MSCFModel::freeSpeed
(
const
MSVehicle
*
const
veh,
SUMOReal
speed,
SUMOReal
seen,
SUMOReal
maxSpeed)
const
{
115
UNUSED_PARAMETER
(veh);
116
// adapt speed to succeeding lane, no reaction time is involved
117
// when breaking for y steps the following distance g is covered
118
// (drive with v in the final step)
119
// g = (y^2 + y) * 0.5 * b + y * v
120
// y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
121
const
SUMOReal
b =
ACCEL2SPEED
(
myDecel
);
122
const
SUMOReal
y =
MAX2
(0.0, ((sqrt((b + 2.0 * maxSpeed) * (b + 2.0 * maxSpeed) + 8.0 * b * seen) - b) * 0.5 - maxSpeed) / b);
123
const
SUMOReal
yFull = floor(y);
124
const
SUMOReal
exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * maxSpeed + (y > yFull ? maxSpeed : 0.0);
125
return
MAX2
((
SUMOReal
)0.0, seen - exactGap) / (yFull + 1) + yFull *
myDecel
+ maxSpeed;
126
}
127
128
/****************************************************************************/
build
buildd
sumo-0.17.1~dfsg
src
microsim
MSCFModel.cpp
Generated on Sun Jun 16 2013 17:30:16 for SUMO - Simulation of Urban MObility by
1.8.3.1