SUMO - Simulation of Urban MObility
MSSOTLWaveTrafficLightLogic.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // The class for SOTL Platoon logics
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright 2001-2009 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
23 
25  MSTLLogicControl& tlcontrol, const std::string& id,
26  const std::string& subid, const Phases& phases, int step,
27  SUMOTime delay,
28  const std::map<std::string, std::string>& parameters) throw() :
29  MSSOTLTrafficLightLogic(tlcontrol, id, subid, phases, step, delay,
30  parameters) {
32  "*** Intersection " + id
33  + " will run using MSSOTLWaveTrafficLightLogic ***");
34  //sets the lastDuration of every phase to the same value as the default duration of that phase
35  for (int i = 0; i < getPhaseNumber(); i++) {
36  (*myPhases[i]).lastDuration = (*myPhases[i]).duration;
37  }
38 }
39 
41  MSTLLogicControl& tlcontrol, const std::string& id,
42  const std::string& subid, const Phases& phases, int step,
43  SUMOTime delay, const std::map<std::string, std::string>& parameters,
44  MSSOTLSensors* sensors) throw() :
45  MSSOTLTrafficLightLogic(tlcontrol, id, subid, phases, step, delay,
46  parameters, sensors) {
47  //sets the lastDuration of every phase to the same value as the default duration of that phase
48  for (int i = 0; i < getPhaseNumber(); i++) {
49  (*myPhases[i]).lastDuration = (*myPhases[i]).duration;
50  }
51 }
52 
54 
55  //10% of lastDuration
56  SUMOTime delta = 10 * getCurrentPhaseDef().lastDuration / 100;
57 
58  //this allows a minimum variation of +-1s
59  if (delta < 1000) {
60  delta = 1000;
61  }
62  if (getCurrentPhaseElapsed() >= getCurrentPhaseDef().minDuration) {
64  >= getCurrentPhaseDef().lastDuration - delta) {
65  if ((countVehicles() == 0) //no other vehicles approaching green lights
67  >= getCurrentPhaseDef().lastDuration + delta) //maximum value of the window surrounding lastDuration
69  >= getCurrentPhaseDef().maxDuration) //declared maximum duration has been reached
70  ) {
71 
72  (*myPhases[getCurrentPhaseIndex()]).lastDuration =
74  return true;
75  }
76  }
77  }
78  return false;
79 }
80 
82  std::string state = getCurrentPhaseDef().getState();
83  int vehicles = 0;
84  for (int i = 0; i < (int)getLaneVectors().size(); i++) {
85  if (i > 0
86  && ((getLaneVectors()[i][0]->getID()).compare(
87  getLaneVectors()[i - 1][0]->getID()) == 0)) {
88  continue;
89  }
90  if (state[i] != 'r') {
91  vehicles += getSensors()->countVehicles(getLaneVectors()[i][0]);
92  }
93 
94  }
95  return vehicles;
96 }
const std::string & getState() const
Returns the state within this phase.
long long int SUMOTime
Definition: SUMOTime.h:43
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
MSSOTLWaveTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &subid, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > &parameters)
Constructor without sensors passed.
A class that stores and controls tls and switching of their programs.
A self-organizing traffic light logic.
Phases myPhases
The list of phases this logic uses.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:62
virtual int countVehicles(MSLane *lane)=0
SUMOTime lastDuration
The previous duration of the phase.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
int getCurrentPhaseIndex() const
Returns the current index within the program.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89