MSCalibrator.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Calibrates the number of vehicles on a lane
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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 MSCalibrator_h
00020 #define MSCalibrator_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 <vector>
00034 #include <utils/common/Command.h>
00035 #include "MSTriggeredXMLReader.h"
00036 #include "MSTrigger.h"
00037 #include <utils/common/RandomDistributor.h>
00038 
00039 #include <netload/NLDetectorBuilder.h>
00040 
00041 
00042 // ===========================================================================
00043 // class declarations
00044 // ===========================================================================
00045 class MSNet;
00046 class MSLane;
00047 class NLDetectorBuilder;
00048 class MSInductLoop;
00049 
00050 
00051 // ===========================================================================
00052 // class definitions
00053 // ===========================================================================
00059 class MSCalibrator : public MSTrigger {
00060 public:
00070     MSCalibrator(const std::string &id, MSNet &net, MSLane* destLane,
00071                  SUMOReal pos, const std::string &file) throw();
00072 
00073     virtual ~MSCalibrator() throw();
00074 
00075 
00076 public:
00084     class MSCalibratorChild {
00085     public:
00087         MSCalibratorChild(MSCalibrator &parent, MSVehicleControl &vc)
00088                 : myParent(parent), myVehicleControl(vc), myTimeOffset(0) { }
00089 
00091         virtual ~MSCalibratorChild() { }
00092 
00094         const MSRoute *getRndRoute() const {
00095             return myRouteDist.get();
00096         }
00097 
00099         const std::vector<const MSRoute*> &getAllRoutes() const {
00100             return myRouteDist.getVals();
00101         }
00102 
00104         MSVehicleType *getRndVType() const {
00105             return myVTypeDist.get();
00106         }
00107 
00109         bool hasRoutes() const {
00110             return myRouteDist.getOverallProb()!=0;
00111         }
00112 
00114         bool hasVTypes() const {
00115             return myVTypeDist.getOverallProb()!=0;
00116         }
00117 
00119         SUMOReal computeOffset(SUMOReal flow) const {
00120             SUMOReal freq = (SUMOReal)(1. / (flow / 3600.));
00121             SUMOReal ret = freq;
00122             myTimeOffset += (freq - (SUMOTime) ret);
00123             if (myTimeOffset>1) {
00124                 myTimeOffset -= 1;
00125                 ret += 1;
00126             }
00127             if (ret==0) { // !!! check what to do in this case (more than one vehicle/s)
00128                 ret = 1;
00129             }
00130             return ret;
00131         }
00132 
00134         RandomDistributor<const MSRoute*> &getRouteDist() {
00135             return myRouteDist;
00136         }
00137 
00138     protected:
00140         MSCalibrator &myParent;
00141 
00143         MSVehicleControl &myVehicleControl;
00144 
00146         RandomDistributor<const MSRoute*> myRouteDist;
00147 
00149         RandomDistributor<MSVehicleType*> myVTypeDist;
00150 
00152         mutable SUMOReal myTimeOffset;
00153 
00154     private:
00156         MSCalibratorChild(const MSCalibratorChild&);
00157 
00159         MSCalibratorChild& operator=(const MSCalibratorChild&);
00160 
00161 
00162     };
00163 
00164 public:
00169     bool childCheckEmit(MSCalibratorChild *child);
00170 
00172     size_t getActiveChildIndex() const;
00173 
00175     void setActiveChild(MSCalibratorChild *child);
00176 
00177 
00178 protected:
00183     class MSCalibrator_FileTriggeredChild
00184                 : public MSTriggeredXMLReader, public MSCalibratorChild, public Command {
00185     public:
00187         MSCalibrator_FileTriggeredChild(MSNet &net,
00188                                         const std::string &aXMLFilename, MSCalibrator &parent, MSVehicleControl &vc) throw();
00189 
00191         ~MSCalibrator_FileTriggeredChild() throw();
00192 
00194         bool processNextEntryReaderTriggered();
00195 
00196 
00199 
00207         SUMOTime execute(SUMOTime currentTime) throw(ProcessError);
00209 
00210 
00212         SUMOReal getLoadedFlow() const;
00213 
00214     protected:
00216 
00217 
00225         virtual void myStartElement(SumoXMLTag element,
00226                                     const SUMOSAXAttributes &attrs) throw(ProcessError);
00228 
00230         void inputEndReached();
00231 
00233         // !!! seee
00234         bool nextRead();
00235         //TM
00236     public:
00238         void buildAndScheduleFlowVehicle() {
00239             buildAndScheduleFlowVehicle(-1);
00240         }
00241         void buildAndScheduleFlowVehicle(SUMOReal speed);
00242 
00243     protected:
00245         bool myHaveNext;
00246 
00248         SUMOReal myFlow;
00249 
00251         bool myHaveInitialisedFlow;
00252 
00254         int myRunningID;
00255 
00257         SUMOTime myBeginTime;
00258 
00259 
00260     private:
00262         MSCalibrator_FileTriggeredChild(const MSCalibrator_FileTriggeredChild&);
00263 
00265         MSCalibrator_FileTriggeredChild& operator=(const MSCalibrator_FileTriggeredChild&);
00266 
00267     };
00268 
00269 public:
00271     void schedule(MSCalibratorChild *child, MSVehicle *v, SUMOReal speed);
00272 
00273     //TM
00274     NLDetectorBuilder myDb;
00275     MSInductLoop * myIL;
00276     SUMOReal myToCalibrate;
00277     SUMOTime myInterval;
00278     SUMOReal myNumVehicles;
00279     int myDebugLevel;
00280     std::string myDebugFilesBaseName;
00281 
00282     static void updateCalibrator(std::string name, int time, SUMOReal count);
00283 
00284 protected:
00286     MSNet &myNet;
00287 
00289     MSLane *myDestLane;
00290 
00292     SUMOReal myPos;
00293 
00294 
00296     MSCalibratorChild *myFileBasedCalibrator;
00297 
00299     std::map<MSCalibratorChild*, std::pair<MSVehicle*, SUMOReal> > myToEmit;
00300 
00302     MSCalibratorChild *myActiveChild;
00303 
00304 
00306     SUMOTime execute(SUMOTime currentTime) throw(ProcessError);
00307     static std::map<std::string, MSCalibrator*> calibratorMap;
00308 
00309 
00310 private:
00312     MSCalibrator(const MSCalibrator&);
00313 
00315     MSCalibrator& operator=(const MSCalibrator&);
00316 
00317 
00318 };
00319 
00320 
00321 #endif
00322 
00323 /****************************************************************************/
00324 

Generated on Wed May 5 00:06:31 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6