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