24 #include "../MSLane.h" 25 #include "../MSEdge.h" 29 #define ANALYSIS_DBG(X) {X} 31 #define ANALYSIS_DBG(X) DBG(X) 38 const std::string&
id,
39 const std::string& subid,
43 const std::map<std::string, std::string>& parameters)
55 const std::string&
id,
56 const std::string& subid,
60 const std::map<std::string, std::string>& parameters,
72 for (std::vector<MSPushButton*>::iterator vIt = mapIt->second.begin(); vIt != mapIt->second.end(); ++vIt) {
76 for (
int i = 0; i < (int)
myPhases.size(); i++) {
91 for (
int step = 0; step < (int)
getPhases().size(); step++) {
100 for (
int phaseStep = 0; phaseStep < (int)
getPhases().size(); phaseStep++) {
111 for (
int step = 0; step < (int)
getPhases().size(); step++) {
144 for (
int i = 0; i < lvv.size(); i++) {
147 for (
int j = 0; j < lv.size(); j++) {
157 if (
getParameter(
"USE_VEHICLE_TYPES_WEIGHTS",
"0") ==
"1") {
175 for (
int i = 0; i < myLinks.size(); i++) {
178 for (
int j = 0; j < oneLink.size(); j++) {
180 MSLane* lane = oneLink[j]->getLane();
193 for (
int i = 0; i < (int)myLinks.size(); i++) {
195 for (
int j = 0; j < (int)oneLink.size(); j++) {
196 MSLane* lane = oneLink[j]->getLane();
197 outLanes.push_back(lane);
201 if (outLanes.size() > 0) {
202 myLaneVector.push_back(outLanes);
204 if (myLaneVector.size() > 0) {
216 std::map<int, SUMOTime>::iterator phaseIterator =
targetPhasesCTS.find(phaseStep);
218 phaseIterator->second = 0;
228 for (std::map<int, SUMOTime>::iterator mapIterator =
targetPhasesCTS.begin();
231 int chain = mapIterator->first;
232 SUMOTime oldVal = mapIterator->second;
237 lastCheckForTargetPhase[chain] = now;
242 mapIterator->second += elapsedTimeSteps
246 mapIterator->second += elapsedTimeSteps
253 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
255 std::ostringstream oss;
256 oss <<
"MSSOTLTrafficLightLogic::updateCTS->TLC " <<
getID() <<
" chain " << chain <<
" oldVal " << oldVal <<
" newVal " << mapIterator->second;
275 for (MSPhaseDefinition::LaneIdVector::const_iterator laneIterator = targetLanes.begin(); laneIterator != targetLanes.end(); laneIterator++) {
288 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
301 std::stringstream out;
312 std::ostringstream threshold_str;
325 std::ostringstream str;
334 for (std::map<int, SUMOTime>::const_iterator iterator =
339 std::ostringstream threshold_str;
343 <<
";" << iterator->second <<
";" <<
getPhase(iterator->first).
getState() <<
";" 374 bool usedMaxCTS =
false;
375 std::vector<int> equalIndexes;
379 if (maxLastStep < it->second) {
380 maxLastStep = it->second;
381 equalIndexes.clear();
382 equalIndexes.push_back(it->first);
383 }
else if (maxLastStep == it->second) {
384 equalIndexes.push_back(it->first);
388 if (equalIndexes.size() == 0) {
390 for (std::map<int, SUMOTime>::const_iterator iterator =
targetPhasesCTS.begin();
393 if (maxCTS < iterator->second) {
394 maxCTS = iterator->second;
395 equalIndexes.clear();
396 equalIndexes.push_back(iterator->first);
397 }
else if (maxCTS == iterator->second) {
398 equalIndexes.push_back(iterator->first);
404 std::ostringstream oss;
405 oss <<
"MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS-> TLC " <<
getID();
407 oss <<
" maxCTS " << maxCTS;
409 oss <<
" forcing selection since not selected for " << maxLastStep;
411 if (equalIndexes.size() == 1) {
412 oss <<
" phase " << equalIndexes[0];
414 return equalIndexes[0];
418 for (std::vector<int>::const_iterator it = equalIndexes.begin(); it != equalIndexes.end(); ++it) {
421 oss <<
"]. Random select " << index;
478 std::ostringstream oss;
479 oss <<
"Forced selection of the phase " <<
lastChain <<
" since its last selection was " << it->second <<
" changes ago";
483 }
else if (it->first != previousStep) {
499 std::ostringstream oss;
static const T & getRandomFrom(const std::vector< T > &v)
Returns a random element from the given vector.
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.
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.
static double rand()
Returns a random real number in [0, 1)
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.
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
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.
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
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)