SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSCFModel_SmartSK.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A smarter SK
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <microsim/MSVehicle.h>
32 #include <microsim/MSLane.h>
33 #include "MSCFModel_SmartSK.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  SUMOReal dawdle, SUMOReal headwayTime,
43  SUMOReal tmp1, SUMOReal tmp2, SUMOReal tmp3, SUMOReal tmp4, SUMOReal tmp5)
44 // check whether setting these variables here with default values is ''good'' SUMO design
45 // SUMOReal tmp1=0.0, SUMOReal tmp2=5.0, SUMOReal tmp3=0.0, SUMOReal tmp4, SUMOReal tmp5)
46  : MSCFModel(vtype, accel, decel, headwayTime), myDawdle(dawdle), myTauDecel(decel* headwayTime),
47  myTmp1(tmp1), myTmp2(tmp2), myTmp3(tmp3), myTmp4(tmp4), myTmp5(tmp5) {
48  // the variable tmp1 is the acceleration delay time, e.g. two seconds (or something like this).
49  // for use in the upate process, a rule like if (v<myTmp1) vsafe = 0; is needed.
50  // To have this, we have to transform myTmp1 (which is a time) into an equivalent speed. This is done by the
51  // using the vsafe formula and computing:
52  // v(t=myTmp1) = -myTauDecel + sqrt(myTauDecel*myTauDecel + accel*(accel + decel)*t*t + accel*decel*t*TS);
53  SUMOReal t = myTmp1;
54  myS2Sspeed = -myTauDecel + sqrt(myTauDecel * myTauDecel + accel * (accel + decel) * t * t + accel * decel * t * TS);
55  std::cout << "# s2s-speed: " << myS2Sspeed << std::endl;
56  if (myS2Sspeed > 5.0) {
57  myS2Sspeed = 5.0;
58  }
59 // SUMOReal maxDeltaGap = -0.5*ACCEL2DIST(myDecel + myAccel);
60  maxDeltaGap = -0.5 * (myDecel + myAccel) * TS * TS;
61  std::cout << "# maxDeltaGap = " << maxDeltaGap << std::endl;
62  myTmp2 = TS / myTmp2;
63  myTmp3 = sqrt(TS) * myTmp3;
64 }
65 
67 
68 #include <map>
69 
72  const SUMOReal oldV = veh->getSpeed(); // save old v for optional acceleration computation
73  const SUMOReal vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
74  // we need the acceleration for emission computation;
75  // in this case, we neglect dawdling, nonetheless, using
76  // vSafe does not incorporate speed reduction due to interaction
77  // on lane changing
78  const SUMOReal vMin = getSpeedAfterMaxDecel(oldV);
79  const SUMOReal vMax = MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe);
80 #ifdef _DEBUG
81  if (vMin > vMax) {
82  WRITE_WARNING("Vehicle's '" + veh->getID() + "' maximum speed is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
83  }
84 #endif
85  updateMyHeadway(veh);
87 #ifdef _DEBUG
88  if (vars->ggOld.size() > 1) {
89  std::cout << "# more than one entry in ggOld list. Speed is " << vPos << ", corresponding dist is " << vars->ggOld[(int) vPos] << "\n";
90  for (std::map<int, SUMOReal>::iterator I = vars->ggOld.begin(); I != vars->ggOld.end(); I++) {
91  std::cout << "# " << (*I).first << ' ' << (*I).second << std::endl;
92  }
93  }
94 #endif
95 
96  vars->gOld = vars->ggOld[(int) vPos];
97  vars->ggOld.clear();
98  return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, dawdle(vMax)), vMax, *this);
99 }
100 
101 SUMOReal
102 MSCFModel_SmartSK::followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap, SUMOReal predSpeed, SUMOReal /*predMaxDecel*/) const {
104 
105 // if (((gap - vars->gOld) < maxDeltaGap) && (speed>=5.0) && gap>=5.0) {
106  if ((gap - vars->gOld) < maxDeltaGap) {
107  SUMOReal tTauTest = gap / speed;
108 // allow headway only to decrease only, never to increase. Increase is handled automatically by the headway dynamics in moveHelper()!!!
109  if ((tTauTest < vars->myHeadway) && (tTauTest > TS)) {
110  vars->myHeadway = tTauTest;
111  }
112  }
113 
114  SUMOReal vsafe = _vsafe(veh, gap, predSpeed);
115  if ((speed <= 0.0) && (vsafe < myS2Sspeed)) {
116  vsafe = 0;
117  }
118 
119  SUMOReal vNew = MAX2(getSpeedAfterMaxDecel(speed), MIN2(vsafe, maxNextSpeed(speed, veh)));
120  // there must be a better place to do the following assignment!!!
121  vars->gOld = gap;
122  vars->ggOld[(int)vNew] = gap;
123  return vNew;
124 }
125 
126 SUMOReal
127 MSCFModel_SmartSK::stopSpeed(const MSVehicle* const veh, SUMOReal gap) const {
129  SUMOReal speed = veh->getSpeed();
130 
131 // if (((gap - vars->gOld) < maxDeltaGap) && (speed>=5.0) && gap>=5.0) {
132  if ((gap - vars->gOld) < maxDeltaGap) {
133  SUMOReal tTauTest = gap / speed;
134 // allow headway only to decrease only, never to increase. Increase is handled automatically by the headway dynamics in moveHelper()!!!
135  if ((tTauTest < vars->myHeadway) && (tTauTest > TS)) {
136  vars->myHeadway = tTauTest;
137  }
138  }
139 
140  return MAX2(getSpeedAfterMaxDecel(veh->getSpeed()), MIN2(_vsafe(veh, gap, 0), maxNextSpeed(veh->getSpeed(), veh)));
141 }
142 
143 
144 SUMOReal
146  return MAX2(SUMOReal(0), speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand()));
147 }
148 
149 
151 SUMOReal MSCFModel_SmartSK::_vsafe(const MSVehicle* const veh, SUMOReal gap, SUMOReal predSpeed) const {
152  if (predSpeed == 0 && gap < 0.01) {
153  return 0;
154  }
156  // this is the most obvious change to the normal SK: the model uses the variable vars->myHeadway instead of the constant
157  // myHeadwayTime as the "reaction time" tau
158  SUMOReal bTau = myDecel * (vars->myHeadway);
159  SUMOReal vsafe = (SUMOReal)(-1. * bTau
160  + sqrt(
161  bTau * bTau
162  + (predSpeed * predSpeed)
163  + (2. * myDecel * gap)
164  ));
165  assert(vsafe >= 0);
166  return vsafe;
167 }
168 
169 
170 MSCFModel*
174 }