MSPerson.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The class for modelling person-movements
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include <string>
00031 #include <vector>
00032 #include "MSNet.h"
00033 #include "MSEdge.h"
00034 #include "MSLane.h"
00035 #include "MSPerson.h"
00036 #include "MSPersonControl.h"
00037 #include "MSEmitControl.h"
00038 #include "MSVehicle.h"
00039 #include <utils/iodevices/OutputDevice.h>
00040 
00041 #ifdef CHECK_MEMORY_LEAKS
00042 #include <foreign/nvwa/debug_new.h>
00043 #endif // CHECK_MEMORY_LEAKS
00044 
00045 
00046 // ===========================================================================
00047 // method definitions
00048 // ===========================================================================
00049 /* -------------------------------------------------------------------------
00050  * MSPerson::MSPersonStage - methods
00051  * ----------------------------------------------------------------------- */
00052 MSPerson::MSPersonStage::MSPersonStage(const MSEdge &destination)
00053         : myDestination(destination), myDeparted(-1) {}
00054 
00055 
00056 MSPerson::MSPersonStage::~MSPersonStage() {}
00057 
00058 
00059 const MSEdge &
00060 MSPerson::MSPersonStage::getDestination() const {
00061     return myDestination;
00062 }
00063 
00064 
00065 void
00066 MSPerson::MSPersonStage::setDeparted(SUMOTime now) {
00067     if (myDeparted < 0) {
00068         myDeparted = now;
00069     }
00070 }
00071 
00072 
00073 void
00074 MSPerson::MSPersonStage::setArrived(SUMOTime now) {
00075     myArrived = now;
00076 }
00077 
00078 
00079 bool
00080 MSPerson::MSPersonStage::isWaitingFor(const std::string &line) const {
00081     return false;
00082 }
00083 
00084 /* -------------------------------------------------------------------------
00085  * MSPerson::MSPersonStage_Walking - methods
00086  * ----------------------------------------------------------------------- */
00087 MSPerson::MSPersonStage_Walking::MSPersonStage_Walking(MSEdgeVector route, SUMOTime walkingTime, SUMOReal speed)
00088         : MSPersonStage(*route.back()), myWalkingTime(walkingTime) {
00089     if (speed > 0) {
00090         SUMOReal time = 0;
00091         for (MSEdgeVector::const_iterator it = route.begin(); it != route.end(); ++it) {
00092             time += ((*it)->getLanes())[0]->getLength() * speed;
00093         }
00094         myWalkingTime = MAX2(walkingTime, (SUMOTime)(time * 1000.));
00095     }
00096 }
00097 
00098 
00099 MSPerson::MSPersonStage_Walking::~MSPersonStage_Walking() {}
00100 
00101 
00102 void
00103 MSPerson::MSPersonStage_Walking::proceed(MSNet* net,
00104         MSPerson* person, SUMOTime now,
00105         const MSEdge & /*previousEdge*/) {
00106     net->getPersonControl().setArrival(MAX2(now, now + myWalkingTime), person);
00107 }
00108 
00109 
00110 void
00111 MSPerson::MSPersonStage_Walking::tripInfoOutput(OutputDevice &os) const throw(IOError) {
00112     (os.openTag("walk") <<
00113      " arrival=\"" << time2string(myArrived) <<
00114      "\"").closeTag(true);
00115 }
00116 
00117 
00118 
00119 /* -------------------------------------------------------------------------
00120  * MSPerson::MSPersonStage_Driving - methods
00121  * ----------------------------------------------------------------------- */
00122 MSPerson::MSPersonStage_Driving::MSPersonStage_Driving(const MSEdge &destination,
00123         const std::vector<std::string> &lines)
00124         : MSPersonStage(destination), myLines(lines.begin(), lines.end()) {}
00125 
00126 
00127 MSPerson::MSPersonStage_Driving::~MSPersonStage_Driving() {}
00128 
00129 
00130 void
00131 MSPerson::MSPersonStage_Driving::proceed(MSNet* net,
00132         MSPerson* person, SUMOTime now,
00133         const MSEdge &previousEdge) {
00134     MSVehicle *v = MSNet::getInstance()->getVehicleControl().getWaitingVehicle(&previousEdge, myLines);
00135     if (v != 0) {
00136         v->addPerson(person);
00137         if (v->getDesiredDepart() == -1) {
00138             MSNet::getInstance()->getEmitControl().add(v);
00139             MSNet::getInstance()->getVehicleControl().removeWaiting(&previousEdge, v);
00140         }
00141     } else {
00142         net->getPersonControl().addWaiting(&previousEdge, person);
00143     }
00144 }
00145 
00146 
00147 bool
00148 MSPerson::MSPersonStage_Driving::isWaitingFor(const std::string &line) const {
00149     return myLines.count(line) > 0;
00150 }
00151 
00152 
00153 void
00154 MSPerson::MSPersonStage_Driving::tripInfoOutput(OutputDevice &os) const throw(IOError) {
00155     (os.openTag("ride") <<
00156      " depart=\"" << time2string(myDeparted) <<
00157      "\" arrival=\"" << time2string(myArrived) <<
00158      "\"").closeTag(true);
00159 }
00160 
00161 
00162 /* -------------------------------------------------------------------------
00163  * MSPerson::MSPersonStage_Waiting - methods
00164  * ----------------------------------------------------------------------- */
00165 MSPerson::MSPersonStage_Waiting::MSPersonStage_Waiting(const MSEdge &destination,
00166         SUMOTime duration, SUMOTime until)
00167         : MSPersonStage(destination), myWaitingDuration(duration), myWaitingUntil(until) {}
00168 
00169 
00170 MSPerson::MSPersonStage_Waiting::~MSPersonStage_Waiting() {}
00171 
00172 
00173 void
00174 MSPerson::MSPersonStage_Waiting::proceed(MSNet* net,
00175         MSPerson* person, SUMOTime now,
00176         const MSEdge & /*previousEdge*/) {
00177     const SUMOTime until = MAX3(now, now + myWaitingDuration, myWaitingUntil);
00178     net->getPersonControl().setArrival(until, person);
00179 }
00180 
00181 
00182 void
00183 MSPerson::MSPersonStage_Waiting::tripInfoOutput(OutputDevice &os) const throw(IOError) {
00184     (os.openTag("stop") <<
00185      " arrival=\"" << time2string(myArrived) <<
00186      "\"").closeTag(true);
00187 }
00188 
00189 
00190 /* -------------------------------------------------------------------------
00191  * MSPerson - methods
00192  * ----------------------------------------------------------------------- */
00193 MSPerson::MSPerson(const SUMOVehicleParameter* pars, MSPersonPlan *plan)
00194         : myParameter(pars), myPlan(plan) {
00195     myStep = myPlan->begin();
00196 }
00197 
00198 
00199 MSPerson::~MSPerson() {
00200     delete myPlan;
00201 }
00202 
00203 
00204 const std::string&
00205 MSPerson::getID() const throw() {
00206     return myParameter->id;
00207 }
00208 
00209 
00210 void
00211 MSPerson::proceed(MSNet* net, SUMOTime time) {
00212     const MSEdge &arrivedAt = (*myStep)->getDestination();
00213     (*myStep)->setArrived(time);
00214     myStep++;
00215     if (myStep != myPlan->end()) {
00216         (*myStep)->proceed(net, this, time, arrivedAt);
00217     } else {
00218         net->getPersonControl().erase(this);
00219     }
00220 }
00221 
00222 
00223 SUMOTime
00224 MSPerson::getDesiredDepart() const throw() {
00225     return myParameter->depart;
00226 }
00227 
00228 
00229 void
00230 MSPerson::setDeparted(SUMOTime now) {
00231     (*myStep)->setDeparted(now);
00232 }
00233 
00234 
00235 const MSEdge &
00236 MSPerson::getDestination() const {
00237     return (*myStep)->getDestination();
00238 }
00239 
00240 
00241 void
00242 MSPerson::tripInfoOutput(OutputDevice &os) const throw(IOError) {
00243     for (MSPersonPlan::const_iterator i=myPlan->begin(); i!=myPlan->end(); ++i) {
00244         (*i)->tripInfoOutput(os);
00245     }
00246 }
00247 
00248 
00249 bool
00250 MSPerson::isWaitingFor(const std::string &line) const {
00251     return (*myStep)->isWaitingFor(line);
00252 }
00253 
00254 
00255 /****************************************************************************/
00256 

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