35 const std::string&
id,
36 const std::string& programID,
53 const std::string&
id,
54 const std::string& programID,
71 for (std::vector<MSPushButton*>::iterator vIt = mapIt->second.begin(); vIt != mapIt->second.end(); ++vIt) {
87 for (
int step = 0; step < (int)
getPhases().size(); step++) {
96 for (
int phaseStep = 0; phaseStep < (int)
getPhases().size(); phaseStep++) {
107 for (
int step = 0; step < (int)
getPhases().size(); step++) {
140 for (
int i = 0; i < lvv.size(); i++) {
143 for (
int j = 0; j < lv.size(); j++) {
153 if (
getParameter(
"USE_VEHICLE_TYPES_WEIGHTS",
"0") ==
"1") {
170 for (
int i = 0; i < links.size(); i++) {
172 for (
int j = 0; j < oneLink.size(); j++) {
173 MSLane* lane = oneLink[j]->getLane();
183 for (
int i = 0; i < (int)links.size(); i++) {
185 for (
int j = 0; j < (int)oneLink.size(); j++) {
186 MSLane* lane = oneLink[j]->getLane();
187 outLanes.push_back(lane);
191 if (outLanes.size() > 0) {
192 myLaneVector.push_back(outLanes);
194 if (myLaneVector.size() > 0) {
206 std::map<int, SUMOTime>::iterator phaseIterator =
targetPhasesCTS.find(phaseStep);
208 phaseIterator->second = 0;
218 for (std::map<int, SUMOTime>::iterator mapIterator =
targetPhasesCTS.begin();
221 int chain = mapIterator->first;
222 SUMOTime oldVal = mapIterator->second;
232 mapIterator->second += elapsedTimeSteps
236 mapIterator->second += elapsedTimeSteps
243 WRITE_ERROR(
TL(
"Unrecognized traffic threshold calculation mode"));
245 std::ostringstream oss;
246 oss <<
"MSSOTLTrafficLightLogic::updateCTS->TLC " <<
getID() <<
" chain " << chain <<
" oldVal " << oldVal <<
" newVal " << mapIterator->second;
277 WRITE_ERROR(
TL(
"Unrecognized traffic threshold calculation mode"));
289 std::stringstream out;
299 std::ostringstream threshold_str;
312 std::ostringstream str;
321 for (std::map<int, SUMOTime>::const_iterator iterator =
326 std::ostringstream threshold_str;
330 <<
";" << iterator->second <<
";" <<
getPhase(iterator->first).
getState() <<
";"
361 bool usedMaxCTS =
false;
362 std::vector<int> equalIndexes;
366 if (maxLastStep < it->second) {
367 maxLastStep = it->second;
368 equalIndexes.clear();
369 equalIndexes.push_back(it->first);
370 }
else if (maxLastStep == it->second) {
371 equalIndexes.push_back(it->first);
375 if (equalIndexes.size() == 0) {
377 for (std::map<int, SUMOTime>::const_iterator iterator =
targetPhasesCTS.begin();
380 if (maxCTS < iterator->second) {
381 maxCTS = iterator->second;
382 equalIndexes.clear();
383 equalIndexes.push_back(iterator->first);
384 }
else if (maxCTS == iterator->second) {
385 equalIndexes.push_back(iterator->first);
391 std::ostringstream oss;
392 oss <<
"MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS-> TLC " <<
getID();
394 oss <<
" maxCTS " << maxCTS;
396 oss <<
" forcing selection since not selected for " << maxLastStep;
398 if (equalIndexes.size() == 1) {
399 oss <<
" phase " << equalIndexes[0];
401 return equalIndexes[0];
405 for (std::vector<int>::const_iterator it = equalIndexes.begin(); it != equalIndexes.end(); ++it) {
408 oss <<
"]. Random select " << index;
446 #ifdef ANALYSIS_DEBUG
467 std::ostringstream oss;
468 oss <<
"Forced selection of the phase " <<
lastChain <<
" since its last selection was " << it->second <<
" changes ago";
472 }
else if (it->first != previousStep) {
487 #ifdef ANALYSIS_DEBUG
488 std::ostringstream oss;
#define WRITE_MESSAGE(msg)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Representation of a lane in the micro simulation.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
The definition of a single phase of a tls logic.
const std::string & getState() const
Returns the state within this phase.
const std::vector< std::string > & getTargetLaneSet() const
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
bool isDecisional() const
void buildCountOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
void buildCountSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
virtual void stepChanged(int newStep)
virtual int countVehicles(MSLane *lane)=0
std::map< int, SUMOTime > lastCheckForTargetPhase
void setStep(int step)
Forces a specific step.
~MSSOTLTrafficLightLogic()
Destructor.
int getPhaseIndexWithMaxCTS()
SUMOTime trySwitch()
Switches to the next phase.
MSSOTLE2Sensors * myCountSensors
double getOutputSensorsLength()
virtual bool canRelease()=0
double getDecayConstant()
double getSpeedThreshold()
int countVehicles(MSPhaseDefinition phase)
PhasePushButtons m_pushButtons
std::map< int, SUMOTime > targetPhasesCTS
virtual SUMOTime computeReturnTime()
std::map< int, int > targetPhasesLastSelection
void resetCTS(int phaseStep)
MSSOTLSensors * mySensors
void updateDecayThreshold()
bool isDecayThresholdActivated()
double getInputSensorsLength()
virtual int decideNextPhase()
int getTargetPhaseMaxLastSelection()
MSSOTLTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const TrafficLightType logicType, const Phases &phases, int step, SUMOTime delay, const Parameterised::Map ¶meters)
Constructor without sensors passed.
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
SUMOTime getCurrentPhaseElapsed()
bool isPushButtonPressed()
A fixed traffic light logic.
Phases myPhases
The list of phases this logic uses.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
int myStep
The current step.
int getCurrentPhaseIndex() const override
Returns the current index within the program.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const override
gets a parameter
const Phases & getPhases() const override
Returns the phases of this tls program.
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns the definition of the current phase.
A class that stores and controls tls and switching of their programs.
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Builds detectors for microsim.
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
std::map< std::string, std::string > Map
parameters map
static const T & getRandomFrom(const std::vector< T > &v, SumoRNG *rng=nullptr)
Returns a random element from the given vector.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)