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/MSEdge.h>
00037 #include <microsim/MSPerson.h>
00038 #include <utils/iodevices/OutputDevice.h>
00039 
00040 #ifdef CHECK_MEMORY_LEAKS
00041 #include <foreign/nvwa/debug_new.h>
00042 #endif // CHECK_MEMORY_LEAKS
00043 
00044 
00045 // ===========================================================================
00046 // method definitions
00047 // ===========================================================================
00048 // ---------------------------------------------------------------------------
00049 // static initialisation methods
00050 // ---------------------------------------------------------------------------
00051 MSDevice_Person*
00052 MSDevice_Person::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*> &into) {
00053     MSDevice_Person* device = new MSDevice_Person(v, "person_" + v.getID());
00054     into.push_back(device);
00055     return device;
00056 }
00057 
00058 
00059 // ---------------------------------------------------------------------------
00060 // MSDevice_Person-methods
00061 // ---------------------------------------------------------------------------
00062 MSDevice_Person::MSDevice_Person(SUMOVehicle& holder, const std::string& id)
00063     : MSDevice(holder, id), myPersons(), myStopped(holder.isStopped()) {
00064 }
00065 
00066 
00067 MSDevice_Person::~MSDevice_Person() {
00068 }
00069 
00070 
00071 bool
00072 MSDevice_Person::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal /*newSpeed*/) {
00073     if (myStopped) {
00074         if (!veh.isStopped()) {
00075             for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
00076                 (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
00077             }
00078             myStopped = false;
00079         }
00080     } else {
00081         if (veh.isStopped()) {
00082             for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end();) {
00083                 if (&(*i)->getDestination() == veh.getEdge()) {
00084                     (*i)->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep());
00085                     i = myPersons.erase(i);
00086                 } else {
00087                     ++i;
00088                 }
00089             }
00090             myStopped = true;
00091         }
00092     }
00093     return true;
00094 }
00095 
00096 
00097 bool
00098 MSDevice_Person::notifyEnter(SUMOVehicle& /*veh*/, MSMoveReminder::Notification reason) {
00099     if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) {
00100         for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
00101             (*i)->setDeparted(MSNet::getInstance()->getCurrentTimeStep());
00102         }
00103     }
00104     return true;
00105 }
00106 
00107 
00108 bool
00109 MSDevice_Person::notifyLeave(SUMOVehicle& veh, SUMOReal /*lastPos*/,
00110                              MSMoveReminder::Notification reason) {
00111     if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
00112         for (std::vector<MSPerson*>::iterator i = myPersons.begin(); i != myPersons.end(); ++i) {
00113             if (&(*i)->getDestination() != veh.getEdge()) {
00114                 WRITE_WARNING("Teleporting person '" + (*i)->getID() +
00115                               "' from vehicle destination '" + veh.getEdge()->getID() +
00116                               "' to intended destination '" + (*i)->getDestination().getID() + "'");
00117             }
00118             (*i)->proceed(MSNet::getInstance(), MSNet::getInstance()->getCurrentTimeStep());
00119         }
00120     }
00121     return true;
00122 }
00123 
00124 
00125 void
00126 MSDevice_Person::addPerson(MSPerson* person) {
00127     myPersons.push_back(person);
00128 }
00129 
00130 
00131 /****************************************************************************/
00132 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines