SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00013 // The simulated network and simulation perfomer 00014 /****************************************************************************/ 00015 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00016 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00017 /****************************************************************************/ 00018 // 00019 // This file is part of SUMO. 00020 // SUMO is free software: you can redistribute it and/or modify 00021 // it under the terms of the GNU General Public License as published by 00022 // the Free Software Foundation, either version 3 of the License, or 00023 // (at your option) any later version. 00024 // 00025 /****************************************************************************/ 00026 #ifndef MSNet_h 00027 #define MSNet_h 00028 00029 00030 // =========================================================================== 00031 // included modules 00032 // =========================================================================== 00033 #ifdef _MSC_VER 00034 #include <windows_config.h> 00035 #else 00036 #include <config.h> 00037 #endif 00038 00039 #include <typeinfo> 00040 #include <vector> 00041 #include <map> 00042 #include <string> 00043 #include <fstream> 00044 #include <iostream> 00045 #include <cmath> 00046 #include <iomanip> 00047 #include "MSVehicleControl.h" 00048 #include "MSEventControl.h" 00049 #include <utils/geom/Boundary.h> 00050 #include <utils/geom/Position.h> 00051 #include <utils/common/SUMOTime.h> 00052 #include <microsim/trigger/MSBusStop.h> 00053 #include <utils/common/UtilExceptions.h> 00054 #include <utils/common/NamedObjectCont.h> 00055 00056 // =========================================================================== 00057 // class declarations 00058 // =========================================================================== 00059 class MSEdge; 00060 class MSEdgeControl; 00061 class MSJunctionControl; 00062 class MSInsertionControl; 00063 class MSRouteLoaderControl; 00064 class MSPersonControl; 00065 class MSVehicle; 00066 class MSRoute; 00067 class MSLane; 00068 class MSTLLogicControl; 00069 class MSDetectorControl; 00070 class ShapeContainer; 00071 class BinaryInputDevice; 00072 class MSRouteLoader; 00073 class MSEdgeWeightsStorage; 00074 class SUMOVehicle; 00075 #ifdef _MESSAGES 00076 class MSMessageEmitter; 00077 #endif 00078 00079 00080 // =========================================================================== 00081 // class definitions 00082 // =========================================================================== 00087 class MSNet { 00088 public: 00092 enum SimulationState { 00094 SIMSTATE_RUNNING, 00096 SIMSTATE_END_STEP_REACHED, 00098 SIMSTATE_NO_FURTHER_VEHICLES, 00100 SIMSTATE_CONNECTION_CLOSED, 00102 SIMSTATE_ERROR_IN_SIM, 00104 SIMSTATE_TOO_MANY_VEHICLES 00105 }; 00106 00107 00108 public: 00113 static MSNet* getInstance() ; 00114 00115 00130 MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents, 00131 MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents, 00132 ShapeContainer* shapeCont = 0) ; 00133 00134 00136 virtual ~MSNet() ; 00137 00138 00150 void closeBuilding(MSEdgeControl* edges, MSJunctionControl* junctions, 00151 MSRouteLoaderControl* routeLoaders, MSTLLogicControl* tlc, 00152 std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles) ; 00153 00154 00158 static void clearAll(); 00159 00160 00168 int simulate(SUMOTime start, SUMOTime stop); 00169 00170 00174 void simulationStep(); 00175 00176 00184 void closeSimulation(SUMOTime start); 00185 00186 00192 SimulationState simulationState(SUMOTime stopTime) const ; 00193 00194 00198 static std::string getStateMessage(SimulationState state) ; 00199 00200 00204 SUMOTime getCurrentTimeStep() const; 00205 00206 00210 void writeOutput(); 00211 00212 00216 bool logSimulationDuration() const ; 00217 00218 00220 00221 00226 void preSimStepOutput() const ; 00227 00228 00233 void postSimStepOutput() const ; 00234 //} 00235 00236 00237 00238 #ifdef HAVE_MESOSIM 00239 00240 00241 00246 void saveState(std::ostream& os) ; 00247 00248 00253 unsigned int loadState(BinaryInputDevice& bis) ; 00255 #endif 00256 00259 00265 MSVehicleControl& getVehicleControl() { 00266 return *myVehicleControl; 00267 } 00268 00269 00278 MSPersonControl& getPersonControl() ; 00279 00280 00286 MSEdgeControl& getEdgeControl() { 00287 return *myEdges; 00288 } 00289 00290 00296 MSInsertionControl& getInsertionControl() { 00297 return *myInserter; 00298 } 00299 00300 00306 MSDetectorControl& getDetectorControl() { 00307 return *myDetectorControl; 00308 } 00309 00310 00316 MSTLLogicControl& getTLSControl() { 00317 return *myLogics; 00318 } 00319 00320 00326 MSJunctionControl& getJunctionControl() { 00327 return *myJunctions; 00328 } 00329 00330 00336 MSEventControl& getBeginOfTimestepEvents() { 00337 return *myBeginOfTimestepEvents; 00338 } 00339 00340 00346 MSEventControl& getEndOfTimestepEvents() { 00347 return *myEndOfTimestepEvents; 00348 } 00349 00350 00356 MSEventControl& getInsertionEvents() { 00357 return *myInsertionEvents; 00358 } 00359 00360 00366 ShapeContainer& getShapeContainer() { 00367 return *myShapeContainer; 00368 } 00369 00370 00376 MSEdgeWeightsStorage& getWeightsStorage() ; 00378 00379 00380 00383 00395 bool addBusStop(MSBusStop* busStop); 00396 00397 00402 MSBusStop* getBusStop(const std::string& id) const; 00403 00404 00410 std::string getBusStopID(const MSLane* lane, const SUMOReal pos) const; 00412 00413 00414 00415 00416 00417 00420 00422 enum VehicleState { 00424 VEHICLE_STATE_BUILT, 00426 VEHICLE_STATE_DEPARTED, 00428 VEHICLE_STATE_STARTING_TELEPORT, 00430 VEHICLE_STATE_ENDING_TELEPORT, 00432 VEHICLE_STATE_ARRIVED, 00434 VEHICLE_STATE_NEWROUTE 00435 }; 00436 00437 00441 class VehicleStateListener { 00442 public: 00444 VehicleStateListener() { } 00445 00447 virtual ~VehicleStateListener() { } 00448 00453 virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0; 00454 00455 }; 00456 00457 00461 void addVehicleStateListener(VehicleStateListener* listener) ; 00462 00463 00467 void removeVehicleStateListener(VehicleStateListener* listener) ; 00468 00469 00475 void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to) ; 00477 00478 00488 class EdgeWeightsProxi { 00489 public: 00494 EdgeWeightsProxi(const MSEdgeWeightsStorage& vehKnowledge, 00495 const MSEdgeWeightsStorage& netKnowledge) 00496 : myVehicleKnowledge(vehKnowledge), myNetKnowledge(netKnowledge) {} 00497 00498 00500 ~EdgeWeightsProxi() {} 00501 00502 00510 SUMOReal getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) const; 00511 00512 00520 SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) const; 00521 00522 private: 00523 EdgeWeightsProxi& operator=(const EdgeWeightsProxi&); // just to avoid a compiler warning 00524 00525 private: 00527 const MSEdgeWeightsStorage& myVehicleKnowledge; 00528 00530 const MSEdgeWeightsStorage& myNetKnowledge; 00531 00532 }; 00533 00534 00535 #ifdef _MESSAGES 00536 00537 typedef NamedObjectCont< MSMessageEmitter* > MsgEmitterDict; 00538 00539 // TODO 00546 MSMessageEmitter* getMsgEmitter(const std::string& whatemit); 00547 00552 void createMsgEmitter(std::string& id, 00553 std::string& file, 00554 const std::string& base, 00555 std::string& whatemit, 00556 bool reverse, 00557 bool table, 00558 bool xy, 00559 SUMOReal step); 00560 #endif 00561 00562 protected: 00564 static MSNet* myInstance; 00565 00567 MSRouteLoaderControl* myRouteLoaders; 00568 00570 SUMOTime myStep; 00571 00572 00573 00576 00578 MSVehicleControl* myVehicleControl; 00580 MSPersonControl* myPersonControl; 00582 MSEdgeControl* myEdges; 00584 MSJunctionControl* myJunctions; 00586 MSTLLogicControl* myLogics; 00588 MSInsertionControl* myInserter; 00590 MSDetectorControl* myDetectorControl; 00592 MSEventControl* myBeginOfTimestepEvents; 00594 MSEventControl* myEndOfTimestepEvents; 00596 MSEventControl* myInsertionEvents; 00598 ShapeContainer* myShapeContainer; 00600 MSEdgeWeightsStorage* myEdgeWeights; 00602 00603 00604 00607 00609 bool myLogExecutionTime; 00610 00612 bool myLogStepNumber; 00613 00615 long mySimStepBegin, mySimStepEnd, mySimStepDuration; 00616 00618 long mySimBeginMillis; 00619 00621 long myVehiclesMoved; 00622 //} 00623 00624 00625 00628 00630 std::vector<SUMOTime> myStateDumpTimes; 00632 std::vector<std::string> myStateDumpFiles; 00634 00635 00637 int myTooManyVehicles; 00638 00639 00641 NamedObjectCont<MSBusStop*> myBusStopDict; 00642 00644 std::vector<VehicleStateListener*> myVehicleStateListeners; 00645 00646 00647 #ifdef _MESSAGES 00648 00649 MsgEmitterDict myMsgEmitter; 00650 00652 std::vector<MSMessageEmitter*> msgEmitVec; 00653 #endif 00654 00655 00656 private: 00658 MSNet(const MSNet&); 00659 00661 MSNet& operator=(const MSNet&); 00662 00663 00664 }; 00665 00666 00667 #endif 00668 00669 /****************************************************************************/ 00670