Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file MSOffTrafficLightLogic.h 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @author Michael Behrisch 18 : /// @date 08.05.2007 19 : /// 20 : // A traffic lights logic which represents a tls in an off-mode 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : 25 : #include <utility> 26 : #include <vector> 27 : #include <bitset> 28 : #include <utils/common/StdDefs.h> 29 : #include "MSTLLogicControl.h" 30 : #include "MSTrafficLightLogic.h" 31 : 32 : 33 : // =========================================================================== 34 : // class definitions 35 : // =========================================================================== 36 : /** 37 : * @class MSOffTrafficLightLogic 38 : * @brief A traffic lights logic which represents a tls in an off-mode 39 : */ 40 : class MSOffTrafficLightLogic : public MSTrafficLightLogic { 41 : public: 42 : /** @brief Constructor 43 : * @param[in] tlcontrol The tls control responsible for this tls 44 : * @param[in] id This tls' id 45 : * The sub-id is always "off". 46 : */ 47 : MSOffTrafficLightLogic(MSTLLogicControl& tlcontrol, 48 : const std::string& id); 49 : 50 : 51 : /** @brief Initialises the tls with information about incoming lanes 52 : * @param[in] nb The detector builder 53 : * @param[in] edgeContinuations Information about edge predecessors/successors 54 : */ 55 : virtual void init(NLDetectorBuilder& nb); 56 : 57 : 58 : /// @brief Destructor 59 : ~MSOffTrafficLightLogic(); 60 : 61 : 62 : /// @name Handling of controlled links 63 : /// @{ 64 : 65 : /** @brief Applies information about controlled links and lanes from the given logic 66 : * @param[in] logic The logic to use the information about controlled links/lanes from 67 : * @see MSTrafficLightLogic::adaptLinkInformationFrom 68 : */ 69 : void adaptLinkInformationFrom(const MSTrafficLightLogic& logic); 70 : /// @} 71 : 72 : 73 : 74 : /// @name Switching and setting current rows 75 : /// @{ 76 : 77 : /** @brief Switches to the next phase 78 : * @return The time of the next switch (always 120) 79 : * @see MSTrafficLightLogic::trySwitch 80 : */ 81 1805 : SUMOTime trySwitch() { 82 1805 : return 120 * DELTA_T; 83 : } 84 : 85 : /// @} 86 : 87 : 88 : /// @name Static Information Retrieval 89 : /// @{ 90 : 91 : /** @brief Returns the number of phases 92 : * @return The number of this tls program's phases 93 : * @see MSTrafficLightLogic::getPhaseNumber 94 : */ 95 : int getPhaseNumber() const; 96 : 97 : 98 : /** @brief Returns the phases of this tls program 99 : * @return The phases of this tls program 100 : * @see MSTrafficLightLogic::getPhases 101 : */ 102 : const Phases& getPhases() const; 103 : 104 : 105 : /** @brief Returns the definition of the phase from the given position within the plan 106 : * @param[in] givenstep The index of the phase within the plan 107 : * @return The definition of the phase at the given position 108 : * @see MSTrafficLightLogic::getPhase 109 : */ 110 : const MSPhaseDefinition& getPhase(int givenstep) const; 111 : 112 : /** @brief Returns the type of the logic as a string 113 : * @return The type of the logic 114 : */ 115 : const std::string getLogicType() const { 116 : return "offTrafficLightLogic"; 117 : } 118 : /// @} 119 : 120 : 121 : 122 : /// @name Dynamic Information Retrieval 123 : /// @{ 124 : 125 : /** @brief Returns the current index within the program 126 : * @return The index of the current phase within the tls 127 : * @see MSTrafficLightLogic::getCurrentPhaseIndex 128 : */ 129 : int getCurrentPhaseIndex() const; 130 : 131 : 132 : /** @brief Returns the definition of the current phase 133 : * @return The current phase 134 : * @see MSTrafficLightLogic::getCurrentPhaseDef 135 : */ 136 : const MSPhaseDefinition& getCurrentPhaseDef() const; 137 : /// @} 138 : 139 : 140 : 141 : /// @name Conversion between time and phase 142 : /// @{ 143 : 144 : /** @brief Returns the index of the logic at the given simulation step 145 : * @return The (estimated) index of the tls at the given simulation time step 146 : * @see MSTrafficLightLogic::getPhaseIndexAtTime 147 : */ 148 : SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const; 149 : 150 : 151 : /** @brief Returns the position (start of a phase during a cycle) from of a given step 152 : * @param[in] index The index of the phase to return the begin of 153 : * @return The begin time of the phase 154 : * @see MSTrafficLightLogic::getOffsetFromIndex 155 : */ 156 : SUMOTime getOffsetFromIndex(int index) const; 157 : 158 : 159 : /** @brief Returns the step (the phasenumber) of a given position of the cycle 160 : * @param[in] offset The offset (time) for which the according phase shall be returned 161 : * @return The according phase 162 : * @see MSTrafficLightLogic::getIndexFromOffset 163 : */ 164 : int getIndexFromOffset(SUMOTime offset) const; 165 : /// @} 166 : 167 : 168 : 169 : /// @name Changing phases and phase durations 170 : /// @{ 171 : 172 : /** @brief Changes the current phase and her duration 173 : * @param[in] tlcontrol The responsible traffic lights control 174 : * @param[in] simStep The current simulation step 175 : * @param[in] step Index of the phase to use 176 : * @param[in] stepDuration The left duration of the phase 177 : * @see MSTrafficLightLogic::changeStepAndDuration 178 : */ 179 0 : void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration) { 180 : UNUSED_PARAMETER(tlcontrol); 181 : UNUSED_PARAMETER(simStep); 182 : UNUSED_PARAMETER(step); 183 : UNUSED_PARAMETER(stepDuration); 184 0 : } 185 : /// @} 186 : 187 : 188 : private: 189 : /** @brief (Re)builds the internal phase definition 190 : */ 191 : void rebuildPhase(); 192 : 193 : 194 : private: 195 : /// @brief The phase definition (only one) 196 : MSTrafficLightLogic::Phases myPhaseDefinition; 197 : 198 : 199 : };