SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00011 // The parent class for traffic light logics 00012 /****************************************************************************/ 00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00015 /****************************************************************************/ 00016 // 00017 // This file is part of SUMO. 00018 // SUMO is free software: you can redistribute it and/or modify 00019 // it under the terms of the GNU General Public License as published by 00020 // the Free Software Foundation, either version 3 of the License, or 00021 // (at your option) any later version. 00022 // 00023 /****************************************************************************/ 00024 #ifndef MSTrafficLightLogic_h 00025 #define MSTrafficLightLogic_h 00026 00027 00028 // =========================================================================== 00029 // included modules 00030 // =========================================================================== 00031 #ifdef _MSC_VER 00032 #include <windows_config.h> 00033 #else 00034 #include <config.h> 00035 #endif 00036 00037 #include <map> 00038 #include <string> 00039 #include <bitset> 00040 #include <utils/common/Command.h> 00041 #include <microsim/MSLogicJunction.h> 00042 #include <microsim/MSLink.h> 00043 #include "MSPhaseDefinition.h" 00044 00045 00046 // =========================================================================== 00047 // class declarations 00048 // =========================================================================== 00049 class MSNet; 00050 class MSLink; 00051 class MSTLLogicControl; 00052 class NLDetectorBuilder; 00053 00054 00055 // =========================================================================== 00056 // class definitions 00057 // =========================================================================== 00062 class MSTrafficLightLogic { 00063 public: 00066 00068 typedef std::vector<MSPhaseDefinition*> Phases; 00069 00071 typedef std::vector<MSLink*> LinkVector; 00072 00074 typedef std::vector<LinkVector> LinkVectorVector; 00075 00077 typedef std::vector<MSLane*> LaneVector; 00078 00080 typedef std::vector<LaneVector> LaneVectorVector; 00082 00083 00084 public: 00091 MSTrafficLightLogic(MSTLLogicControl& tlcontrol, 00092 const std::string& id, const std::string& programID, SUMOTime delay); 00093 00094 00100 virtual void init(NLDetectorBuilder& nb); 00101 00102 00104 virtual ~MSTrafficLightLogic(); 00105 00106 00107 00110 00116 void addLink(MSLink* link, MSLane* lane, unsigned int pos); 00117 00118 00126 virtual void adaptLinkInformationFrom(const MSTrafficLightLogic& logic); 00127 00128 00132 std::map<MSLink*, LinkState> collectLinkStates() const; 00133 00134 00138 void resetLinkStates(const std::map<MSLink*, LinkState> &vals) const; 00140 00141 00142 00145 00150 virtual SUMOTime trySwitch(bool isActive) = 0; 00151 00152 00159 bool setTrafficLightSignals(SUMOTime t) const; 00161 00162 00163 00166 00170 const std::string& getID() const { 00171 return myID; 00172 } 00173 00174 00178 const std::string& getProgramID() const { 00179 return myProgramID; 00180 } 00181 00182 00186 const LaneVectorVector& getLanes() const { 00187 return myLanes; 00188 } 00189 00190 00195 const LaneVector& getLanesAt(unsigned int i) const { 00196 return myLanes[i]; 00197 } 00198 00199 00203 const LinkVectorVector& getLinks() const { 00204 return myLinks; 00205 } 00206 00207 00212 const LinkVector& getLinksAt(unsigned int i) const { 00213 return myLinks[i]; 00214 } 00215 00216 00221 int getLinkIndex(const MSLink* const link) const; 00222 00223 00227 virtual unsigned int getPhaseNumber() const = 0; 00228 00229 00233 virtual const Phases& getPhases() const = 0; 00234 00235 00240 virtual const MSPhaseDefinition& getPhase(unsigned int givenstep) const = 0; 00242 00243 00244 00247 00251 virtual unsigned int getCurrentPhaseIndex() const = 0; 00252 00253 00257 virtual const MSPhaseDefinition& getCurrentPhaseDef() const = 0; 00258 00259 00263 SUMOTime getDefaultCycleTime() const { 00264 return myDefaultCycleTime; 00265 } 00266 00267 00273 SUMOTime getNextSwitchTime() const; 00275 00276 00277 00280 00284 virtual SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const = 0; 00285 00286 00291 virtual SUMOTime getOffsetFromIndex(unsigned int index) const = 0; 00292 00293 00298 virtual unsigned int getIndexFromOffset(SUMOTime offset) const = 0; 00300 00301 00302 00305 00309 void addOverridingDuration(SUMOTime duration); 00310 00311 00315 void setCurrentDurationIncrement(SUMOTime delay); 00316 00317 00324 virtual void changeStepAndDuration(MSTLLogicControl& tlcontrol, 00325 SUMOTime simStep, unsigned int step, SUMOTime stepDuration) = 0; 00326 00328 00329 00330 00333 00337 void setParameter(const std::map<std::string, std::string> ¶ms); 00338 00339 00344 std::string getParameterValue(const std::string& key) const; 00346 00347 00348 protected: 00353 class SwitchCommand : public Command { 00354 public: 00360 SwitchCommand(MSTLLogicControl& tlcontrol, 00361 MSTrafficLightLogic* tlLogic, 00362 SUMOTime nextSwitch); 00363 00365 ~SwitchCommand(); 00366 00371 SUMOTime execute(SUMOTime currentTime); 00372 00373 00377 void deschedule(MSTrafficLightLogic* tlLogic); 00378 00379 00383 SUMOTime getNextSwitchTime() const { 00384 return myAssumedNextSwitch; 00385 } 00386 00387 00388 private: 00390 MSTLLogicControl& myTLControl; 00391 00393 MSTrafficLightLogic* myTLLogic; 00394 00396 SUMOTime myAssumedNextSwitch; 00397 00399 bool myAmValid; 00400 00401 private: 00403 SwitchCommand(const SwitchCommand&); 00404 00406 SwitchCommand& operator=(const SwitchCommand&); 00407 00408 }; 00409 00410 protected: 00412 std::map<std::string, std::string> myParameter; 00413 00415 std::string myID, myProgramID; 00416 00418 LinkVectorVector myLinks; 00419 00421 LaneVectorVector myLanes; 00422 00424 std::vector<SUMOTime> myOverridingTimes; 00425 00427 SUMOTime myCurrentDurationIncrement; 00428 00430 SwitchCommand* mySwitchCommand; 00431 00433 SUMOTime myDefaultCycleTime; 00434 00435 00436 private: 00438 MSTrafficLightLogic(const MSTrafficLightLogic& s); 00439 00441 MSTrafficLightLogic& operator=(const MSTrafficLightLogic& s); 00442 00443 }; 00444 00445 00446 #endif 00447 00448 /****************************************************************************/ 00449