|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A device which is used to keep track of Persons riding with a vehicle 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 // =========================================================================== 00021 // included modules 00022 // =========================================================================== 00023 #ifdef _MSC_VER 00024 #include <windows_config.h> 00025 #else 00026 #include <config.h> 00027 #endif 00028 00029 #include "MSDevice_Person.h" 00030 #include <microsim/MSNet.h> 00031 #include <microsim/MSLane.h> 00032 #include <microsim/MSPerson.h> 00033 #include <utils/iodevices/OutputDevice.h> 00034 00035 #ifdef CHECK_MEMORY_LEAKS 00036 #include <foreign/nvwa/debug_new.h> 00037 #endif // CHECK_MEMORY_LEAKS 00038 00039 00040 // =========================================================================== 00041 // method definitions 00042 // =========================================================================== 00043 // --------------------------------------------------------------------------- 00044 // static initialisation methods 00045 // --------------------------------------------------------------------------- 00046 MSDevice_Person* 00047 MSDevice_Person::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*> &into) throw() { 00048 MSDevice_Person* device = new MSDevice_Person(v, "person_" + v.getID()); 00049 into.push_back(device); 00050 return device; 00051 } 00052 00053 00054 // --------------------------------------------------------------------------- 00055 // MSDevice_Person-methods 00056 // --------------------------------------------------------------------------- 00057 MSDevice_Person::MSDevice_Person(SUMOVehicle& holder, const std::string& id) throw() 00058 : MSDevice(holder, id), myPersons(), myStopped(holder.isStopped()) { 00059 } 00060 00061 00062 MSDevice_Person::~MSDevice_Person() throw() { 00063 } 00064 00065 00066 bool 00067 MSDevice_Person::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) throw() { 00068 if (myStopped) { 00069 if (!veh.isStopped()) { 00070 for (std::vector<MSPerson*>::iterator i=myPersons.begin(); i!=myPersons.end(); ++i) { 00071 (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep()); 00072 } 00073 myStopped = false; 00074 } 00075 } else { 00076 if (veh.isStopped()) { 00077 for (std::vector<MSPerson*>::iterator i=myPersons.begin(); i!=myPersons.end();) { 00078 if (&(*i)->getDestination() == veh.getEdge()) { 00079 (*i)->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep()); 00080 i = myPersons.erase(i); 00081 } else { 00082 ++i; 00083 } 00084 } 00085 myStopped = true; 00086 } 00087 } 00088 return true; 00089 } 00090 00091 00092 bool 00093 MSDevice_Person::notifyEnter(SUMOVehicle& /*veh*/, MSMoveReminder::Notification reason) throw() { 00094 if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) { 00095 for (std::vector<MSPerson*>::iterator i=myPersons.begin(); i!=myPersons.end(); ++i) { 00096 (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep()); 00097 } 00098 } 00099 return true; 00100 } 00101 00102 00103 bool 00104 MSDevice_Person::notifyLeave(SUMOVehicle& veh, SUMOReal /*lastPos*/, 00105 MSMoveReminder::Notification reason) throw() { 00106 if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) { 00107 for (std::vector<MSPerson*>::iterator i=myPersons.begin(); i!=myPersons.end(); ++i) { 00108 if (&(*i)->getDestination() != veh.getEdge()) { 00109 WRITE_WARNING("Teleporting person '" + (*i)->getID() + 00110 "' from vehicle destination '" + veh.getEdge()->getID() + 00111 "' to intended destination '" + (*i)->getDestination().getID() + "'"); 00112 } 00113 (*i)->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep()); 00114 } 00115 } 00116 return true; 00117 } 00118 00119 00120 void 00121 MSDevice_Person::addPerson(MSPerson* person) throw() { 00122 myPersons.push_back(person); 00123 } 00124 00125 00126 /****************************************************************************/ 00127