NBLoadedTLDef.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A loaded (complete) traffic light logic
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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 NBLoadedTLDef_h
00020 #define NBLoadedTLDef_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 <set>
00035 #include "NBTrafficLightDefinition.h"
00036 #include "NBNode.h"
00037 #include <utils/common/SUMOTime.h>
00038 
00039 
00040 // ===========================================================================
00041 // class definitions
00042 // ===========================================================================
00047 class NBLoadedTLDef : public NBTrafficLightDefinition {
00048 public:
00052     class SignalGroup : public Named {
00053     public:
00057         SignalGroup(const std::string &id) throw();
00058 
00060         ~SignalGroup() throw();
00061 
00065         void addConnection(const NBConnection &c) throw();
00066 
00071         void addPhaseBegin(SUMOTime time, TLColor color) throw();
00072 
00077         void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow) throw();
00078 
00083         DoubleVector getTimes(SUMOTime cycleDuration) const throw();
00084 
00086         void sortPhases() throw();
00087 
00091         unsigned int getLinkNo() const throw();
00092 
00097         bool mayDrive(SUMOTime time) const throw();
00098 
00103         bool hasYellow(SUMOTime time) const throw();
00104 
00110         bool containsConnection(NBEdge *from, NBEdge *to) const throw();
00111 
00116         bool containsIncoming(NBEdge *from) const throw();
00117 
00122         void remapIncoming(NBEdge *which, const EdgeVector &by) throw(ProcessError);
00123 
00128         bool containsOutgoing(NBEdge *to) const throw();
00129 
00134         void remapOutgoing(NBEdge *which, const EdgeVector &by) throw(ProcessError);
00135 
00140         const NBConnection &getConnection(unsigned int pos) const throw();
00141 
00145         void patchTYellow(SUMOTime tyellow) throw();
00146 
00153         void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane) throw();
00154 
00158         class PhaseDef {
00159         public:
00164             PhaseDef(SUMOTime time, TLColor color) throw()
00165                     : myTime(time), myColor(color) { }
00166 
00168             SUMOTime myTime;
00170             TLColor myColor;
00171         };
00172 
00176         class phase_by_time_sorter {
00177         public:
00179             explicit phase_by_time_sorter() { }
00180 
00185             int operator()(const PhaseDef &p1, const PhaseDef &p2) {
00186                 return p1.myTime<p2.myTime;
00187             }
00188         };
00189 
00190     private:
00192         NBConnectionVector myConnections;
00194         std::vector<PhaseDef> myPhases;
00196         SUMOTime myTRedYellow, myTYellow;
00197     };
00198 
00199 
00200 
00202     typedef std::map<std::string, SignalGroup*> SignalGroupCont;
00203 
00204 
00209     NBLoadedTLDef(const std::string &id,
00210                   const std::vector<NBNode*> &junctions) throw();
00211 
00212 
00217     NBLoadedTLDef(const std::string &id, NBNode *junction) throw();
00218 
00219 
00223     NBLoadedTLDef(const std::string &id) throw();
00224 
00225 
00227     ~NBLoadedTLDef() throw();
00228 
00229 
00235     SignalGroup *findGroup(NBEdge *from, NBEdge *to) const throw();
00236 
00237 
00241     void setCycleDuration(unsigned int cycleDur) throw();
00242 
00243 
00247     void addSignalGroup(const std::string &id) throw();
00248 
00249 
00254     bool addToSignalGroup(const std::string &groupid,
00255                           const NBConnection &connection) throw();
00256 
00257 
00262     bool addToSignalGroup(const std::string &groupid,
00263                           const NBConnectionVector &connections) throw();
00264 
00265 
00271     void addSignalGroupPhaseBegin(const std::string &groupid,
00272                                   SUMOTime time, TLColor color) throw();
00273 
00274 
00280     void setSignalYellowTimes(const std::string &groupid,
00281                               SUMOTime tRedYellow, SUMOTime tYellow) throw();
00282 
00283 
00286 
00291     void setTLControllingInformation(const NBEdgeCont &ec) const throw();
00292 
00293 
00300     void remapRemoved(NBEdge *removed,
00301                       const EdgeVector &incoming, const EdgeVector &outgoing) throw();
00303 
00304 
00305 protected:
00308 
00315     NBTrafficLightLogic *myCompute(const NBEdgeCont &ec,
00316                                    unsigned int brakingTime) throw();
00317 
00318 
00322     void collectNodes() throw();
00323 
00324 
00329     void collectLinks() throw(ProcessError);
00330 
00331 
00339     bool mustBrake(const NBEdgeCont &ec,
00340                    const NBConnection &possProhibited,
00341                    const std::string &state,
00342                    unsigned int strmpos) const throw();
00343 
00344 
00352     void replaceRemoved(NBEdge *removed, int removedLane,
00353                         NBEdge *by, int byLane) throw();
00355 
00356 private:
00362     std::string buildPhaseState(const NBEdgeCont &ec, unsigned int time) const throw();
00363 
00364 
00365 private:
00367     SignalGroupCont mySignalGroups;
00368 
00370     unsigned int myCycleDuration;
00371 
00372 
00373 };
00374 
00375 
00376 #endif
00377 
00378 /****************************************************************************/
00379 

Generated on Wed May 5 00:06:33 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6