MSPersonControl Class Reference

#include <MSPersonControl.h>


Detailed Description

The class is used to handle persons who are not using a transportation system but are walking or waiting. Both is processed by waiting for the arrival time / the time the waiting is over.

Definition at line 51 of file MSPersonControl.h.


Public Types

typedef std::vector< MSPerson * > PersonVector

Public Member Functions

bool add (const std::string &id, MSPerson *person)
 adds a single person, returns false iff an id clash occured
void addWaiting (const MSEdge *edge, MSPerson *person) throw ()
 adds a person to the list of persons waiting for a vehicle on the specified edge
void checkWaiting (const MSEdge *edge, MSVehicle *vehicle) throw ()
 checkls whether a person waits for the specified vehicle and if so removes it from the list
void erase (MSPerson *person)
 removes a single person
bool hasArrivedPersons (SUMOTime time) const
 returns whether any persons waiting or walking time is over
 MSPersonControl ()
 constructor
const PersonVector popArrivedPersons (SUMOTime time)
 returns the list of persons which waiting or walking period is over
void setArrival (SUMOTime time, MSPerson *person)
 sets the arrival time for a waiting or walking person
 ~MSPersonControl ()
 destructor

Private Attributes

std::map< SUMOTime, PersonVectormyArrivals
 the lists of walking / stopping persons
std::map< std::string, MSPerson * > myPersons
 all persons by id
std::map< const MSEdge
*, PersonVector
myWaiting
 the lists of waiting persons

Member Typedef Documentation

typedef std::vector<MSPerson*> MSPersonControl::PersonVector

Definition at line 54 of file MSPersonControl.h.


Constructor & Destructor Documentation

MSPersonControl::MSPersonControl (  ) 

constructor

Definition at line 47 of file MSPersonControl.cpp.

00047 {}

MSPersonControl::~MSPersonControl (  ) 

destructor

Definition at line 50 of file MSPersonControl.cpp.

References myPersons, and myWaiting.

00050                                   {
00051     for (std::map<std::string, MSPerson*>::iterator i=myPersons.begin(); i!=myPersons.end(); ++i) {
00052         delete(*i).second;
00053     }
00054     myPersons.clear();
00055     myWaiting.clear();
00056 }


Member Function Documentation

bool MSPersonControl::add ( const std::string &  id,
MSPerson person 
)

adds a single person, returns false iff an id clash occured

Definition at line 60 of file MSPersonControl.cpp.

References myPersons.

00060                                                           {
00061     if (myPersons.find(id) == myPersons.end()) {
00062         myPersons[id] = person;
00063         return true;
00064     }
00065     return false;
00066 }

void MSPersonControl::addWaiting ( const MSEdge edge,
MSPerson person 
) throw ()

adds a person to the list of persons waiting for a vehicle on the specified edge

Definition at line 119 of file MSPersonControl.cpp.

References myWaiting.

Referenced by MSPerson::MSPersonStage_Driving::proceed().

00119                                                                               {
00120     if (myWaiting.find(edge) == myWaiting.end()) {
00121         myWaiting[edge] = std::vector<MSPerson*>();
00122     }
00123     myWaiting[edge].push_back(person);
00124 }

void MSPersonControl::checkWaiting ( const MSEdge edge,
MSVehicle vehicle 
) throw ()

checkls whether a person waits for the specified vehicle and if so removes it from the list

Definition at line 128 of file MSPersonControl.cpp.

References myWaiting.

Referenced by MSVehicle::processNextStop().

00128                                                                                   {
00129     if (myWaiting.find(edge) != myWaiting.end()) {
00130         PersonVector &waitPersons = myWaiting[edge];
00131         for (PersonVector::iterator i=waitPersons.begin(); i!=waitPersons.end();) {
00132             const std::string &line = vehicle->getParameter().line == "" ? vehicle->getParameter().id : vehicle->getParameter().line;
00133             if ((*i)->isWaitingFor(line)) {
00134                 vehicle->addPerson(*i);
00135                 i = waitPersons.erase(i);
00136             } else {
00137                 ++i;
00138             }
00139         }
00140     }
00141 }

void MSPersonControl::erase ( MSPerson person  ) 

removes a single person

Definition at line 70 of file MSPersonControl.cpp.

References OutputDevice::closeTag(), MSCORN::CORN_OUT_TRIPDURATIONS, MSCORN::CORN_OUT_VEHROUTES, MSNet::getCurrentTimeStep(), MSPerson::getDesiredDepart(), OutputDevice::getDeviceByOption(), MSPerson::getID(), MSNet::getInstance(), myPersons, OutputDevice::openTag(), time2string(), MSPerson::tripInfoOutput(), and MSCORN::wished().

Referenced by MSPerson::proceed().

00070                                        {
00071     const std::string &id = person->getID();
00072     if (MSCORN::wished(MSCORN::CORN_OUT_TRIPDURATIONS)) {
00073         OutputDevice& od = OutputDevice::getDeviceByOption("tripinfo-output");
00074         od.openTag("personinfo") << " id=\"" << id << "\" ";
00075         od << "depart=\"" << time2string(person->getDesiredDepart()) << "\">\n";
00076         person->tripInfoOutput(od);
00077         od.closeTag();
00078     }
00079     if (MSCORN::wished(MSCORN::CORN_OUT_VEHROUTES)) {
00080         OutputDevice& od = OutputDevice::getDeviceByOption("vehroute-output");
00081         od.openTag("person") << " id=\"" << id
00082         << "\" depart=\"" << time2string(person->getDesiredDepart())
00083         << "\" arrival=\"" << time2string(MSNet::getInstance()->getCurrentTimeStep())
00084         << "\">\n";
00085         od.closeTag();
00086         od << "\n";
00087     }
00088     if (myPersons.find(id) != myPersons.end()) {
00089         delete myPersons[id];
00090         myPersons.erase(id);
00091     }
00092 }

bool MSPersonControl::hasArrivedPersons ( SUMOTime  time  )  const

returns whether any persons waiting or walking time is over

Definition at line 105 of file MSPersonControl.cpp.

References myArrivals.

Referenced by MSNet::simulationStep().

00105                                                       {
00106     return myArrivals.find(time)!=myArrivals.end();
00107 }

const MSPersonControl::PersonVector MSPersonControl::popArrivedPersons ( SUMOTime  time  ) 

returns the list of persons which waiting or walking period is over

Definition at line 111 of file MSPersonControl.cpp.

References myArrivals.

Referenced by MSNet::simulationStep().

00111                                                 {
00112     MSPersonControl::PersonVector arrived = myArrivals[time];
00113     myArrivals.erase(time);
00114     return arrived;
00115 }

void MSPersonControl::setArrival ( SUMOTime  time,
MSPerson person 
)

sets the arrival time for a waiting or walking person

Definition at line 95 of file MSPersonControl.cpp.

References DELTA_T, and myArrivals.

Referenced by MSRouteHandler::closePerson(), MSPerson::MSPersonStage_Waiting::proceed(), and MSPerson::MSPersonStage_Walking::proceed().

00095                                                                  {
00096     const SUMOTime step = time % DELTA_T == 0 ? time : (time / DELTA_T + 1) * DELTA_T;
00097     if (myArrivals.find(step)==myArrivals.end()) {
00098         myArrivals[step] = PersonVector();
00099     }
00100     myArrivals[step].push_back(person);
00101 }


Field Documentation

the lists of walking / stopping persons

Definition at line 89 of file MSPersonControl.h.

Referenced by hasArrivedPersons(), popArrivedPersons(), and setArrival().

std::map<std::string, MSPerson*> MSPersonControl::myPersons [private]

all persons by id

Definition at line 86 of file MSPersonControl.h.

Referenced by add(), erase(), and ~MSPersonControl().

std::map<const MSEdge*, PersonVector> MSPersonControl::myWaiting [private]

the lists of waiting persons

Definition at line 92 of file MSPersonControl.h.

Referenced by addWaiting(), checkWaiting(), and ~MSPersonControl().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:49 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6