|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // The class responsible for building and deletion of vehicles 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef MSVehicleControl_h 00023 #define MSVehicleControl_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <string> 00036 #include <map> 00037 #include <set> 00038 #include "MSGlobals.h" 00039 #include <utils/common/SUMOTime.h> 00040 #include <utils/common/RandomDistributor.h> 00041 #include <utils/common/SUMOVehicleParameter.h> 00042 00043 00044 // =========================================================================== 00045 // class declarations 00046 // =========================================================================== 00047 class SUMOVehicle; 00048 class MSVehicle; 00049 class MSRoute; 00050 class MSVehicleType; 00051 class BinaryInputDevice; 00052 class MSEdge; 00053 00054 00055 // =========================================================================== 00056 // class definitions 00057 // =========================================================================== 00073 class MSVehicleControl { 00074 public: 00076 typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt; 00077 00078 public: 00080 MSVehicleControl() ; 00081 00082 00084 virtual ~MSVehicleControl() ; 00085 00086 00089 00103 virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route, 00104 const MSVehicleType* type) ; 00106 00107 00108 00111 00124 virtual bool addVehicle(const std::string& id, SUMOVehicle* v) ; 00125 00126 00135 SUMOVehicle* getVehicle(const std::string& id) const ; 00136 00137 00143 virtual void deleteVehicle(SUMOVehicle* v) ; 00144 00145 00157 void scheduleVehicleRemoval(SUMOVehicle* veh) ; 00158 00159 00164 constVehIt loadedVehBegin() const ; 00165 00166 00171 constVehIt loadedVehEnd() const ; 00173 00174 00175 00178 00186 void vehicleDeparted(const SUMOVehicle& v) ; 00188 00189 00190 00193 00197 unsigned int getLoadedVehicleNo() const { 00198 return myLoadedVehNo; 00199 } 00200 00201 00205 unsigned int getEndedVehicleNo() const { 00206 return myEndedVehNo; 00207 } 00208 00209 00213 unsigned int getRunningVehicleNo() const { 00214 return myRunningVehNo; 00215 } 00216 00217 00221 unsigned int getDepartedVehicleNo() const { 00222 return myRunningVehNo + myEndedVehNo; 00223 } 00224 00225 00229 bool isInQuota(const SUMOReal frac) const { 00230 if (MSGlobals::gFractions.find(frac) == MSGlobals::gFractions.end()) { 00231 return (myLoadedVehNo - 1) % 1000 < (unsigned int)(frac * 1000.); 00232 } 00233 return (myLoadedVehNo - 1) % MSGlobals::gFractions[frac].second < MSGlobals::gFractions[frac].first; 00234 } 00235 00236 00241 int getActiveVehicleCount() const { 00242 return myLoadedVehNo - (myWaitingForPerson + myEndedVehNo); 00243 } 00245 00246 00249 00254 void printMeanWaitingTime(OutputDevice& od) const ; 00255 00256 00261 void printMeanTravelTime(OutputDevice& od) const ; 00263 00264 00265 00266 00269 00282 bool addVType(MSVehicleType* vehType) ; 00283 00284 00298 bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*> *vehTypeDistribution) ; 00299 00300 00308 bool hasVTypeDistribution(const std::string& id) const ; 00309 00310 00315 MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID) ; 00316 00317 00321 void insertVTypeIDs(std::vector<std::string> &into) const ; 00323 00324 void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle) ; 00325 00326 void removeWaiting(const MSEdge* const edge, SUMOVehicle* vehicle) ; 00327 00328 SUMOVehicle* getWaitingVehicle(const MSEdge* const edge, const std::set<std::string> &lines) ; 00329 00332 void registerOneWaitingForPerson() { 00333 myWaitingForPerson++; 00334 } 00335 00338 void unregisterOneWaitingForPerson() { 00339 myWaitingForPerson--; 00340 } 00341 00344 00348 virtual void saveState(std::ostream& os) ; 00349 00353 virtual void loadState(BinaryInputDevice& bis, const SUMOTime offset) ; 00355 // 00356 00359 void abortWaiting() ; 00360 00361 00362 private: 00369 bool checkVType(const std::string& id) ; 00370 00371 00372 protected: 00375 00377 unsigned int myLoadedVehNo; 00378 00380 unsigned int myRunningVehNo; 00381 00383 unsigned int myEndedVehNo; 00385 00386 00389 00391 SUMOReal myTotalDepartureDelay; 00392 00394 SUMOReal myTotalTravelTime; 00396 00397 00400 00402 typedef std::map< std::string, SUMOVehicle* > VehicleDictType; 00404 VehicleDictType myVehicleDict; 00406 00407 00410 00412 typedef std::map< std::string, MSVehicleType* > VTypeDictType; 00414 VTypeDictType myVTypeDict; 00415 00417 typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType; 00419 VTypeDistDictType myVTypeDistDict; 00420 00422 bool myDefaultVTypeMayBeDeleted; 00423 00425 std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting; 00426 00428 unsigned int myWaitingForPerson; 00429 00430 00431 private: 00433 MSVehicleControl(const MSVehicleControl& s); 00434 00436 MSVehicleControl& operator=(const MSVehicleControl& s); 00437 00438 00439 }; 00440 00441 00442 #endif 00443 00444 /****************************************************************************/ 00445