24 #include "../MSLane.h"
25 #include "../MSEdge.h"
35 const std::string&
id,
36 const std::string& programID,
41 const std::map<std::string, std::string>& parameters)
53 const std::string&
id,
54 const std::string& programID,
59 const std::map<std::string, std::string>& parameters,
71 for (std::vector<MSPushButton*>::iterator vIt = mapIt->second.begin(); vIt != mapIt->second.end(); ++vIt) {
75 for (
int i = 0; i < (int)
myPhases.size(); i++) {
90 for (
int step = 0; step < (int)
getPhases().size(); step++) {
99 for (
int phaseStep = 0; phaseStep < (int)
getPhases().size(); phaseStep++) {
110 for (
int step = 0; step < (int)
getPhases().size(); step++) {
143 for (
int i = 0; i < lvv.size(); i++) {
146 for (
int j = 0; j < lv.size(); j++) {
156 if (
getParameter(
"USE_VEHICLE_TYPES_WEIGHTS",
"0") ==
"1") {
173 for (
int i = 0; i < links.size(); i++) {
175 for (
int j = 0; j < oneLink.size(); j++) {
176 MSLane* lane = oneLink[j]->getLane();
186 for (
int i = 0; i < (int)links.size(); i++) {
188 for (
int j = 0; j < (int)oneLink.size(); j++) {
189 MSLane* lane = oneLink[j]->getLane();
190 outLanes.push_back(lane);
194 if (outLanes.size() > 0) {
195 myLaneVector.push_back(outLanes);
197 if (myLaneVector.size() > 0) {
209 std::map<int, SUMOTime>::iterator phaseIterator =
targetPhasesCTS.find(phaseStep);
211 phaseIterator->second = 0;
221 for (std::map<int, SUMOTime>::iterator mapIterator =
targetPhasesCTS.begin();
224 int chain = mapIterator->first;
225 SUMOTime oldVal = mapIterator->second;
235 mapIterator->second += elapsedTimeSteps
239 mapIterator->second += elapsedTimeSteps
246 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
248 std::ostringstream oss;
249 oss <<
"MSSOTLTrafficLightLogic::updateCTS->TLC " <<
getID() <<
" chain " << chain <<
" oldVal " << oldVal <<
" newVal " << mapIterator->second;
280 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
292 std::stringstream out;
302 std::ostringstream threshold_str;
315 std::ostringstream str;
324 for (std::map<int, SUMOTime>::const_iterator iterator =
329 std::ostringstream threshold_str;
333 <<
";" << iterator->second <<
";" <<
getPhase(iterator->first).
getState() <<
";"
364 bool usedMaxCTS =
false;
365 std::vector<int> equalIndexes;
369 if (maxLastStep < it->second) {
370 maxLastStep = it->second;
371 equalIndexes.clear();
372 equalIndexes.push_back(it->first);
373 }
else if (maxLastStep == it->second) {
374 equalIndexes.push_back(it->first);
378 if (equalIndexes.size() == 0) {
380 for (std::map<int, SUMOTime>::const_iterator iterator =
targetPhasesCTS.begin();
383 if (maxCTS < iterator->second) {
384 maxCTS = iterator->second;
385 equalIndexes.clear();
386 equalIndexes.push_back(iterator->first);
387 }
else if (maxCTS == iterator->second) {
388 equalIndexes.push_back(iterator->first);
394 std::ostringstream oss;
395 oss <<
"MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS-> TLC " <<
getID();
397 oss <<
" maxCTS " << maxCTS;
399 oss <<
" forcing selection since not selected for " << maxLastStep;
401 if (equalIndexes.size() == 1) {
402 oss <<
" phase " << equalIndexes[0];
404 return equalIndexes[0];
408 for (std::vector<int>::const_iterator it = equalIndexes.begin(); it != equalIndexes.end(); ++it) {
411 oss <<
"]. Random select " << index;
449 #ifdef ANALYSIS_DEBUG
470 std::ostringstream oss;
471 oss <<
"Forced selection of the phase " <<
lastChain <<
" since its last selection was " << it->second <<
" changes ago";
475 }
else if (it->first != previousStep) {
490 #ifdef ANALYSIS_DEBUG
491 std::ostringstream oss;
#define WRITE_MESSAGE(msg)
std::string time2string(SUMOTime t)
convert SUMOTime to string
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
A fixed traffic light logic.
Phases myPhases
The list of phases this logic uses.
const Phases & getPhases() const
Returns the phases of this tls program.
int getCurrentPhaseIndex() const
Returns the current index within the program.
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
void setStep(int step)
Forces a specific step.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
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
~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)
MSSOTLTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const TrafficLightType logicType, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > ¶meters)
Constructor without sensors passed.
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()
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 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.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
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)