MSEmitter.h
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MSEmitter_h
00020 #define MSEmitter_h
00021
00022
00023
00024
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
00040
00041
00042
00043 class MSNet;
00044 class MSLane;
00045
00046
00047
00048
00049
00059 class MSEmitter : public MSTrigger {
00060 public:
00069 MSEmitter(const std::string &id, MSNet &net, MSLane* destLane,
00070 SUMOReal pos, const std::string &file) throw();
00071
00073 virtual ~MSEmitter() throw();
00074
00075
00076 public:
00084 class MSEmitterChild {
00085 public:
00087 MSEmitterChild(MSEmitter &parent, MSVehicleControl &vc)
00088 : myParent(parent), myVehicleControl(vc), myTimeOffset(0) { }
00089
00091 virtual ~MSEmitterChild() { }
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) {
00128 ret = 1;
00129 }
00130 return ret;
00131 }
00132
00134 RandomDistributor<const MSRoute*> &getRouteDist() {
00135 return myRouteDist;
00136 }
00137
00138 protected:
00140 MSEmitter &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 MSEmitterChild(const MSEmitterChild&);
00157
00159 MSEmitterChild& operator=(const MSEmitterChild&);
00160
00161 };
00162
00163
00164 public:
00169 bool childCheckEmit(MSEmitterChild *child);
00170
00172 size_t getActiveChildIndex() const;
00173
00175 void setActiveChild(MSEmitterChild *child);
00176
00177
00178 protected:
00183 class MSEmitter_FileTriggeredChild
00184 : public MSTriggeredXMLReader, public MSEmitterChild, public Command {
00185 public:
00187 MSEmitter_FileTriggeredChild(MSNet &net,
00188 const std::string &aXMLFilename, MSEmitter &parent, MSVehicleControl &vc) throw();
00189
00191 ~MSEmitter_FileTriggeredChild() throw();
00192
00194 bool processNextEntryReaderTriggered();
00195
00196
00199
00207 SUMOTime execute(SUMOTime currentTime) throw(ProcessError);
00209
00210
00212 SUMOReal getLoadedFlow() const;
00213
00214
00215 protected:
00217
00218
00226 virtual void myStartElement(SumoXMLTag element,
00227 const SUMOSAXAttributes &attrs) throw(ProcessError);
00229
00231 void inputEndReached();
00232
00234
00235 bool nextRead();
00236
00238 void buildAndScheduleFlowVehicle();
00239
00240 protected:
00242 bool myHaveNext;
00243
00245 SUMOReal myFlow;
00246
00248 bool myHaveInitialisedFlow;
00249
00251 int myRunningID;
00252
00254 SUMOTime myBeginTime;
00255
00256 private:
00258 MSEmitter_FileTriggeredChild(const MSEmitter_FileTriggeredChild&);
00259
00261 MSEmitter_FileTriggeredChild& operator=(const MSEmitter_FileTriggeredChild&);
00262
00263
00264 };
00265
00266 public:
00268 void schedule(MSEmitterChild *child, MSVehicle *v, SUMOReal speed);
00269
00270 protected:
00272 MSNet &myNet;
00273
00275 MSLane *myDestLane;
00276
00278 SUMOReal myPos;
00279
00281 MSEmitterChild *myFileBasedEmitter;
00282
00284 std::map<MSEmitterChild*, std::pair<MSVehicle*, SUMOReal> > myToEmit;
00285
00287 MSEmitterChild *myActiveChild;
00288
00289 private:
00291 MSEmitter(const MSEmitter&);
00292
00294 MSEmitter& operator=(const MSEmitter&);
00295
00296
00297 };
00298
00299
00300 #endif
00301
00302
00303