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-sim.org/
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(const std::string& description, MSLane* const lane, const bool doAdd) :
40  myLane(lane),
41  myDescription(description) {
42  if (myLane != 0 && doAdd) {
43  // add reminder to lane
44  myLane->addMoveReminder(this);
45  }
46 }
47 
48 
49 #ifdef HAVE_INTERNAL
50 void
51 MSMoveReminder::updateDetector(SUMOVehicle& veh, SUMOReal entryPos, SUMOReal leavePos,
52  SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime) {
53  // each vehicle is tracked linearly across its segment. For each vehicle,
54  // the time and position of the previous call are maintained and only
55  // the increments are sent to notifyMoveInternal
56  if (entryTime > currentTime) {
57  return; // calibrator may insert vehicles a tiny bit into the future; ignore those
58  }
59  std::map<SUMOVehicle*, std::pair<SUMOTime, SUMOReal> >::iterator j = myLastVehicleUpdateValues.find(&veh);
60  if (j != myLastVehicleUpdateValues.end()) {
61  // the vehicle already has reported its values before; use these
62  // however, if this was called from prepareDetectorForWriting the time
63  // only has a resolution of DELTA_T and might be invalid
64  const SUMOTime previousEntryTime = j->second.first;
65  if (previousEntryTime <= currentTime) {
66  entryTime = previousEntryTime;
67  entryPos = j->second.second;
68  }
69  myLastVehicleUpdateValues.erase(j);
70  }
71  assert(entryTime <= currentTime);
72  if ((entryTime < leaveTime) && (entryPos < leavePos)) {
73  const SUMOReal timeOnLane = STEPS2TIME(currentTime - entryTime);
74  const SUMOReal speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
75  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(currentTime, entryPos + speed * timeOnLane);
76  assert(timeOnLane >= 0);
77  assert(speed >= 0);
78  notifyMoveInternal(veh, timeOnLane, speed);
79  } else {
80  // it would be natrual to
81  // assert(entryTime == leaveTime);
82  // assert(entryPos == leavePos);
83  // However, in the presence of calibrators, vehicles may jump a bit
84  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(leaveTime, leavePos);
85  }
86 
87 }
88 #endif
89 /****************************************************************************/
90 
MSLane *const myLane
Lane on which the reminder works.
virtual void addMoveReminder(MSMoveReminder *rem)
Add a move-reminder to move-reminder container.
Definition: MSLane.cpp:112
MSMoveReminder(const std::string &description, MSLane *const lane=0, const bool doAdd=true)
Constructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:63
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
virtual void notifyMoveInternal(SUMOVehicle &veh, SUMOReal timeOnLane, SUMOReal speed)
Internal notification about the vehicle moves.
int SUMOTime
Definition: SUMOTime.h:43
#define SUMOReal
Definition: config.h:215
Representation of a lane in the micro simulation.
Definition: MSLane.h:77