SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // A loaded (complete) traffic light logic 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 NBLoadedTLDef_h 00022 #define NBLoadedTLDef_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 <set> 00037 #include "NBTrafficLightDefinition.h" 00038 #include "NBNode.h" 00039 #include <utils/common/SUMOTime.h> 00040 00041 00042 // =========================================================================== 00043 // class definitions 00044 // =========================================================================== 00049 class NBLoadedTLDef : public NBTrafficLightDefinition { 00050 public: 00054 class SignalGroup : public Named { 00055 public: 00059 SignalGroup(const std::string& id) ; 00060 00062 ~SignalGroup() ; 00063 00067 void addConnection(const NBConnection& c) ; 00068 00073 void addPhaseBegin(SUMOTime time, TLColor color) ; 00074 00079 void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow) ; 00080 00085 std::vector<SUMOReal> getTimes(SUMOTime cycleDuration) const ; 00086 00088 void sortPhases() ; 00089 00093 unsigned int getLinkNo() const ; 00094 00099 bool mayDrive(SUMOTime time) const ; 00100 00105 bool hasYellow(SUMOTime time) const ; 00106 00112 bool containsConnection(NBEdge* from, NBEdge* to) const ; 00113 00118 bool containsIncoming(NBEdge* from) const ; 00119 00124 void remapIncoming(NBEdge* which, const EdgeVector& by) ; 00125 00130 bool containsOutgoing(NBEdge* to) const ; 00131 00136 void remapOutgoing(NBEdge* which, const EdgeVector& by) ; 00137 00142 const NBConnection& getConnection(unsigned int pos) const ; 00143 00147 void patchTYellow(SUMOTime tyellow) ; 00148 00155 void remap(NBEdge* removed, int removedLane, NBEdge* by, int byLane) ; 00156 00160 class PhaseDef { 00161 public: 00166 PhaseDef(SUMOTime time, TLColor color) 00167 : myTime(time), myColor(color) { } 00168 00170 SUMOTime myTime; 00172 TLColor myColor; 00173 }; 00174 00178 class phase_by_time_sorter { 00179 public: 00181 explicit phase_by_time_sorter() { } 00182 00187 int operator()(const PhaseDef& p1, const PhaseDef& p2) { 00188 return p1.myTime < p2.myTime; 00189 } 00190 }; 00191 00192 private: 00194 NBConnectionVector myConnections; 00196 std::vector<PhaseDef> myPhases; 00198 SUMOTime myTRedYellow, myTYellow; 00199 }; 00200 00201 00202 00204 typedef std::map<std::string, SignalGroup*> SignalGroupCont; 00205 00206 00211 NBLoadedTLDef(const std::string& id, 00212 const std::vector<NBNode*> &junctions) ; 00213 00214 00219 NBLoadedTLDef(const std::string& id, NBNode* junction) ; 00220 00221 00225 NBLoadedTLDef(const std::string& id) ; 00226 00227 00229 ~NBLoadedTLDef() ; 00230 00231 00237 SignalGroup* findGroup(NBEdge* from, NBEdge* to) const ; 00238 00239 00243 void setCycleDuration(unsigned int cycleDur) ; 00244 00245 00249 void addSignalGroup(const std::string& id) ; 00250 00251 00256 bool addToSignalGroup(const std::string& groupid, 00257 const NBConnection& connection) ; 00258 00259 00264 bool addToSignalGroup(const std::string& groupid, 00265 const NBConnectionVector& connections) ; 00266 00267 00273 void addSignalGroupPhaseBegin(const std::string& groupid, 00274 SUMOTime time, TLColor color) ; 00275 00276 00282 void setSignalYellowTimes(const std::string& groupid, 00283 SUMOTime tRedYellow, SUMOTime tYellow) ; 00284 00285 00288 00293 void setTLControllingInformation(const NBEdgeCont& ec) const ; 00294 00295 00302 void remapRemoved(NBEdge* removed, 00303 const EdgeVector& incoming, const EdgeVector& outgoing) ; 00305 00306 00307 protected: 00310 00317 NBTrafficLightLogic* myCompute(const NBEdgeCont& ec, 00318 unsigned int brakingTime) ; 00319 00320 00324 void collectNodes() ; 00325 00326 00331 void collectLinks() ; 00332 00333 00341 bool mustBrake(const NBEdgeCont& ec, 00342 const NBConnection& possProhibited, 00343 const std::string& state, 00344 unsigned int strmpos) const ; 00345 00346 00354 void replaceRemoved(NBEdge* removed, int removedLane, 00355 NBEdge* by, int byLane) ; 00357 00358 private: 00364 std::string buildPhaseState(const NBEdgeCont& ec, unsigned int time) const ; 00365 00366 00367 private: 00369 SignalGroupCont mySignalGroups; 00370 00372 unsigned int myCycleDuration; 00373 00374 00375 }; 00376 00377 00378 #endif 00379 00380 /****************************************************************************/ 00381