24 #include "../MSLane.h" 25 #include "../MSEdge.h" 28 #ifdef CHECK_MEMORY_LEAKS 30 #endif // CHECK_MEMORY_LEAKS 33 #define ANALYSIS_DBG(X) {X} 35 #define ANALYSIS_DBG(X) DBG(X) 42 const std::string&
id,
43 const std::string& subid,
47 const std::map<std::string, std::string>& parameters)
59 const std::string&
id,
60 const std::string& subid,
64 const std::map<std::string, std::string>& parameters,
76 for (std::vector<MSPushButton*>::iterator vIt = mapIt->second.begin(); vIt != mapIt->second.end(); ++vIt) {
80 for (
int i = 0; i < (int)
myPhases.size(); i++) {
95 for (
int step = 0; step < (int)
getPhases().size(); step++) {
104 for (
int phaseStep = 0; phaseStep < (int)
getPhases().size(); phaseStep++) {
115 for (
int step = 0; step < (int)
getPhases().size(); step++) {
148 for (
int i = 0; i < lvv.size(); i++) {
151 for (
int j = 0; j < lv.size(); j++) {
161 if (
getParameter(
"USE_VEHICLE_TYPES_WEIGHTS",
"0") ==
"1") {
179 for (
int i = 0; i < myLinks.size(); i++) {
182 for (
int j = 0; j < oneLink.size(); j++) {
184 MSLane* lane = oneLink[j]->getLane();
197 for (
int i = 0; i < (int)myLinks.size(); i++) {
199 for (
int j = 0; j < (int)oneLink.size(); j++) {
200 MSLane* lane = oneLink[j]->getLane();
201 outLanes.push_back(lane);
205 if (outLanes.size() > 0) {
206 myLaneVector.push_back(outLanes);
208 if (myLaneVector.size() > 0) {
220 std::map<int, SUMOTime>::iterator phaseIterator =
targetPhasesCTS.find(phaseStep);
222 phaseIterator->second = 0;
232 for (std::map<int, SUMOTime>::iterator mapIterator =
targetPhasesCTS.begin();
235 int chain = mapIterator->first;
236 SUMOTime oldVal = mapIterator->second;
241 lastCheckForTargetPhase[chain] = now;
246 mapIterator->second += elapsedTimeSteps
250 mapIterator->second += elapsedTimeSteps
257 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
259 std::ostringstream oss;
260 oss <<
"MSSOTLTrafficLightLogic::updateCTS->TLC " <<
getID() <<
" chain " << chain <<
" oldVal " << oldVal <<
" newVal " << mapIterator->second;
279 for (MSPhaseDefinition::LaneIdVector::const_iterator laneIterator = targetLanes.begin(); laneIterator != targetLanes.end(); laneIterator++) {
292 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
305 std::stringstream out;
316 std::ostringstream threshold_str;
329 std::ostringstream str;
338 for (std::map<int, SUMOTime>::const_iterator iterator =
343 std::ostringstream threshold_str;
347 <<
";" << iterator->second <<
";" <<
getPhase(iterator->first).
getState() <<
";" 378 bool usedMaxCTS =
false;
379 std::vector<int> equalIndexes;
383 if (maxLastStep < it->second) {
384 maxLastStep = it->second;
385 equalIndexes.clear();
386 equalIndexes.push_back(it->first);
387 }
else if (maxLastStep == it->second) {
388 equalIndexes.push_back(it->first);
392 if (equalIndexes.size() == 0) {
394 for (std::map<int, SUMOTime>::const_iterator iterator =
targetPhasesCTS.begin();
397 if (maxCTS < iterator->second) {
398 maxCTS = iterator->second;
399 equalIndexes.clear();
400 equalIndexes.push_back(iterator->first);
401 }
else if (maxCTS == iterator->second) {
402 equalIndexes.push_back(iterator->first);
408 std::ostringstream oss;
409 oss <<
"MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS-> TLC " <<
getID();
411 oss <<
" maxCTS " << maxCTS;
413 oss <<
" forcing selection since not selected for " << maxLastStep;
415 if (equalIndexes.size() == 1) {
416 oss <<
" phase " << equalIndexes[0];
418 return equalIndexes[0];
422 for (std::vector<int>::const_iterator it = equalIndexes.begin(); it != equalIndexes.end(); ++it) {
425 oss <<
"]. Random select " << index;
482 std::ostringstream oss;
483 oss <<
"Forced selection of the phase " <<
lastChain <<
" since its last selection was " << it->second <<
" changes ago";
487 }
else if (it->first != previousStep) {
503 std::ostringstream oss;
static const T & getRandomFrom(const std::vector< T > &v)
Returns a random element from the given vector.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Builds detectors for microsim.
const std::string & getState() const
Returns the state within this phase.
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
static SUMOReal rand()
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).
std::map< int, SUMOTime > lastCheckForTargetPhase
SUMOReal getOutputSensorsLength()
bool isDecayThresholdActivated()
virtual int decideNextPhase()
void buildCountOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
int getPhaseIndexWithMaxCTS()
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.
const std::string & getID() const
Returns the id.
MSSOTLSensors * mySensors
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
int getCurrentPhaseIndex() const
Returns the current index within the program.
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)
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
PhasePushButtons m_pushButtons
SUMOReal getInputSensorsLength()
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
virtual int countVehicles(MSLane *lane)=0
std::vector< MSLink * > LinkVector
Definition of the list of links that participate in this tl-light.
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.
const LaneIdVector & getTargetLaneSet() const
std::string myID
The name of the object.
std::vector< MSLane * > LaneVector
Definition of the list of links that participate in this tl-light.
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of links that do have the same attribute.
~MSSOTLTrafficLightLogic()
Destructor.
SUMOTime getCurrentPhaseElapsed()
std::vector< std::string > LaneIdVector
SUMOReal getSpeedThreshold()
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 ...
SUMOReal getDecayConstant()
SUMOTime trySwitch()
Switches to the next phase.
void inform(std::string msg, bool addType=true)
adds a new error to the list
const Phases & getPhases() const
Returns the phases of this tls program.
virtual SUMOTime computeReturnTime()
int getTargetPhaseMaxLastSelection()
virtual bool canRelease()=0
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()
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
bool isDecisional() const
void setStep(int step)
Forces a specific step.
MSSOTLE2Sensors * myCountSensors
std::map< int, int > targetPhasesLastSelection
int countVehicles(MSPhaseDefinition phase)