SUMO - Simulation of Urban MObility
 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-2012 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 "MSCFModel.h"
36 #include "MSVehicleType.h"
37 #include "MSVehicle.h"
38 #include "MSLane.h"
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 MSCFModel::MSCFModel(const MSVehicleType* vtype, const SUMOReal accel,
46  const SUMOReal decel, const SUMOReal headwayTime)
47  : myType(vtype), myAccel(accel), myDecel(decel), myHeadwayTime(headwayTime) {
48 }
49 
50 
52 
53 
55 MSCFModel::moveHelper(MSVehicle* const veh, SUMOReal vPos) const {
56  const SUMOReal oldV = veh->getSpeed(); // save old v for optional acceleration computation
57  const SUMOReal vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
58  // we need the acceleration for emission computation;
59  // in this case, we neglect dawdling, nonetheless, using
60  // vSafe does not incorporate speed reduction due to interaction
61  // on lane changing
62  veh->setPreDawdleAcceleration(SPEED2ACCEL(vSafe - oldV));
63  const SUMOReal vMin = MAX2((SUMOReal) 0, oldV - ACCEL2SPEED(myDecel));
64  const SUMOReal vMax = MIN3(veh->getLane()->getMaxSpeed(), maxNextSpeed(oldV), vSafe);
65  assert(vMin <= vMax);
66  return veh->getLaneChangeModel().patchSpeed(vMin, vMax, vMax, *this);
67 }
68 
69 
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->getLane()->getMaxSpeed());
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 
99  return MIN2(speed + (SUMOReal) ACCEL2SPEED(getMaxAccel()), myType->getMaxSpeed());
100 }
101 
102 
103 SUMOReal
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 void MSCFModel::saveState(std::ostream& /*os*/) {}
114 
115 
116 /****************************************************************************/