23 #include "../MSLane.h" 24 #include "../MSEdge.h" 28 #define ANALYSIS_DBG(X) {X} 30 #define ANALYSIS_DBG(X) DBG(X) 37 const std::string&
id,
38 const std::string& subid,
42 const std::map<std::string, std::string>& parameters)
54 const std::string&
id,
55 const std::string& subid,
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") {
174 for (
int i = 0; i < myLinks.size(); i++) {
177 for (
int j = 0; j < oneLink.size(); j++) {
179 MSLane* lane = oneLink[j]->getLane();
192 for (
int i = 0; i < (int)myLinks.size(); i++) {
194 for (
int j = 0; j < (int)oneLink.size(); j++) {
195 MSLane* lane = oneLink[j]->getLane();
196 outLanes.push_back(lane);
200 if (outLanes.size() > 0) {
201 myLaneVector.push_back(outLanes);
203 if (myLaneVector.size() > 0) {
215 std::map<int, SUMOTime>::iterator phaseIterator =
targetPhasesCTS.find(phaseStep);
217 phaseIterator->second = 0;
227 for (std::map<int, SUMOTime>::iterator mapIterator =
targetPhasesCTS.begin();
230 int chain = mapIterator->first;
231 SUMOTime oldVal = mapIterator->second;
236 lastCheckForTargetPhase[chain] = now;
241 mapIterator->second += elapsedTimeSteps
245 mapIterator->second += elapsedTimeSteps
252 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
254 std::ostringstream oss;
255 oss <<
"MSSOTLTrafficLightLogic::updateCTS->TLC " <<
getID() <<
" chain " << chain <<
" oldVal " << oldVal <<
" newVal " << mapIterator->second;
274 for (MSPhaseDefinition::LaneIdVector::const_iterator laneIterator = targetLanes.begin(); laneIterator != targetLanes.end(); laneIterator++) {
287 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
300 std::stringstream out;
311 std::ostringstream threshold_str;
324 std::ostringstream str;
333 for (std::map<int, SUMOTime>::const_iterator iterator =
338 std::ostringstream threshold_str;
342 <<
";" << iterator->second <<
";" <<
getPhase(iterator->first).
getState() <<
";" 373 bool usedMaxCTS =
false;
374 std::vector<int> equalIndexes;
378 if (maxLastStep < it->second) {
379 maxLastStep = it->second;
380 equalIndexes.clear();
381 equalIndexes.push_back(it->first);
382 }
else if (maxLastStep == it->second) {
383 equalIndexes.push_back(it->first);
387 if (equalIndexes.size() == 0) {
389 for (std::map<int, SUMOTime>::const_iterator iterator =
targetPhasesCTS.begin();
392 if (maxCTS < iterator->second) {
393 maxCTS = iterator->second;
394 equalIndexes.clear();
395 equalIndexes.push_back(iterator->first);
396 }
else if (maxCTS == iterator->second) {
397 equalIndexes.push_back(iterator->first);
403 std::ostringstream oss;
404 oss <<
"MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS-> TLC " <<
getID();
406 oss <<
" maxCTS " << maxCTS;
408 oss <<
" forcing selection since not selected for " << maxLastStep;
410 if (equalIndexes.size() == 1) {
411 oss <<
" phase " << equalIndexes[0];
413 return equalIndexes[0];
417 for (std::vector<int>::const_iterator it = equalIndexes.begin(); it != equalIndexes.end(); ++it) {
420 oss <<
"]. Random select " << index;
477 std::ostringstream oss;
478 oss <<
"Forced selection of the phase " <<
lastChain <<
" since its last selection was " << it->second <<
" changes ago";
482 }
else if (it->first != previousStep) {
498 std::ostringstream oss;
const std::string & getState() const
Returns the state within this phase.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Builds detectors for microsim.
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
std::string time2string(SUMOTime t)
void resetCTS(int phaseStep)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
std::map< int, SUMOTime > lastCheckForTargetPhase
const std::string & getID() const
Returns the id.
bool isDecayThresholdActivated()
virtual int decideNextPhase()
void buildCountOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
int getPhaseIndexWithMaxCTS()
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index...
A class that stores and controls tls and switching of their programs.
MSSOTLSensors * mySensors
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
Phases myPhases
The list of phases this logic uses.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
std::map< int, SUMOTime > targetPhasesCTS
void buildCountSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
double getInputSensorsLength()
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
double getOutputSensorsLength()
PhasePushButtons m_pushButtons
double getDecayConstant()
virtual int countVehicles(MSLane *lane)=0
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
void updateDecayThreshold()
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index...
MSSOTLTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &subid, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > ¶meters)
Constructor without sensors passed.
std::string myID
The name of the object.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
~MSSOTLTrafficLightLogic()
Destructor.
SUMOTime getCurrentPhaseElapsed()
std::vector< std::string > LaneIdVector
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
static const T & getRandomFrom(const std::vector< T > &v, std::mt19937 *rng=0)
Returns a random element from the given vector.
int getCurrentPhaseIndex() const
Returns the current index within the program.
void buildSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
This function member has to be extended to properly build sensors for the input lanes Sensors has to ...
SUMOTime trySwitch()
Switches to the next phase.
const Phases & getPhases() const
Returns the phases of this tls program.
void inform(std::string msg, bool addType=true)
adds a new error to the list
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
double getSpeedThreshold()
virtual SUMOTime computeReturnTime()
int getTargetPhaseMaxLastSelection()
virtual bool canRelease()=0
const LaneIdVector & getTargetLaneSet() const
virtual void stepChanged(int newStep)
A fixed traffic light logic.
#define WRITE_MESSAGE(msg)
The definition of a single phase of a tls logic.
Representation of a lane in the micro simulation.
bool isPushButtonPressed()
void setStep(int step)
Forces a specific step.
bool isDecisional() const
MSSOTLE2Sensors * myCountSensors
std::map< int, int > targetPhasesLastSelection
int countVehicles(MSPhaseDefinition phase)