Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2010-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 MSSOTLWaveTrafficLightLogic.cpp 15 : /// @author Riccardo Belletti 16 : /// @author Anna Chiara Bellini 17 : /// @date Sep 2013 18 : /// 19 : // The class for SOTL Platoon logics 20 : /****************************************************************************/ 21 : 22 : #include "MSSOTLWaveTrafficLightLogic.h" 23 : 24 32 : MSSOTLWaveTrafficLightLogic::MSSOTLWaveTrafficLightLogic( 25 : MSTLLogicControl& tlcontrol, const std::string& id, 26 : const std::string& programID, const Phases& phases, int step, 27 : SUMOTime delay, 28 32 : const Parameterised::Map& parameters) : 29 : MSSOTLTrafficLightLogic(tlcontrol, id, programID, TrafficLightType::SOTL_WAVE, phases, step, delay, 30 32 : parameters) { 31 64 : MsgHandler::getMessageInstance()->inform( 32 32 : "*** Intersection " + id 33 64 : + " will run using MSSOTLWaveTrafficLightLogic ***"); 34 : //sets the lastDuration of every phase to the same value as the default duration of that phase 35 224 : for (int i = 0; i < getPhaseNumber(); i++) { 36 192 : (*myPhases[i]).lastDuration = (*myPhases[i]).duration; 37 : } 38 32 : } 39 : 40 0 : MSSOTLWaveTrafficLightLogic::MSSOTLWaveTrafficLightLogic( 41 : MSTLLogicControl& tlcontrol, const std::string& id, 42 : const std::string& programID, const Phases& phases, int step, 43 : SUMOTime delay, const Parameterised::Map& parameters, 44 0 : MSSOTLSensors* sensors) : 45 : MSSOTLTrafficLightLogic(tlcontrol, id, programID, TrafficLightType::SOTL_WAVE, phases, step, delay, 46 0 : parameters, sensors) { 47 : //sets the lastDuration of every phase to the same value as the default duration of that phase 48 0 : for (int i = 0; i < getPhaseNumber(); i++) { 49 0 : (*myPhases[i]).lastDuration = (*myPhases[i]).duration; 50 : } 51 0 : } 52 : 53 29350 : bool MSSOTLWaveTrafficLightLogic::canRelease() { 54 : 55 : //10% of lastDuration 56 29350 : SUMOTime delta = 10 * getCurrentPhaseDef().lastDuration / 100; 57 : 58 : //this allows a minimum variation of +-1s 59 29350 : if (delta < 1000) { 60 : delta = 1000; 61 : } 62 29350 : if (getCurrentPhaseElapsed() >= getCurrentPhaseDef().minDuration) { 63 21404 : if (getCurrentPhaseElapsed() 64 21404 : >= getCurrentPhaseDef().lastDuration - delta) { 65 3628 : if ((countVehicles() == 0) //no other vehicles approaching green lights 66 3328 : || (getCurrentPhaseElapsed() 67 3328 : >= getCurrentPhaseDef().lastDuration + delta) //maximum value of the window surrounding lastDuration 68 6756 : || (getCurrentPhaseElapsed() 69 3128 : >= getCurrentPhaseDef().maxDuration) //declared maximum duration has been reached 70 : ) { 71 : 72 738 : (*myPhases[getCurrentPhaseIndex()]).lastDuration = 73 738 : getCurrentPhaseElapsed(); 74 738 : return true; 75 : } 76 : } 77 : } 78 : return false; 79 : } 80 : 81 3628 : int MSSOTLWaveTrafficLightLogic::countVehicles() { 82 3628 : std::string state = getCurrentPhaseDef().getState(); 83 : int vehicles = 0; 84 18140 : for (int i = 0; i < (int)getLaneVectors().size(); i++) { 85 0 : if (i > 0 86 14512 : && ((getLaneVectors()[i][0]->getID()).compare( 87 10884 : getLaneVectors()[i - 1][0]->getID()) == 0)) { 88 0 : continue; 89 : } 90 14512 : if (state[i] != 'r') { 91 7256 : vehicles += getSensors()->countVehicles(getLaneVectors()[i][0]); 92 : } 93 : 94 : } 95 3628 : return vehicles; 96 : }