SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSMoveReminder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Something on a lane to be noticed about vehicle movement
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
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 <string>
32 #include "MSLane.h"
33 #include "MSMoveReminder.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 MSMoveReminder::MSMoveReminder(MSLane* const lane, const bool doAdd)
40  : myLane(lane) {
41  if (myLane != 0 && doAdd) {
42  // add reminder to lane
43  myLane->addMoveReminder(this);
44  }
45 }
46 
47 
48 #ifdef HAVE_INTERNAL
49 void
50 MSMoveReminder::updateDetector(SUMOVehicle& veh, SUMOReal entryPos, SUMOReal leavePos,
51  SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime) {
52  // each vehicle is tracked linearly across its segment. For each vehicle,
53  // the time and position of the previous call are maintained and only
54  // the increments are sent to notifyMoveInternal
55  if (entryTime > currentTime) {
56  return; // calibrator may insert vehicles a tiny bit into the future; ignore those
57  }
58  std::map<SUMOVehicle*, std::pair<SUMOTime, SUMOReal> >::iterator j = myLastVehicleUpdateValues.find(&veh);
59  if (j != myLastVehicleUpdateValues.end()) {
60  // the vehicle already has reported its values before; use these
61  // however, if this was called from prepareDetectorForWriting the time
62  // only has a resolution of DELTA_T and might be invalid
63  const SUMOTime previousEntryTime = j->second.first;
64  if (previousEntryTime <= currentTime) {
65  entryTime = previousEntryTime;
66  entryPos = j->second.second;
67  }
68  myLastVehicleUpdateValues.erase(j);
69  }
70  assert(entryTime <= currentTime);
71  if ((entryTime < leaveTime) && (entryPos < leavePos)) {
72  const SUMOReal timeOnLane = STEPS2TIME(currentTime - entryTime);
73  const SUMOReal speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
74  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(currentTime, entryPos + speed * timeOnLane);
75  assert(timeOnLane >= 0);
76  assert(speed >= 0);
77  notifyMoveInternal(veh, timeOnLane, speed);
78  } else {
79  // it would be natrual to
80  // assert(entryTime == leaveTime);
81  // assert(entryPos == leavePos);
82  // However, in the presence of calibrators, vehicles may jump a bit
83  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(leaveTime, leavePos);
84  }
85 
86 }
87 #endif
88 /****************************************************************************/
89