SUMO - Simulation of Urban MObility
 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-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 <microsim/MSVehicle.h>
36 #include <microsim/MSLane.h>
37 #include <microsim/MSGlobals.h>
38 #include "MSCFModel_Krauss.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
47  SUMOReal dawdle, SUMOReal headwayTime)
48  : MSCFModel_KraussOrig1(vtype, accel, decel, dawdle, headwayTime) {
49 }
50 
51 
53 
54 
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 
62 MSCFModel_Krauss::stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal gap) const {
63  return MIN2(_vstop(gap), maxNextSpeed(speed, veh));
64 }
65 
66 
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 
86  gap -= NUMERICAL_EPS; // lots of code relies on some slack
87  if (gap <= 0) {
88  return 0;
89  } else if (gap <= ACCEL2SPEED(myDecel)) {
90  return gap;
91  }
92  const SUMOReal g = gap;
93  const SUMOReal b = ACCEL2SPEED(myDecel);
94  const SUMOReal t = myHeadwayTime;
95  const SUMOReal s = TS;
96  // h = the distance that would be covered if it were possible to stop
97  // exactly after gap and decelerate with b every simulation step
98  // h = 0.5 * n * (n-1) * b * s + n * b * t (solve for n)
99  //n = ((1.0/2.0) - ((t + (pow(((s*s) + (4.0*((s*((2.0*h/b) - t)) + (t*t)))), (1.0/2.0))*sign/2.0))/s));
100  const SUMOReal n = floor((1.0 / 2.0) - ((t + (pow(((s * s) + (4.0 * ((s * ((2.0 * g / b) - t)) + (t * t)))), (1.0 / 2.0)) * -0.5)) / s));
101  const SUMOReal h = 0.5 * n * (n - 1) * b * s + n * b * t;
102  assert(h <= g + NUMERICAL_EPS);
103  // compute the additional speed that must be used during deceleration to fix
104  // the discrepancy between g and h
105  const SUMOReal r = (g - h) / (n * s + t);
106  const SUMOReal x = n * b + r;
107  assert(x >= 0);
108  return x;
109 }
110 
111 
113 SUMOReal
114 MSCFModel_Krauss::_vsafe(SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const {
115  // the speed is safe if allows the ego vehicle to come to a stop behind the leader even if
116  // the leaders starts braking hard until stopped
117  // unfortunately it is not sufficent to compare stopping distances if the follower can brake harder than the leader
118  // (the trajectories might intersect before both vehicles are stopped even if the follower has a shorter stopping distance than the leader)
119  // To make things safe, we ensure that the leaders brake distance is computed with an deceleration that is at least as high as the follower's.
120  // @todo: this is a conservative estimate for safe speed which could be increased
121  const SUMOReal x = _vstop(gap + brakeGap(predSpeed, MAX2(myDecel, predMaxDecel), 0));
122  assert(x >= 0);
123  assert(!ISNAN(x));
124  return x;
125 }
126 
127 
128 MSCFModel*
130  return new MSCFModel_Krauss(vtype, myAccel, myDecel, myDawdle, myHeadwayTime);
131 }
132 
133 
134 //void MSCFModel::saveState(std::ostream &os) {}
135