|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // The base class for traffic light logic definitions 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 NBTrafficLightDefinition_h 00020 #define NBTrafficLightDefinition_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 <vector> 00033 #include <string> 00034 #include <bitset> 00035 #include <utility> 00036 #include <set> 00037 #include <utils/common/Named.h> 00038 #include <utils/common/VectorHelper.h> 00039 #include <utils/common/SUMOTime.h> 00040 #include <utils/common/UtilExceptions.h> 00041 #include "NBCont.h" 00042 #include "NBConnection.h" 00043 #include "NBConnectionDefs.h" 00044 #include "NBLinkPossibilityMatrix.h" 00045 00046 00047 // =========================================================================== 00048 // class declarations 00049 // =========================================================================== 00050 class NBNode; 00051 class OptionsCont; 00052 class NBTrafficLightLogic; 00053 00054 00055 // =========================================================================== 00056 // class definitions 00057 // =========================================================================== 00070 class NBTrafficLightDefinition : public Named { 00071 public: 00072 00073 static const std::string DefaultProgramID; 00074 00079 enum TLColor { 00081 TLCOLOR_RED, 00083 TLCOLOR_YELLOW, 00085 TLCOLOR_REDYELLOW, 00087 TLCOLOR_GREEN, 00089 TLCOLOR_BLINK 00090 }; 00091 00092 00097 NBTrafficLightDefinition(const std::string& id, 00098 const std::vector<NBNode*> &junctions, 00099 const std::string& programID) throw(); 00100 00101 00106 NBTrafficLightDefinition(const std::string& id, 00107 NBNode* junction, 00108 const std::string& programID) throw(); 00109 00110 00114 NBTrafficLightDefinition(const std::string& id, const std::string& programID) throw(); 00115 00116 00118 virtual ~NBTrafficLightDefinition() throw(); 00119 00120 00130 NBTrafficLightLogic* compute(const NBEdgeCont& ec, OptionsCont& oc) throw(); 00131 00132 00133 00136 00140 virtual void addNode(NBNode* node); 00141 00142 00146 virtual void removeNode(NBNode* node); 00147 00148 00152 const std::vector<NBNode*> &getNodes() const throw() { 00153 return myControlledNodes; 00154 } 00156 00157 00168 bool mustBrake(const NBEdge* const from, const NBEdge* const to) const throw(); 00169 00170 00178 bool mustBrake(const NBConnection& possProhibited, 00179 const NBConnection& possProhibitor, 00180 bool regardNonSignalisedLowerPriority) const throw(); 00181 00191 bool mustBrake(const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo, 00192 const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo, 00193 bool regardNonSignalisedLowerPriority) const throw(); 00194 00195 00205 bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo, 00206 const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo, 00207 bool regardNonSignalisedLowerPriority) const throw(); 00208 00209 00217 bool foes(const NBEdge* const from1, const NBEdge* const to1, 00218 const NBEdge* const from2, const NBEdge* const to2) const throw(); 00219 00220 00224 virtual void setTLControllingInformation(const NBEdgeCont& ec) const throw() = 0; 00225 00226 00229 virtual void setParticipantsInformation() throw(); 00230 00231 00235 void addControlledInnerEdges(const std::vector<std::string> &edges) throw(); 00236 00237 00243 virtual void remapRemoved(NBEdge* removed, 00244 const EdgeVector& incoming, const EdgeVector& outgoing) throw() = 0; 00245 00246 00253 virtual void replaceRemoved(NBEdge* removed, int removedLane, 00254 NBEdge* by, int byLane) throw() = 0; 00255 00256 00262 bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const throw(); 00263 00264 00268 const EdgeVector& getIncomingEdges() const throw(); 00269 00270 00272 const NBConnectionVector& getControlledLinks() const { 00273 return myControlledLinks; 00274 } 00275 00276 00277 // @breif returns the controlled nodes 00278 const std::vector<NBNode*>& getControlledNodes() const { 00279 return myControlledNodes; 00280 } 00281 00282 00286 const std::string& getProgramID() const { 00287 return mySubID; 00288 }; 00289 00290 00291 void setProgramID(const std::string& programID) { 00292 mySubID = programID; 00293 } 00294 00295 00296 protected: 00302 virtual NBTrafficLightLogic* myCompute(const NBEdgeCont& ec, 00303 unsigned int brakingTime) throw() = 0; 00304 00305 00309 virtual void collectLinks() = 0; 00310 00311 00314 void collectEdges() throw(); 00315 00316 00322 unsigned int computeBrakingTime(SUMOReal minDecel) const throw(); 00323 00324 00325 // @return whether this traffic light is invalid and should be computed 00326 virtual bool amInvalid() const; 00327 00328 00329 protected: 00331 std::vector<NBNode*> myControlledNodes; 00332 00334 EdgeVector myIncomingEdges; 00335 00337 EdgeVector myEdgesWithin; 00338 00340 NBConnectionVector myControlledLinks; 00341 00343 std::set<std::string> myControlledInnerEdges; 00344 00346 std::string mySubID; 00347 00348 }; 00349 00350 00351 #endif 00352 00353 /****************************************************************************/ 00354