SUMO - Simulation of Urban MObility
MSVehicleControl.h
Go to the documentation of this file.
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 <math.h>
00036 #include <string>
00037 #include <map>
00038 #include <set>
00039 #include "MSGlobals.h"
00040 #include <utils/common/SUMOTime.h>
00041 #include <utils/common/RandomDistributor.h>
00042 #include <utils/common/SUMOVehicleParameter.h>
00043 
00044 
00045 // ===========================================================================
00046 // class declarations
00047 // ===========================================================================
00048 class SUMOVehicle;
00049 class MSVehicle;
00050 class MSRoute;
00051 class MSVehicleType;
00052 class BinaryInputDevice;
00053 class MSEdge;
00054 
00055 
00056 // ===========================================================================
00057 // class definitions
00058 // ===========================================================================
00074 class MSVehicleControl {
00075 public:
00077     typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
00078 
00079 public:
00081     MSVehicleControl() ;
00082 
00083 
00085     virtual ~MSVehicleControl() ;
00086 
00087 
00090 
00104     virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route,
00105                                       const MSVehicleType* type) ;
00107 
00108 
00109 
00112 
00125     virtual bool addVehicle(const std::string& id, SUMOVehicle* v) ;
00126 
00127 
00136     SUMOVehicle* getVehicle(const std::string& id) const ;
00137 
00138 
00145     virtual void deleteVehicle(SUMOVehicle* v, bool discard=false) ;
00146 
00147 
00159     void scheduleVehicleRemoval(SUMOVehicle* veh) ;
00160 
00161 
00166     constVehIt loadedVehBegin() const ;
00167 
00168 
00173     constVehIt loadedVehEnd() const ;
00175 
00176 
00177 
00180 
00188     void vehicleDeparted(const SUMOVehicle& v) ;
00190 
00191 
00192 
00195 
00199     unsigned int getLoadedVehicleNo() const {
00200         return myLoadedVehNo;
00201     }
00202 
00203 
00207     unsigned int getEndedVehicleNo() const {
00208         return myEndedVehNo;
00209     }
00210 
00211 
00215     unsigned int getRunningVehicleNo() const {
00216         return myRunningVehNo;
00217     }
00218 
00219 
00223     unsigned int getDepartedVehicleNo() const {
00224         return myRunningVehNo + myEndedVehNo - myDiscarded;
00225     }
00226 
00227 
00232     bool isInQuota(const SUMOReal frac) const;
00233 
00234 
00239     int getActiveVehicleCount() const {
00240         return myLoadedVehNo - (myWaitingForPerson + myEndedVehNo);
00241     }
00243 
00244 
00247 
00252     void printMeanWaitingTime(OutputDevice& od) const ;
00253 
00254 
00259     void printMeanTravelTime(OutputDevice& od) const ;
00261 
00262 
00263 
00264 
00267 
00280     bool addVType(MSVehicleType* vehType) ;
00281 
00282 
00296     bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*> *vehTypeDistribution) ;
00297 
00298 
00306     bool hasVTypeDistribution(const std::string& id) const ;
00307 
00308 
00313     MSVehicleType* getVType(const std::string& id = DEFAULT_VTYPE_ID) ;
00314 
00315 
00319     void insertVTypeIDs(std::vector<std::string> &into) const ;
00321 
00322     void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle) ;
00323 
00324     void removeWaiting(const MSEdge* const edge, SUMOVehicle* vehicle) ;
00325 
00326     SUMOVehicle* getWaitingVehicle(const MSEdge* const edge, const std::set<std::string> &lines) ;
00327 
00330     void registerOneWaitingForPerson() {
00331         myWaitingForPerson++;
00332     }
00333 
00336     void unregisterOneWaitingForPerson() {
00337         myWaitingForPerson--;
00338     }
00339 
00342 
00346     virtual void saveState(std::ostream& os) ;
00347 
00351     virtual void loadState(BinaryInputDevice& bis, const SUMOTime offset) ;
00353     //
00354 
00357     void abortWaiting() ;
00358 
00359 
00360 private:
00367     bool checkVType(const std::string& id) ;
00368 
00369 
00370 protected:
00373 
00375     unsigned int myLoadedVehNo;
00376 
00378     unsigned int myRunningVehNo;
00379 
00381     unsigned int myEndedVehNo;
00382 
00384     unsigned int myDiscarded;
00386 
00387 
00390 
00392     SUMOReal myTotalDepartureDelay;
00393 
00395     SUMOReal myTotalTravelTime;
00397 
00398 
00401 
00403     typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
00405     VehicleDictType myVehicleDict;
00407 
00408 
00411 
00413     typedef std::map< std::string, MSVehicleType* > VTypeDictType;
00415     VTypeDictType myVTypeDict;
00416 
00418     typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
00420     VTypeDistDictType myVTypeDistDict;
00421 
00423     bool myDefaultVTypeMayBeDeleted;
00424 
00426     std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting;
00427 
00429     unsigned int myWaitingForPerson;
00430 
00431 
00432 private:
00434     MSVehicleControl(const MSVehicleControl& s);
00435 
00437     MSVehicleControl& operator=(const MSVehicleControl& s);
00438 
00439 
00440 };
00441 
00442 
00443 #endif
00444 
00445 /****************************************************************************/
00446 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines