|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A SUMO-compliant built logic for a traffic light 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 NBTrafficLightLogic_h 00020 #define NBTrafficLightLogic_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 "NBConnectionDefs.h" 00038 #include <utils/common/SUMOTime.h> 00039 #include <utils/common/Named.h> 00040 00041 00042 // =========================================================================== 00043 // class declarations 00044 // =========================================================================== 00045 class OutputDevice; 00046 00047 00048 // =========================================================================== 00049 // class definitions 00050 // =========================================================================== 00055 class NBTrafficLightLogic : public Named { 00056 public: 00061 class PhaseDefinition { 00062 public: 00064 SUMOTime duration; 00065 00067 std::string state; 00068 00073 PhaseDefinition(SUMOTime durationArg, const std::string& stateArg) throw() 00074 : duration(durationArg), state(stateArg) { } 00075 00077 ~PhaseDefinition() throw() { } 00078 00083 bool operator!=(const PhaseDefinition& pd) const throw() { 00084 return pd.duration != duration || pd.state != state; 00085 } 00086 00087 }; 00088 00089 00095 NBTrafficLightLogic(const std::string& id, const std::string& subid, unsigned int noLinks) throw(); 00096 00097 00101 NBTrafficLightLogic(const NBTrafficLightLogic* logic); 00102 00103 00105 ~NBTrafficLightLogic() throw(); 00106 00107 00116 void addStep(SUMOTime duration, const std::string& state, int index=-1); 00117 00118 00124 void setPhaseState(unsigned int phaseIndex, int tlIndex, LinkState linkState); 00125 00130 void setPhaseDuration(unsigned int phaseIndex, SUMOTime duration); 00131 00132 /* @brief deletes the phase at the given index 00133 * @note thhrows InvalidArgument on out-of range index 00134 */ 00135 void deletePhase(unsigned int index); 00136 00137 /* @brief deletes all phases and reset the expect number of links 00138 */ 00139 void resetPhases(); 00140 00145 void closeBuilding() throw(); 00146 00147 00151 SUMOTime getDuration() const throw(); 00152 00153 00157 void setOffset(SUMOTime offset) throw() { 00158 myOffset = offset; 00159 } 00160 00161 00165 const std::string& getProgramID() const { 00166 return mySubID; 00167 }; 00168 00169 00173 const std::vector<PhaseDefinition> &getPhases() const { 00174 return myPhases; 00175 } 00176 00177 00181 SUMOTime getOffset() const { 00182 return myOffset; 00183 }; 00184 00185 00188 unsigned int getNumLinks() { 00189 return myNumLinks; 00190 } 00191 00192 00193 private: 00195 unsigned int myNumLinks; 00196 00198 const std::string mySubID; 00199 00201 SUMOTime myOffset; 00202 00204 typedef std::vector<PhaseDefinition> PhaseDefinitionVector; 00205 00207 PhaseDefinitionVector myPhases; 00208 00210 static const char allowedStatesInitializer[]; 00211 static const std::string ALLOWED_STATES; 00212 00213 00214 }; 00215 00216 00217 #endif 00218 00219 /****************************************************************************/ 00220