|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // The simulated network and simulation perfomer 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 MSNet_h 00020 #define MSNet_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 <typeinfo> 00033 #include <vector> 00034 #include <map> 00035 #include <string> 00036 #include <fstream> 00037 #include <iostream> 00038 #include <cmath> 00039 #include <iomanip> 00040 #include "MSVehicleControl.h" 00041 #include "MSEventControl.h" 00042 #include <utils/geom/Boundary.h> 00043 #include <utils/geom/Position.h> 00044 #include <utils/common/SUMOTime.h> 00045 #include <microsim/trigger/MSBusStop.h> 00046 #include <utils/common/UtilExceptions.h> 00047 #include <utils/common/NamedObjectCont.h> 00048 00049 // =========================================================================== 00050 // class declarations 00051 // =========================================================================== 00052 class MSEdge; 00053 class MSEdgeControl; 00054 class MSJunctionControl; 00055 class MSInsertionControl; 00056 class MSRouteLoaderControl; 00057 class MSPersonControl; 00058 class MSVehicle; 00059 class MSRoute; 00060 class MSLane; 00061 class MSTLLogicControl; 00062 class MSDetectorControl; 00063 class ShapeContainer; 00064 class BinaryInputDevice; 00065 class MSRouteLoader; 00066 class MSEdgeWeightsStorage; 00067 class SUMOVehicle; 00068 #ifdef _MESSAGES 00069 class MSMessageEmitter; 00070 #endif 00071 00072 00073 // =========================================================================== 00074 // class definitions 00075 // =========================================================================== 00080 class MSNet { 00081 public: 00085 enum SimulationState { 00087 SIMSTATE_RUNNING, 00089 SIMSTATE_END_STEP_REACHED, 00091 SIMSTATE_NO_FURTHER_VEHICLES, 00093 SIMSTATE_CONNECTION_CLOSED, 00095 SIMSTATE_ERROR_IN_SIM, 00097 SIMSTATE_TOO_MANY_VEHICLES 00098 }; 00099 00100 00101 public: 00106 static MSNet* getInstance() throw(ProcessError); 00107 00108 00123 MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents, 00124 MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents, 00125 ShapeContainer* shapeCont=0) throw(ProcessError); 00126 00127 00129 virtual ~MSNet() throw(); 00130 00131 00143 void closeBuilding(MSEdgeControl* edges, MSJunctionControl* junctions, 00144 MSRouteLoaderControl* routeLoaders, MSTLLogicControl* tlc, 00145 std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles) throw(); 00146 00147 00151 static void clearAll(); 00152 00153 00161 int simulate(SUMOTime start, SUMOTime stop); 00162 00163 00167 void simulationStep(); 00168 00169 00177 void closeSimulation(SUMOTime start); 00178 00179 00185 SimulationState simulationState(SUMOTime stopTime) const throw(); 00186 00187 00191 static std::string getStateMessage(SimulationState state) throw(); 00192 00193 00197 SUMOTime getCurrentTimeStep() const; 00198 00199 00203 void writeOutput(); 00204 00205 00209 bool logSimulationDuration() const throw(); 00210 00211 00213 00214 00219 void preSimStepOutput() const throw(); 00220 00221 00226 void postSimStepOutput() const throw(); 00227 //} 00228 00229 00230 00231 #ifdef HAVE_MESOSIM 00232 00233 00234 00239 void saveState(std::ostream& os) throw(); 00240 00241 00246 unsigned int loadState(BinaryInputDevice& bis) throw(); 00248 #endif 00249 00252 00258 MSVehicleControl& getVehicleControl() throw() { 00259 return *myVehicleControl; 00260 } 00261 00262 00271 MSPersonControl& getPersonControl() throw(); 00272 00273 00279 MSEdgeControl& getEdgeControl() throw() { 00280 return *myEdges; 00281 } 00282 00283 00289 MSInsertionControl& getInsertionControl() throw() { 00290 return *myInserter; 00291 } 00292 00293 00299 MSDetectorControl& getDetectorControl() throw() { 00300 return *myDetectorControl; 00301 } 00302 00303 00309 MSTLLogicControl& getTLSControl() throw() { 00310 return *myLogics; 00311 } 00312 00313 00319 MSJunctionControl& getJunctionControl() throw() { 00320 return *myJunctions; 00321 } 00322 00323 00329 MSEventControl& getBeginOfTimestepEvents() throw() { 00330 return *myBeginOfTimestepEvents; 00331 } 00332 00333 00339 MSEventControl& getEndOfTimestepEvents() throw() { 00340 return *myEndOfTimestepEvents; 00341 } 00342 00343 00349 MSEventControl& getInsertionEvents() throw() { 00350 return *myInsertionEvents; 00351 } 00352 00353 00359 ShapeContainer& getShapeContainer() throw() { 00360 return *myShapeContainer; 00361 } 00362 00363 00369 MSEdgeWeightsStorage& getWeightsStorage() throw(); 00371 00372 00373 00376 00388 bool addBusStop(MSBusStop* busStop); 00389 00390 00395 MSBusStop* getBusStop(const std::string& id) const; 00396 00397 00403 std::string getBusStopID(const MSLane* lane, const SUMOReal pos) const; 00405 00406 00407 00408 00409 00410 00413 00415 enum VehicleState { 00417 VEHICLE_STATE_BUILT, 00419 VEHICLE_STATE_DEPARTED, 00421 VEHICLE_STATE_STARTING_TELEPORT, 00423 VEHICLE_STATE_ENDING_TELEPORT, 00425 VEHICLE_STATE_ARRIVED, 00427 VEHICLE_STATE_NEWROUTE 00428 }; 00429 00430 00434 class VehicleStateListener { 00435 public: 00437 VehicleStateListener() { } 00438 00440 virtual ~VehicleStateListener() { } 00441 00446 virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0; 00447 00448 }; 00449 00450 00454 void addVehicleStateListener(VehicleStateListener* listener) throw(); 00455 00456 00460 void removeVehicleStateListener(VehicleStateListener* listener) throw(); 00461 00462 00468 void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to) throw(); 00470 00471 00481 class EdgeWeightsProxi { 00482 public: 00487 EdgeWeightsProxi(const MSEdgeWeightsStorage& vehKnowledge, 00488 const MSEdgeWeightsStorage& netKnowledge) 00489 : myVehicleKnowledge(vehKnowledge), myNetKnowledge(netKnowledge) {} 00490 00491 00493 ~EdgeWeightsProxi() {} 00494 00495 00503 SUMOReal getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) const; 00504 00505 00513 SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) const; 00514 00515 private: 00516 EdgeWeightsProxi& operator=(const EdgeWeightsProxi&); // just to avoid a compiler warning 00517 00518 private: 00520 const MSEdgeWeightsStorage& myVehicleKnowledge; 00521 00523 const MSEdgeWeightsStorage& myNetKnowledge; 00524 00525 }; 00526 00527 00528 #ifdef _MESSAGES 00529 00530 typedef NamedObjectCont< MSMessageEmitter* > MsgEmitterDict; 00531 00532 // TODO 00539 MSMessageEmitter* getMsgEmitter(const std::string& whatemit); 00540 00545 void createMsgEmitter(std::string& id, 00546 std::string& file, 00547 const std::string& base, 00548 std::string& whatemit, 00549 bool reverse, 00550 bool table, 00551 bool xy, 00552 SUMOReal step); 00553 #endif 00554 00555 protected: 00557 static MSNet* myInstance; 00558 00560 MSRouteLoaderControl* myRouteLoaders; 00561 00563 SUMOTime myStep; 00564 00565 00566 00569 00571 MSVehicleControl* myVehicleControl; 00573 MSPersonControl* myPersonControl; 00575 MSEdgeControl* myEdges; 00577 MSJunctionControl* myJunctions; 00579 MSTLLogicControl* myLogics; 00581 MSInsertionControl* myInserter; 00583 MSDetectorControl* myDetectorControl; 00585 MSEventControl* myBeginOfTimestepEvents; 00587 MSEventControl* myEndOfTimestepEvents; 00589 MSEventControl* myInsertionEvents; 00591 ShapeContainer* myShapeContainer; 00593 MSEdgeWeightsStorage* myEdgeWeights; 00595 00596 00597 00600 00602 bool myLogExecutionTime; 00603 00605 bool myLogStepNumber; 00606 00608 long mySimStepBegin, mySimStepEnd, mySimStepDuration; 00609 00611 long mySimBeginMillis; 00612 00614 long myVehiclesMoved; 00615 //} 00616 00617 00618 00621 00623 std::vector<SUMOTime> myStateDumpTimes; 00625 std::vector<std::string> myStateDumpFiles; 00627 00628 00630 int myTooManyVehicles; 00631 00632 00634 NamedObjectCont<MSBusStop*> myBusStopDict; 00635 00637 std::vector<VehicleStateListener*> myVehicleStateListeners; 00638 00639 00640 #ifdef _MESSAGES 00641 00642 MsgEmitterDict myMsgEmitter; 00643 00645 std::vector<MSMessageEmitter*> msgEmitVec; 00646 #endif 00647 00648 00649 private: 00651 MSNet(const MSNet&); 00652 00654 MSNet& operator=(const MSNet&); 00655 00656 00657 }; 00658 00659 00660 #endif 00661 00662 /****************************************************************************/ 00663