 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
20 #include "../MSLane.h"
21 #include "../MSEdge.h"
25 #define ANALYSIS_DBG(X) {X}
27 #define ANALYSIS_DBG(X) DBG(X)
34 const std::string&
id,
35 const std::string& programID,
40 const std::map<std::string, std::string>& parameters)
52 const std::string&
id,
53 const std::string& programID,
58 const std::map<std::string, std::string>& parameters,
70 for (std::vector<MSPushButton*>::iterator vIt = mapIt->second.begin(); vIt != mapIt->second.end(); ++vIt) {
74 for (
int i = 0; i < (int)
myPhases.size(); i++) {
89 for (
int step = 0; step < (int)
getPhases().size(); step++) {
98 for (
int phaseStep = 0; phaseStep < (int)
getPhases().size(); phaseStep++) {
109 for (
int step = 0; step < (int)
getPhases().size(); step++) {
142 for (
int i = 0; i < lvv.size(); i++) {
145 for (
int j = 0; j < lv.size(); j++) {
155 if (
getParameter(
"USE_VEHICLE_TYPES_WEIGHTS",
"0") ==
"1") {
173 for (
int i = 0; i <
myLinks.size(); i++) {
176 for (
int j = 0; j < oneLink.size(); j++) {
178 MSLane* lane = oneLink[j]->getLane();
191 for (
int i = 0; i < (int)
myLinks.size(); i++) {
193 for (
int j = 0; j < (int)oneLink.size(); j++) {
194 MSLane* lane = oneLink[j]->getLane();
195 outLanes.push_back(lane);
199 if (outLanes.size() > 0) {
200 myLaneVector.push_back(outLanes);
202 if (myLaneVector.size() > 0) {
214 std::map<int, SUMOTime>::iterator phaseIterator =
targetPhasesCTS.find(phaseStep);
216 phaseIterator->second = 0;
226 for (std::map<int, SUMOTime>::iterator mapIterator =
targetPhasesCTS.begin();
229 int chain = mapIterator->first;
230 SUMOTime oldVal = mapIterator->second;
240 mapIterator->second += elapsedTimeSteps
244 mapIterator->second += elapsedTimeSteps
251 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
253 std::ostringstream oss;
254 oss <<
"MSSOTLTrafficLightLogic::updateCTS->TLC " <<
getID() <<
" chain " << chain <<
" oldVal " << oldVal <<
" newVal " << mapIterator->second;
273 for (MSPhaseDefinition::LaneIdVector::const_iterator laneIterator = targetLanes.begin(); laneIterator != targetLanes.end(); laneIterator++) {
286 WRITE_ERROR(
"Unrecognized traffic threshold calculation mode");
299 std::stringstream out;
310 std::ostringstream threshold_str;
323 std::ostringstream str;
332 for (std::map<int, SUMOTime>::const_iterator iterator =
337 std::ostringstream threshold_str;
341 <<
";" << iterator->second <<
";" <<
getPhase(iterator->first).
getState() <<
";"
372 bool usedMaxCTS =
false;
373 std::vector<int> equalIndexes;
377 if (maxLastStep < it->second) {
378 maxLastStep = it->second;
379 equalIndexes.clear();
380 equalIndexes.push_back(it->first);
381 }
else if (maxLastStep == it->second) {
382 equalIndexes.push_back(it->first);
386 if (equalIndexes.size() == 0) {
388 for (std::map<int, SUMOTime>::const_iterator iterator =
targetPhasesCTS.begin();
391 if (maxCTS < iterator->second) {
392 maxCTS = iterator->second;
393 equalIndexes.clear();
394 equalIndexes.push_back(iterator->first);
395 }
else if (maxCTS == iterator->second) {
396 equalIndexes.push_back(iterator->first);
402 std::ostringstream oss;
403 oss <<
"MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS-> TLC " <<
getID();
405 oss <<
" maxCTS " << maxCTS;
407 oss <<
" forcing selection since not selected for " << maxLastStep;
409 if (equalIndexes.size() == 1) {
410 oss <<
" phase " << equalIndexes[0];
412 return equalIndexes[0];
416 for (std::vector<int>::const_iterator it = equalIndexes.begin(); it != equalIndexes.end(); ++it) {
419 oss <<
"]. Random select " << index;
476 std::ostringstream oss;
477 oss <<
"Forced selection of the phase " <<
lastChain <<
" since its last selection was " << it->second <<
" changes ago";
481 }
else if (it->first != previousStep) {
497 std::ostringstream oss;
int getTargetPhaseMaxLastSelection()
SUMOTime trySwitch()
Switches to the next phase.
MSSOTLSensors * mySensors
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
void buildCountSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
void resetCTS(int phaseStep)
void updateDecayThreshold()
Representation of a lane in the micro simulation.
virtual void stepChanged(int newStep)
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 ...
Phases myPhases
The list of phases this logic uses.
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
double getSpeedThreshold()
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
MSSOTLE2Sensors * myCountSensors
virtual bool canRelease()=0
std::vector< std::string > LaneIdVector
virtual int countVehicles(MSLane *lane)=0
double getOutputSensorsLength()
bool isPushButtonPressed()
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
void setStep(int step)
Forces a specific step.
double getInputSensorsLength()
bool isDecisional() const
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
virtual SUMOTime computeReturnTime()
~MSSOTLTrafficLightLogic()
Destructor.
bool isDecayThresholdActivated()
virtual int decideNextPhase()
const std::string & getState() const
Returns the state within this phase.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
double getDecayConstant()
std::string time2string(SUMOTime t)
static const T & getRandomFrom(const std::vector< T > &v, std::mt19937 *rng=0)
Returns a random element from the given vector.
const LaneIdVector & getTargetLaneSet() const
const Phases & getPhases() const
Returns the phases of this tls program.
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.
int getPhaseIndexWithMaxCTS()
int getCurrentPhaseIndex() const
Returns the current index within the program.
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
int countVehicles(MSPhaseDefinition phase)
std::map< int, SUMOTime > targetPhasesCTS
PhasePushButtons m_pushButtons
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
std::map< int, int > targetPhasesLastSelection
A class that stores and controls tls and switching of their programs.
std::map< int, SUMOTime > lastCheckForTargetPhase
The definition of a single phase of a tls logic.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
#define WRITE_MESSAGE(msg)
Builds detectors for microsim.
SUMOTime getCurrentPhaseElapsed()
void buildCountOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
A fixed traffic light logic.