|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // The class for modelling person-movements 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 // =========================================================================== 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 "MSInsertionControl.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), myArrived(-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, TIME2STEPS(time)); 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 SUMOVehicle* v = net->getVehicleControl().getWaitingVehicle(&previousEdge, myLines); 00135 if (v != 0 && v->getParameter().departProcedure == DEPART_TRIGGERED) { 00136 v->addPerson(person); 00137 net->getInsertionControl().add(v); 00138 net->getVehicleControl().removeWaiting(&previousEdge, v); 00139 net->getVehicleControl().unregisterOneWaitingForPerson(); 00140 } else { 00141 net->getPersonControl().addWaiting(&previousEdge, person); 00142 } 00143 } 00144 00145 00146 bool 00147 MSPerson::MSPersonStage_Driving::isWaitingFor(const std::string& line) const { 00148 return myLines.count(line) > 0; 00149 } 00150 00151 00152 void 00153 MSPerson::MSPersonStage_Driving::tripInfoOutput(OutputDevice& os) const throw(IOError) { 00154 (os.openTag("ride") << 00155 " depart=\"" << time2string(myDeparted) << 00156 "\" arrival=\"" << time2string(myArrived) << 00157 "\"").closeTag(true); 00158 } 00159 00160 00161 /* ------------------------------------------------------------------------- 00162 * MSPerson::MSPersonStage_Waiting - methods 00163 * ----------------------------------------------------------------------- */ 00164 MSPerson::MSPersonStage_Waiting::MSPersonStage_Waiting(const MSEdge& destination, 00165 SUMOTime duration, SUMOTime until) 00166 : MSPersonStage(destination), myWaitingDuration(duration), myWaitingUntil(until) {} 00167 00168 00169 MSPerson::MSPersonStage_Waiting::~MSPersonStage_Waiting() {} 00170 00171 00172 void 00173 MSPerson::MSPersonStage_Waiting::proceed(MSNet* net, 00174 MSPerson* person, SUMOTime now, 00175 const MSEdge& /*previousEdge*/) { 00176 const SUMOTime until = MAX3(now, now + myWaitingDuration, myWaitingUntil); 00177 net->getPersonControl().setArrival(until, person); 00178 } 00179 00180 00181 void 00182 MSPerson::MSPersonStage_Waiting::tripInfoOutput(OutputDevice& os) const throw(IOError) { 00183 (os.openTag("stop") << 00184 " arrival=\"" << time2string(myArrived) << 00185 "\"").closeTag(true); 00186 } 00187 00188 00189 /* ------------------------------------------------------------------------- 00190 * MSPerson - methods 00191 * ----------------------------------------------------------------------- */ 00192 MSPerson::MSPerson(const SUMOVehicleParameter* pars, MSPersonPlan* plan) 00193 : myParameter(pars), myPlan(plan) { 00194 myStep = myPlan->begin(); 00195 } 00196 00197 00198 MSPerson::~MSPerson() { 00199 for (MSPersonPlan::const_iterator i=myPlan->begin(); i!=myPlan->end(); ++i) { 00200 delete *i; 00201 } 00202 delete myPlan; 00203 delete myParameter; 00204 } 00205 00206 00207 const std::string& 00208 MSPerson::getID() const throw() { 00209 return myParameter->id; 00210 } 00211 00212 00213 void 00214 MSPerson::proceed(MSNet* net, SUMOTime time) { 00215 const MSEdge& arrivedAt = (*myStep)->getDestination(); 00216 (*myStep)->setArrived(time); 00217 myStep++; 00218 if (myStep != myPlan->end()) { 00219 (*myStep)->proceed(net, this, time, arrivedAt); 00220 } else { 00221 net->getPersonControl().erase(this); 00222 } 00223 } 00224 00225 00226 SUMOTime 00227 MSPerson::getDesiredDepart() const throw() { 00228 return myParameter->depart; 00229 } 00230 00231 00232 void 00233 MSPerson::setDeparted(SUMOTime now) { 00234 (*myStep)->setDeparted(now); 00235 } 00236 00237 00238 const MSEdge& 00239 MSPerson::getDestination() const { 00240 return (*myStep)->getDestination(); 00241 } 00242 00243 00244 void 00245 MSPerson::tripInfoOutput(OutputDevice& os) const throw(IOError) { 00246 for (MSPersonPlan::const_iterator i=myPlan->begin(); i!=myPlan->end(); ++i) { 00247 (*i)->tripInfoOutput(os); 00248 } 00249 } 00250 00251 00252 bool 00253 MSPerson::isWaitingFor(const std::string& line) const { 00254 return (*myStep)->isWaitingFor(line); 00255 } 00256 00257 00258 /****************************************************************************/ 00259