|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // The parent class for traffic light logics 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 MSTrafficLightLogic_h 00020 #define MSTrafficLightLogic_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 <map> 00033 #include <string> 00034 #include <bitset> 00035 #include <utils/common/Command.h> 00036 #include <microsim/MSLogicJunction.h> 00037 #include <microsim/MSLink.h> 00038 #include "MSPhaseDefinition.h" 00039 00040 00041 // =========================================================================== 00042 // class declarations 00043 // =========================================================================== 00044 class MSNet; 00045 class MSLink; 00046 class MSTLLogicControl; 00047 class NLDetectorBuilder; 00048 00049 00050 // =========================================================================== 00051 // class definitions 00052 // =========================================================================== 00057 class MSTrafficLightLogic { 00058 public: 00061 00063 typedef std::vector<MSPhaseDefinition*> Phases; 00064 00066 typedef std::vector<MSLink*> LinkVector; 00067 00069 typedef std::vector<LinkVector> LinkVectorVector; 00070 00072 typedef std::vector<MSLane*> LaneVector; 00073 00075 typedef std::vector<LaneVector> LaneVectorVector; 00077 00078 00079 public: 00086 MSTrafficLightLogic(MSTLLogicControl& tlcontrol, 00087 const std::string& id, const std::string& programID, SUMOTime delay); 00088 00089 00095 virtual void init(NLDetectorBuilder& nb); 00096 00097 00099 virtual ~MSTrafficLightLogic(); 00100 00101 00102 00105 00111 void addLink(MSLink* link, MSLane* lane, unsigned int pos); 00112 00113 00121 virtual void adaptLinkInformationFrom(const MSTrafficLightLogic& logic); 00122 00123 00127 std::map<MSLink*, LinkState> collectLinkStates() const; 00128 00129 00133 void resetLinkStates(const std::map<MSLink*, LinkState> &vals) const; 00135 00136 00137 00140 00145 virtual SUMOTime trySwitch(bool isActive) = 0; 00146 00147 00154 bool setTrafficLightSignals(SUMOTime t) const; 00156 00157 00158 00161 00165 const std::string& getID() const { 00166 return myID; 00167 } 00168 00169 00173 const std::string& getProgramID() const { 00174 return myProgramID; 00175 } 00176 00177 00181 const LaneVectorVector& getLanes() const { 00182 return myLanes; 00183 } 00184 00185 00190 const LaneVector& getLanesAt(unsigned int i) const { 00191 return myLanes[i]; 00192 } 00193 00194 00198 const LinkVectorVector& getLinks() const { 00199 return myLinks; 00200 } 00201 00202 00207 const LinkVector& getLinksAt(unsigned int i) const { 00208 return myLinks[i]; 00209 } 00210 00211 00216 int getLinkIndex(const MSLink* const link) const; 00217 00218 00222 virtual unsigned int getPhaseNumber() const = 0; 00223 00224 00228 virtual const Phases& getPhases() const = 0; 00229 00230 00235 virtual const MSPhaseDefinition& getPhase(unsigned int givenstep) const = 0; 00237 00238 00239 00242 00246 virtual unsigned int getCurrentPhaseIndex() const = 0; 00247 00248 00252 virtual const MSPhaseDefinition& getCurrentPhaseDef() const = 0; 00253 00254 00258 SUMOTime getDefaultCycleTime() const { 00259 return myDefaultCycleTime; 00260 } 00261 00262 00268 SUMOTime getNextSwitchTime() const; 00270 00271 00272 00275 00279 virtual SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const = 0; 00280 00281 00286 virtual SUMOTime getOffsetFromIndex(unsigned int index) const = 0; 00287 00288 00293 virtual unsigned int getIndexFromOffset(SUMOTime offset) const = 0; 00295 00296 00297 00300 00304 void addOverridingDuration(SUMOTime duration); 00305 00306 00310 void setCurrentDurationIncrement(SUMOTime delay); 00311 00312 00319 virtual void changeStepAndDuration(MSTLLogicControl& tlcontrol, 00320 SUMOTime simStep, unsigned int step, SUMOTime stepDuration) = 0; 00321 00323 00324 00325 00328 00332 void setParameter(const std::map<std::string, std::string> ¶ms); 00333 00334 00339 std::string getParameterValue(const std::string& key) const; 00341 00342 00343 protected: 00348 class SwitchCommand : public Command { 00349 public: 00355 SwitchCommand(MSTLLogicControl& tlcontrol, 00356 MSTrafficLightLogic* tlLogic, 00357 SUMOTime nextSwitch); 00358 00360 ~SwitchCommand(); 00361 00366 SUMOTime execute(SUMOTime currentTime); 00367 00368 00372 void deschedule(MSTrafficLightLogic* tlLogic); 00373 00374 00378 SUMOTime getNextSwitchTime() const { 00379 return myAssumedNextSwitch; 00380 } 00381 00382 00383 private: 00385 MSTLLogicControl& myTLControl; 00386 00388 MSTrafficLightLogic* myTLLogic; 00389 00391 SUMOTime myAssumedNextSwitch; 00392 00394 bool myAmValid; 00395 00396 private: 00398 SwitchCommand(const SwitchCommand&); 00399 00401 SwitchCommand& operator=(const SwitchCommand&); 00402 00403 }; 00404 00405 protected: 00407 std::map<std::string, std::string> myParameter; 00408 00410 std::string myID, myProgramID; 00411 00413 LinkVectorVector myLinks; 00414 00416 LaneVectorVector myLanes; 00417 00419 std::vector<SUMOTime> myOverridingTimes; 00420 00422 SUMOTime myCurrentDurationIncrement; 00423 00425 SwitchCommand* mySwitchCommand; 00426 00428 SUMOTime myDefaultCycleTime; 00429 00430 00431 private: 00433 MSTrafficLightLogic(const MSTrafficLightLogic& s); 00434 00436 MSTrafficLightLogic& operator=(const MSTrafficLightLogic& s); 00437 00438 }; 00439 00440 00441 #endif 00442 00443 /****************************************************************************/ 00444