1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2010-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file MSPhasedTrafficLightLogic.h 11 /// @author Daniel Krajzewicz 12 /// @date Sept 2002 13 /// @version $Id$ 14 /// 15 // The base class for traffic light logic with phases 16 /****************************************************************************/ 17 #ifndef MSPhasedTrafficLightLogic_h 18 #define MSPhasedTrafficLightLogic_h 19 20 21 // =========================================================================== 22 // included modules 23 // =========================================================================== 24 #include <config.h> 25 26 #include <utility> 27 #include <vector> 28 #include <bitset> 29 #include <microsim/MSEventControl.h> 30 #include <microsim/MSNet.h> 31 #include "MSTrafficLightLogic.h" 32 #include "MSPhaseDefinition.h" 33 34 35 // =========================================================================== 36 // class definitions 37 // =========================================================================== 38 /** 39 * @class MSPhasedTrafficLightLogic 40 * @brief A fixed traffic light logic 41 * 42 * The base class for a traffic light which switches between 43 * it's phases and sets the lights to red in between. 44 * Some functions are called with an information about the current step. This 45 * is needed as a single logic may be used by many junctions and so the current 46 * step is stored within them, not within methods. 47 */ 48 class MSPhasedTrafficLightLogic : public MSTrafficLightLogic { 49 public: 50 /** @brief Constructor 51 * @param[in] tlcontrol The tls control responsible for this tls 52 * @param[in] id This tls' id 53 * @param[in] programID This tls' sub-id (program id) 54 * @param[in] phases Definitions of the phases 55 * @param[in] step The initial phase index 56 * @param[in] delay The time to wait before the first switch 57 */ 58 MSPhasedTrafficLightLogic(MSTLLogicControl& tlcontrol, 59 const std::string& id, const std::string& programID, 60 const TrafficLightType logicType, 61 const Phases& phases, int step, SUMOTime delay, 62 const std::map<std::string, std::string>& parameters); 63 64 65 /// @brief Destructor 66 ~MSPhasedTrafficLightLogic(); 67 68 69 70 /// @name Switching and setting current rows 71 /// @{ 72 /// MEMBER FACTORIZED TO PARENT CLASS (MSTrafficLightLogic) 73 /** @brief Switches to the next phase 74 * @param[in] isActive Whether this program is the currently used one 75 * @return The time of the next switch 76 * @see MSTrafficLightLogic::trySwitch 77 */ 78 /* SUMOTime trySwitch(bool isActive);*/ 79 80 81 82 /// @name Static Information Retrieval 83 /// @{ 84 85 /** @brief Returns the number of phases 86 * @return The number of this tls program's phases 87 * @see MSTrafficLightLogic::getPhaseNumber 88 */ 89 int getPhaseNumber() const; 90 91 92 /** @brief Returns the phases of this tls program 93 * @return The phases of this tls program 94 * @see MSTrafficLightLogic::getPhases 95 */ 96 const Phases& getPhases() const; 97 98 /** @brief Returns the definition of the phase from the given position within the plan 99 * @param[in] givenstep The index of the phase within the plan 100 * @return The definition of the phase at the given position 101 * @see MSTrafficLightLogic::getPhase 102 */ 103 const MSPhaseDefinition& getPhase(int givenstep) const; 104 /// @} 105 106 107 108 /// @name Dynamic Information Retrieval 109 /// @{ 110 111 /** @brief Returns the current index within the program 112 * @return The index of the current phase within the tls 113 * @see MSTrafficLightLogic::getCurrentPhaseIndex 114 */ 115 int getCurrentPhaseIndex() const; 116 117 118 /** @brief Returns the definition of the current phase 119 * @return The current phase 120 * @see MSTrafficLightLogic::getCurrentPhaseDef 121 */ 122 const MSPhaseDefinition& getCurrentPhaseDef() const; 123 /// @} 124 125 126 127 /// @name Conversion between time and phase 128 /// @{ 129 130 /** @brief Returns the index of the logic at the given simulation step 131 * @return The (estimated) index of the tls at the given simulation time step 132 * @see MSTrafficLightLogic::getPhaseIndexAtTime 133 */ 134 SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const; 135 136 137 /** @brief Returns the position (start of a phase during a cycle) from of a given step 138 * @param[in] index The index of the phase to return the begin of 139 * @return The begin time of the phase 140 * @see MSTrafficLightLogic::getOffsetFromIndex 141 */ 142 SUMOTime getOffsetFromIndex(int index) const; 143 144 145 /** @brief Returns the step (the phasenumber) of a given position of the cycle 146 * @param[in] offset The offset (time) for which the according phase shall be returned 147 * @return The according phase 148 * @see MSTrafficLightLogic::getIndexFromOffset 149 */ 150 int getIndexFromOffset(SUMOTime offset) const; 151 /// @} 152 153 154 155 /// @name Changing phases and phase durations 156 /// @{ 157 158 /** @brief Changes the current phase and her duration 159 * @param[in] tlcontrol The responsible traffic lights control 160 * @param[in] simStep The current simulation step 161 * @param[in] step Index of the phase to use 162 * @param[in] stepDuration The left duration of the phase 163 * @see MSTrafficLightLogic::changeStepAndDuration 164 */ 165 void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep, 166 int step, SUMOTime stepDuration); 167 /// @} 168 169 /** @brief Replaces the phases and set the phase index 170 */ 171 void setPhases(const Phases& phases, int index); 172 /// @} 173 174 protected: 175 /// @brief The list of phases this logic uses 176 Phases myPhases; 177 178 /// @brief Proceed to the next step 179 void proceedToNextStep(); 180 181 /// @brief Forces a specific step 182 void setStep(int step); 183 184 private: 185 186 /// @brief frees memory responsibilities 187 void deletePhases(); 188 189 protected: 190 191 /// @brief The current step 192 int myStep; 193 194 195 196 }; 197 198 199 #endif 200 201 /****************************************************************************/ 202 203