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.cpp 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 : #include <config.h> 23 : 24 : #include <utility> 25 : #include <vector> 26 : #include <bitset> 27 : #include <sstream> 28 : #include <microsim/MSEventControl.h> 29 : #include "MSTrafficLightLogic.h" 30 : #include "MSOffTrafficLightLogic.h" 31 : 32 : 33 : // =========================================================================== 34 : // member method definitions 35 : // =========================================================================== 36 135 : MSOffTrafficLightLogic::MSOffTrafficLightLogic(MSTLLogicControl& tlcontrol, const std::string& id) : 37 270 : MSTrafficLightLogic(tlcontrol, id, "off", 0, TrafficLightType::OFF, 0, Parameterised::Map()) { 38 135 : myDefaultCycleTime = TIME2STEPS(120); 39 135 : } 40 : 41 : 42 270 : MSOffTrafficLightLogic::~MSOffTrafficLightLogic() { 43 270 : for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) { 44 135 : delete *i; 45 : } 46 270 : } 47 : 48 : 49 : void 50 0 : MSOffTrafficLightLogic::init(NLDetectorBuilder&) { 51 0 : rebuildPhase(); 52 0 : } 53 : 54 : 55 : // ----------- Handling of controlled links 56 : void 57 135 : MSOffTrafficLightLogic::adaptLinkInformationFrom(const MSTrafficLightLogic& logic) { 58 135 : MSTrafficLightLogic::adaptLinkInformationFrom(logic); 59 135 : rebuildPhase(); 60 135 : } 61 : 62 : 63 : void 64 135 : MSOffTrafficLightLogic::rebuildPhase() { 65 135 : int no = (int)getLinks().size(); 66 : std::string state; 67 2643 : for (int i = 0; i < no; ++i) { 68 : bool foundMajor = false; 69 : bool foundMinor = false; 70 : bool foundAllwayStop = false; 71 5016 : for (const MSLink* l : myLinks[i]) { 72 : /// @note. all links for the same index should have the same 73 2508 : if (l->getOffState() == LINKSTATE_TL_OFF_BLINKING) { 74 : foundMinor = true; 75 366 : } else if (l->getOffState() == LINKSTATE_TL_OFF_NOSIGNAL) { 76 : foundMajor = true; 77 72 : } else if (l->getOffState() == LINKSTATE_ALLWAY_STOP) { 78 : foundAllwayStop = true; 79 : } else { 80 120 : WRITE_WARNINGF(TL("Invalid 'off'-state for link % at junction '%'"), toString(l->getIndex()), l->getJunction()->getID()); 81 : } 82 : } 83 2508 : if (foundMajor && foundMinor) { 84 0 : WRITE_WARNINGF(TL("Inconsistent 'off'-states for linkIndex % at tlLogic '%'"), toString(i), getID()); 85 : } 86 5350 : state += toString(foundAllwayStop ? LINKSTATE_ALLWAY_STOP : (foundMinor ? LINKSTATE_TL_OFF_BLINKING : LINKSTATE_TL_OFF_NOSIGNAL)); 87 : } 88 135 : for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) { 89 0 : delete *i; 90 : } 91 135 : myPhaseDefinition.clear(); 92 135 : myPhaseDefinition.push_back(new MSPhaseDefinition(TIME2STEPS(120), state)); 93 135 : } 94 : 95 : 96 : // ------------ Static Information Retrieval 97 : int 98 0 : MSOffTrafficLightLogic::getPhaseNumber() const { 99 0 : return 0; 100 : } 101 : 102 : 103 : const MSOffTrafficLightLogic::Phases& 104 0 : MSOffTrafficLightLogic::getPhases() const { 105 0 : return myPhaseDefinition; 106 : } 107 : 108 : 109 : const MSPhaseDefinition& 110 135 : MSOffTrafficLightLogic::getPhase(int) const { 111 135 : return *myPhaseDefinition[0]; 112 : } 113 : 114 : 115 : // ------------ Dynamic Information Retrieval 116 : int 117 3622 : MSOffTrafficLightLogic::getCurrentPhaseIndex() const { 118 3622 : return 0; 119 : } 120 : 121 : 122 : const MSPhaseDefinition& 123 2911 : MSOffTrafficLightLogic::getCurrentPhaseDef() const { 124 2911 : return *myPhaseDefinition[0]; 125 : } 126 : 127 : 128 : // ------------ Conversion between time and phase 129 : SUMOTime 130 0 : MSOffTrafficLightLogic::getPhaseIndexAtTime(SUMOTime) const { 131 0 : return 0; 132 : } 133 : 134 : 135 : SUMOTime 136 0 : MSOffTrafficLightLogic::getOffsetFromIndex(int) const { 137 0 : return 0; 138 : } 139 : 140 : 141 : int 142 0 : MSOffTrafficLightLogic::getIndexFromOffset(SUMOTime) const { 143 0 : return 0; 144 : } 145 : 146 : 147 : /****************************************************************************/