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 151 : MSOffTrafficLightLogic::MSOffTrafficLightLogic(MSTLLogicControl& tlcontrol, const std::string& id) :
37 302 : MSTrafficLightLogic(tlcontrol, id, "off", 0, TrafficLightType::OFF, 0, Parameterised::Map()) {
38 151 : myDefaultCycleTime = TIME2STEPS(120);
39 151 : }
40 :
41 :
42 302 : MSOffTrafficLightLogic::~MSOffTrafficLightLogic() {
43 302 : for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) {
44 151 : delete *i;
45 : }
46 302 : }
47 :
48 :
49 : void
50 0 : MSOffTrafficLightLogic::init(NLDetectorBuilder&) {
51 0 : rebuildPhase();
52 0 : }
53 :
54 :
55 : // ----------- Handling of controlled links
56 : void
57 151 : MSOffTrafficLightLogic::adaptLinkInformationFrom(const MSTrafficLightLogic& logic) {
58 151 : MSTrafficLightLogic::adaptLinkInformationFrom(logic);
59 151 : rebuildPhase();
60 151 : }
61 :
62 :
63 : void
64 151 : MSOffTrafficLightLogic::rebuildPhase() {
65 151 : int no = (int)getLinks().size();
66 : std::string state;
67 2987 : for (int i = 0; i < no; ++i) {
68 : bool foundMajor = false;
69 : bool foundMinor = false;
70 : bool foundAllwayStop = false;
71 5672 : for (const MSLink* l : myLinks[i]) {
72 : /// @note. all links for the same index should have the same
73 : if (l->getOffState() == LINKSTATE_TL_OFF_BLINKING) {
74 : foundMinor = true;
75 : } else if (l->getOffState() == LINKSTATE_TL_OFF_NOSIGNAL) {
76 : foundMajor = true;
77 : } else if (l->getOffState() == LINKSTATE_ALLWAY_STOP) {
78 : foundAllwayStop = true;
79 : } else {
80 96 : WRITE_WARNINGF(TL("Invalid 'off'-state for link % at junction '%'"), toString(l->getIndex()), l->getJunction()->getID());
81 : }
82 : }
83 2836 : if (foundMajor && foundMinor) {
84 0 : WRITE_WARNINGF(TL("Inconsistent 'off'-states for linkIndex % at tlLogic '%'"), toString(i), getID());
85 : }
86 6142 : state += toString(foundAllwayStop ? LINKSTATE_ALLWAY_STOP : (foundMinor ? LINKSTATE_TL_OFF_BLINKING : LINKSTATE_TL_OFF_NOSIGNAL));
87 : }
88 151 : for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) {
89 0 : delete *i;
90 : }
91 : myPhaseDefinition.clear();
92 302 : myPhaseDefinition.push_back(new MSPhaseDefinition(TIME2STEPS(120), state));
93 151 : }
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 151 : MSOffTrafficLightLogic::getPhase(int) const {
111 151 : return *myPhaseDefinition[0];
112 : }
113 :
114 :
115 : // ------------ Dynamic Information Retrieval
116 : int
117 3684 : MSOffTrafficLightLogic::getCurrentPhaseIndex() const {
118 3684 : return 0;
119 : }
120 :
121 :
122 : const MSPhaseDefinition&
123 2921 : MSOffTrafficLightLogic::getCurrentPhaseDef() const {
124 2921 : 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 : /****************************************************************************/
|