SUMO - Simulation of Urban MObility

MSVehicleControl.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The class responsible for building and deletion of vehicles
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 #ifndef MSVehicleControl_h
00020 #define MSVehicleControl_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <string>
00033 #include <map>
00034 #include <set>
00035 #include "MSGlobals.h"
00036 #include <utils/common/SUMOTime.h>
00037 #include <utils/common/RandomDistributor.h>
00038 #include <utils/common/SUMOVehicleParameter.h>
00039 
00040 
00041 // ===========================================================================
00042 // class declarations
00043 // ===========================================================================
00044 class SUMOVehicle;
00045 class MSVehicle;
00046 class MSRoute;
00047 class MSVehicleType;
00048 class BinaryInputDevice;
00049 class MSEdge;
00050 
00051 
00052 // ===========================================================================
00053 // class definitions
00054 // ===========================================================================
00070 class MSVehicleControl {
00071 public:
00073     typedef std::map<std::string, SUMOVehicle*>::const_iterator constVehIt;
00074 
00075 public:
00077     MSVehicleControl() throw();
00078 
00079 
00081     virtual ~MSVehicleControl() throw();
00082 
00083 
00086 
00100     virtual SUMOVehicle* buildVehicle(SUMOVehicleParameter* defs, const MSRoute* route,
00101                                       const MSVehicleType* type) throw(ProcessError);
00103 
00104 
00105 
00108 
00121     virtual bool addVehicle(const std::string& id, SUMOVehicle* v) throw();
00122 
00123 
00132     SUMOVehicle* getVehicle(const std::string& id) const throw();
00133 
00134 
00140     virtual void deleteVehicle(SUMOVehicle* v) throw();
00141 
00142 
00154     void scheduleVehicleRemoval(SUMOVehicle* veh) throw();
00155 
00156 
00161     constVehIt loadedVehBegin() const throw();
00162 
00163 
00168     constVehIt loadedVehEnd() const throw();
00170 
00171 
00172 
00175 
00183     void vehicleDeparted(const SUMOVehicle& v) throw();
00185 
00186 
00187 
00190 
00194     unsigned int getLoadedVehicleNo() const throw() {
00195         return myLoadedVehNo;
00196     }
00197 
00198 
00202     unsigned int getEndedVehicleNo() const throw() {
00203         return myEndedVehNo;
00204     }
00205 
00206 
00210     unsigned int getRunningVehicleNo() const throw() {
00211         return myRunningVehNo;
00212     }
00213 
00214 
00218     unsigned int getDepartedVehicleNo() const throw() {
00219         return myRunningVehNo + myEndedVehNo;
00220     }
00221 
00222 
00226     bool isInQuota(const SUMOReal frac) const throw() {
00227         if (MSGlobals::gFractions.find(frac) == MSGlobals::gFractions.end()) {
00228             return (myLoadedVehNo-1) % 1000 < (unsigned int)(frac*1000.);
00229         }
00230         return (myLoadedVehNo-1) % MSGlobals::gFractions[frac].second < MSGlobals::gFractions[frac].first;
00231     }
00232 
00233 
00238     int getActiveVehicleCount() const throw() {
00239         return myLoadedVehNo - (myWaitingForPerson + myEndedVehNo);
00240     }
00242 
00243 
00246 
00251     void printMeanWaitingTime(OutputDevice& od) const throw();
00252 
00253 
00258     void printMeanTravelTime(OutputDevice& od) const throw();
00260 
00261 
00262 
00263 
00266 
00279     bool addVType(MSVehicleType* vehType) throw();
00280 
00281 
00295     bool addVTypeDistribution(const std::string& id, RandomDistributor<MSVehicleType*> *vehTypeDistribution) throw();
00296 
00297 
00305     bool hasVTypeDistribution(const std::string& id) const throw();
00306 
00307 
00312     MSVehicleType* getVType(const std::string& id=DEFAULT_VTYPE_ID) throw();
00313 
00314 
00318     void insertVTypeIDs(std::vector<std::string> &into) const throw();
00320 
00321     void addWaiting(const MSEdge* const edge, SUMOVehicle* vehicle) throw();
00322 
00323     void removeWaiting(const MSEdge* const edge, SUMOVehicle* vehicle) throw();
00324 
00325     SUMOVehicle* getWaitingVehicle(const MSEdge* const edge, const std::set<std::string> &lines) throw();
00326 
00329     void registerOneWaitingForPerson() {
00330         myWaitingForPerson++;
00331     }
00332 
00335     void unregisterOneWaitingForPerson() {
00336         myWaitingForPerson--;
00337     }
00338 
00341 
00345     virtual void saveState(std::ostream& os) throw();
00346 
00350     virtual void loadState(BinaryInputDevice& bis, const SUMOTime offset) throw();
00352     //
00353 
00356     void abortWaiting() throw();
00357 
00358 
00359 private:
00366     bool checkVType(const std::string& id) throw();
00367 
00368 
00369 protected:
00372 
00374     unsigned int myLoadedVehNo;
00375 
00377     unsigned int myRunningVehNo;
00378 
00380     unsigned int myEndedVehNo;
00382 
00383 
00386 
00388     SUMOReal myTotalDepartureDelay;
00389 
00391     SUMOReal myTotalTravelTime;
00393 
00394 
00397 
00399     typedef std::map< std::string, SUMOVehicle* > VehicleDictType;
00401     VehicleDictType myVehicleDict;
00403 
00404 
00407 
00409     typedef std::map< std::string, MSVehicleType* > VTypeDictType;
00411     VTypeDictType myVTypeDict;
00412 
00414     typedef std::map< std::string, RandomDistributor<MSVehicleType*>* > VTypeDistDictType;
00416     VTypeDistDictType myVTypeDistDict;
00417 
00419     bool myDefaultVTypeMayBeDeleted;
00420 
00422     std::map<const MSEdge* const, std::vector<SUMOVehicle*> > myWaiting;
00423 
00425     unsigned int myWaitingForPerson;
00426 
00427 
00428 private:
00430     MSVehicleControl(const MSVehicleControl& s);
00431 
00433     MSVehicleControl& operator=(const MSVehicleControl& s);
00434 
00435 
00436 };
00437 
00438 
00439 #endif
00440 
00441 /****************************************************************************/
00442 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines