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-2012 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 <cassert>
33 #include "MSLane.h"
34 #include "MSMoveReminder.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 MSMoveReminder::MSMoveReminder(MSLane* const lane, const bool doAdd)
41  : myLane(lane) {
42  if (myLane != 0 && doAdd) {
43  // add reminder to lane
44  myLane->addMoveReminder(this);
45  }
46 }
47 
48 
49 #ifdef HAVE_MESOSIM
50 void
51 MSMoveReminder::updateDetector(SUMOVehicle& veh, SUMOReal entryPos, SUMOReal leavePos,
52  SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime) {
53  std::map<SUMOVehicle*, std::pair<SUMOTime, SUMOReal> >::iterator j = myLastVehicleUpdateValues.find(&veh);
54  if (j != myLastVehicleUpdateValues.end()) {
55  // the vehicle already has reported its values before; use these
56  entryTime = (*j).second.first;
57  entryPos = (*j).second.second;
58  myLastVehicleUpdateValues.erase(j);
59  }
60  const SUMOReal timeOnLane = STEPS2TIME(currentTime - entryTime);
61  const SUMOReal speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
62  myLastVehicleUpdateValues[&veh] = std::pair<SUMOTime, SUMOReal>(currentTime, entryPos + speed * timeOnLane);
63  notifyMoveInternal(veh, timeOnLane, speed);
64 }
65 #endif
66 /****************************************************************************/
67