SUMO - Simulation of Urban MObility

MSDevice_Person.cpp

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