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  const SUMOReal vMin = getSpeedAfterMaxDecel(oldV);
63  const SUMOReal vMax = MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV), vSafe);
64  assert(vMin <= vMax);
65  return veh->getLaneChangeModel().patchSpeed(vMin, vMax, vMax, *this);
66 }
67 
68 
70 MSCFModel::interactionGap(const MSVehicle* const veh, SUMOReal vL) const {
71  // Resolve the vsafe equation to gap. Assume predecessor has
72  // speed != 0 and that vsafe will be the current speed plus acceleration,
73  // i.e that with this gap there will be no interaction.
74  const SUMOReal vNext = MIN2(maxNextSpeed(veh->getSpeed()), veh->getLane()->getVehicleMaxSpeed(veh));
75  const SUMOReal gap = (vNext - vL) *
76  ((veh->getSpeed() + vL) / (2.*myDecel) + myHeadwayTime) +
77  vL * myHeadwayTime;
78 
79  // Don't allow timeHeadWay < deltaT situations.
80  return MAX2(gap, SPEED2DIST(vNext));
81 }
82 
83 
84 void
85 MSCFModel::leftVehicleVsafe(const MSVehicle* const ego, const MSVehicle* const neigh, SUMOReal& vSafe) const {
86  if (neigh != 0 && neigh->getSpeed() > 60. / 3.6) {
87  SUMOReal mgap = MAX2((SUMOReal) 0, neigh->getPositionOnLane() - neigh->getVehicleType().getLength() - ego->getPositionOnLane() - ego->getVehicleType().getMinGap());
88  SUMOReal nVSafe = followSpeed(ego, ego->getSpeed(), mgap, neigh->getSpeed(), neigh->getCarFollowModel().getMaxDecel());
89  if (mgap - neigh->getSpeed() >= 0) {
90  vSafe = MIN2(vSafe, nVSafe);
91  }
92  }
93 }
94 
95 
98  return MIN2(speed + (SUMOReal) ACCEL2SPEED(getMaxAccel()), myType->getMaxSpeed());
99 }
100 
101 
102 SUMOReal
104  /* one possiblity to speed this up is to precalculate speedReduction * steps * (steps+1) / 2
105  for small values of steps (up to 10 maybe) and store them in an array */
106  const SUMOReal speedReduction = ACCEL2SPEED(getMaxDecel());
107  const int steps = int(speed / speedReduction);
108  return SPEED2DIST(steps * speed - speedReduction * steps * (steps + 1) / 2) + speed * myHeadwayTime;
109 }
110 
111 
112 void MSCFModel::saveState(std::ostream& /*os*/) {}
113 
114 
115 /****************************************************************************/