22 const std::string& programID,
const Phases& phases,
int step,
23 SUMOTime delay,
const std::map<std::string, std::string>& parameters) :
43 "*** Intersection " +
getID()
44 +
" will run using MSDeterministicHiLevelTrafficLightLogic ***");
46 MSLane* currentLane =
nullptr;
47 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
49 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
50 laneVector->begin(); lane != laneVector->end(); lane++) {
51 currentLane = (*lane);
62 for (
int i = 0; i < (int)
myLinks.size(); i++) {
64 for (
int j = 0; j < (int)oneLink.size(); j++) {
65 currentLane = oneLink[j]->getLane();
100 double vSpeedInTot = 0;
101 for (MSLaneID_set::iterator laneIterator =
inputLanes.begin();
102 laneIterator !=
inputLanes.end(); laneIterator++) {
103 std::string laneId = *laneIterator;
106 vSpeedInTot += (13.89 - maxSpeed) * 10. / 13.89;
109 std::ostringstream i_str; i_str <<
" meanVehiclesSpeed " << maxSpeed <<
" inputLane " << laneId <<
" ID " <<
getID() <<
" .";
WRITE_MESSAGE(
time2string(
MSNet::getInstance()->getCurrentTimeStep()) +
" MSDeterministicHiLevelTrafficLightLogic::getMeanSpeedForInputLanes:: in" + i_str.str());)
118 double vSpeedOutTot = 0;
119 for (MSLaneID_set::iterator laneIterator =
outputLanes.begin();
120 laneIterator !=
outputLanes.end(); laneIterator++) {
121 std::string laneId = *laneIterator;
124 vSpeedOutTot += (13.89 - maxSpeed) * 10. / 13.89;
127 std::ostringstream i_str; i_str <<
" meanVehiclesSpeed " << maxSpeed <<
" outputLane " << laneId <<
" ID " <<
getID() <<
" .";
WRITE_MESSAGE(
time2string(
MSNet::getInstance()->getCurrentTimeStep()) +
" MSDeterministicHiLevelTrafficLightLogic::getMeanSpeedForOutputLanes:: out" + i_str.str());)
140 if (newPolicy != oldPolicy) {
143 std::ostringstream phero_str; phero_str <<
" (mean_vSpeed_in= " << mean_vSpeed_in <<
" ,mean_vSpeed_out= " << mean_vSpeed_out <<
" )";
WRITE_MESSAGE(
"TL " +
getID() +
" time " +
time2string(step) +
" Policy: " + newPolicy->
getName() + phero_str.str() +
" OldPolicy: " + oldPolicy->
getName() +
" id " +
getID() +
" .");)
152 double mean_vSpeed_in,
double mean_vSpeed_out) {
154 int index_maxStimulus = 0;
155 double maxStimulus = -1;
157 for (
int i = 0; i < (int)
getPolicies().size(); i++) {
158 double stimulus =
getPolicies()[i]->computeDesirability(mean_vSpeed_in,
160 if (stimulus > maxStimulus) {
161 maxStimulus = stimulus;
162 index_maxStimulus = i;
165 std::ostringstream so_str; so_str <<
" policy " <<
getPolicies()[i]->getName() <<
" stimulus " << stimulus;
WRITE_MESSAGE(
"MSDeterministicHiLevelTrafficLightLogic::choosePolicy::" + so_str.str());)
void choosePolicy(double mean_vSpeed_in, double mean_vSpeed_out)
void decidePolicy()
Decide the current policy according to pheromone levels The decision reflects on currentPolicy value...
MSLaneID_set inputLanes
This pheronome is an indicator of congestion on input lanes. Its levels refer to the average speed of...
MSSOTLSensors * getSensors()
const std::string & getState() const
Returns the state within this phase.
Builds detectors for microsim.
Class for low-level platoon policy.
std::string time2string(SUMOTime t)
Class for low-level marching policy.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
void init(NLDetectorBuilder &nb)
Initialises the tls.
virtual int decideNextPhase(SUMOTime elapsed, const MSPhaseDefinition *stage, int currentPhaseIndex, int phaseMaxCTS, bool thresholdPassed, bool pushButtonPressed, int vehicleCount)
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
const std::string & getID() const
Returns the id.
~MSDeterministicHiLevelTrafficLightLogic()
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.
virtual bool canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed, const MSPhaseDefinition *stage, int vehicleCount)=0
A self-organizing high-level traffic light logic.
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.
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
std::vector< MSSOTLPolicy * > & getPolicies()
Returns the vector of the low-level policies used by this high-level tll.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
double getMeanSpeedForOutputLanes()
MSLaneID_set outputLanes
This pheromone is an indicator of congestion on output lanes. Its levels refer to the average speed o...
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
MSSOTLPolicy * getCurrentPolicy()
Returns the low-level policy currently selected by this high-level tll.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
virtual double meanVehiclesSpeed(MSLane *lane)=0
double getMeanSpeedForInputLanes()
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index...
SUMOTime getCurrentPhaseElapsed()
void activate(MSSOTLPolicy *policy)
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
int getCurrentPhaseIndex() const
Returns the current index within the program.
Class for low-level phase policy.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Class for a low-level policy.
Class for low-level congestion policy.
#define WRITE_MESSAGE(msg)
Representation of a lane in the micro simulation.
bool isPushButtonPressed()
void addPolicy(MSSOTLPolicy *policy)
MSDeterministicHiLevelTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > ¶meters)
Constructor without sensors passed.
int countVehicles(MSPhaseDefinition phase)