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