SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // The base class for traffic light logic definitions 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 #ifndef NBTrafficLightDefinition_h 00022 #define NBTrafficLightDefinition_h 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #include <vector> 00035 #include <string> 00036 #include <bitset> 00037 #include <utility> 00038 #include <set> 00039 #include <utils/common/Named.h> 00040 #include <utils/common/VectorHelper.h> 00041 #include <utils/common/SUMOTime.h> 00042 #include <utils/common/UtilExceptions.h> 00043 #include "NBCont.h" 00044 #include "NBConnection.h" 00045 #include "NBConnectionDefs.h" 00046 #include "NBLinkPossibilityMatrix.h" 00047 00048 00049 // =========================================================================== 00050 // class declarations 00051 // =========================================================================== 00052 class NBNode; 00053 class OptionsCont; 00054 class NBTrafficLightLogic; 00055 00056 00057 // =========================================================================== 00058 // class definitions 00059 // =========================================================================== 00072 class NBTrafficLightDefinition : public Named { 00073 public: 00074 00075 static const std::string DefaultProgramID; 00076 00081 enum TLColor { 00083 TLCOLOR_RED, 00085 TLCOLOR_YELLOW, 00087 TLCOLOR_REDYELLOW, 00089 TLCOLOR_GREEN, 00091 TLCOLOR_BLINK 00092 }; 00093 00094 00099 NBTrafficLightDefinition(const std::string& id, 00100 const std::vector<NBNode*> &junctions, 00101 const std::string& programID) ; 00102 00103 00108 NBTrafficLightDefinition(const std::string& id, 00109 NBNode* junction, 00110 const std::string& programID) ; 00111 00112 00116 NBTrafficLightDefinition(const std::string& id, const std::string& programID) ; 00117 00118 00120 virtual ~NBTrafficLightDefinition() ; 00121 00122 00132 NBTrafficLightLogic* compute(const NBEdgeCont& ec, OptionsCont& oc) ; 00133 00134 00135 00138 00142 virtual void addNode(NBNode* node); 00143 00144 00148 virtual void removeNode(NBNode* node); 00149 00150 00154 const std::vector<NBNode*> &getNodes() const { 00155 return myControlledNodes; 00156 } 00158 00159 00170 bool mustBrake(const NBEdge* const from, const NBEdge* const to) const ; 00171 00172 00180 bool mustBrake(const NBConnection& possProhibited, 00181 const NBConnection& possProhibitor, 00182 bool regardNonSignalisedLowerPriority) const ; 00183 00193 bool mustBrake(const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo, 00194 const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo, 00195 bool regardNonSignalisedLowerPriority) const ; 00196 00197 00207 bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo, 00208 const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo, 00209 bool regardNonSignalisedLowerPriority) const ; 00210 00211 00219 bool foes(const NBEdge* const from1, const NBEdge* const to1, 00220 const NBEdge* const from2, const NBEdge* const to2) const ; 00221 00222 00226 virtual void setTLControllingInformation(const NBEdgeCont& ec) const = 0; 00227 00228 00231 virtual void setParticipantsInformation() ; 00232 00233 00237 void addControlledInnerEdges(const std::vector<std::string> &edges) ; 00238 00239 00245 virtual void remapRemoved(NBEdge* removed, 00246 const EdgeVector& incoming, const EdgeVector& outgoing) = 0; 00247 00248 00255 virtual void replaceRemoved(NBEdge* removed, int removedLane, 00256 NBEdge* by, int byLane) = 0; 00257 00258 00264 bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const ; 00265 00266 00270 const EdgeVector& getIncomingEdges() const ; 00271 00272 00274 const NBConnectionVector& getControlledLinks() const { 00275 return myControlledLinks; 00276 } 00277 00278 00279 // @breif returns the controlled nodes 00280 const std::vector<NBNode*>& getControlledNodes() const { 00281 return myControlledNodes; 00282 } 00283 00284 00288 const std::string& getProgramID() const { 00289 return mySubID; 00290 }; 00291 00292 00293 void setProgramID(const std::string& programID) { 00294 mySubID = programID; 00295 } 00296 00297 00298 protected: 00304 virtual NBTrafficLightLogic* myCompute(const NBEdgeCont& ec, 00305 unsigned int brakingTime) = 0; 00306 00307 00311 virtual void collectLinks() = 0; 00312 00313 00316 void collectEdges() ; 00317 00318 00324 unsigned int computeBrakingTime(SUMOReal minDecel) const ; 00325 00326 00327 // @return whether this traffic light is invalid and should be computed 00328 virtual bool amInvalid() const; 00329 00330 00331 protected: 00333 std::vector<NBNode*> myControlledNodes; 00334 00336 EdgeVector myIncomingEdges; 00337 00339 EdgeVector myEdgesWithin; 00340 00342 NBConnectionVector myControlledLinks; 00343 00345 std::set<std::string> myControlledInnerEdges; 00346 00348 std::string mySubID; 00349 00350 }; 00351 00352 00353 #endif 00354 00355 /****************************************************************************/ 00356