 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
21 const std::string& programID,
const Phases& phases,
int step,
22 SUMOTime delay,
const std::map<std::string, std::string>& parameters) :
42 "*** Intersection " +
getID()
43 +
" will run using MSDeterministicHiLevelTrafficLightLogic ***");
45 MSLane* currentLane =
nullptr;
46 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
48 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
49 laneVector->begin(); lane != laneVector->end(); lane++) {
50 currentLane = (*lane);
61 for (
int i = 0; i < (int)
myLinks.size(); i++) {
63 for (
int j = 0; j < (int)oneLink.size(); j++) {
64 currentLane = oneLink[j]->getLane();
99 double vSpeedInTot = 0;
100 for (MSLaneID_set::iterator laneIterator =
inputLanes.begin();
101 laneIterator !=
inputLanes.end(); laneIterator++) {
102 std::string laneId = *laneIterator;
105 vSpeedInTot += (13.89 - maxSpeed) * 10. / 13.89;
108 std::ostringstream i_str; i_str <<
" meanVehiclesSpeed " << maxSpeed <<
" inputLane " << laneId <<
" ID " <<
getID() <<
" .";
WRITE_MESSAGE(
time2string(
MSNet::getInstance()->getCurrentTimeStep()) +
" MSDeterministicHiLevelTrafficLightLogic::getMeanSpeedForInputLanes:: in" + i_str.str());)
117 double vSpeedOutTot = 0;
118 for (MSLaneID_set::iterator laneIterator =
outputLanes.begin();
119 laneIterator !=
outputLanes.end(); laneIterator++) {
120 std::string laneId = *laneIterator;
123 vSpeedOutTot += (13.89 - maxSpeed) * 10. / 13.89;
126 std::ostringstream i_str; i_str <<
" meanVehiclesSpeed " << maxSpeed <<
" outputLane " << laneId <<
" ID " <<
getID() <<
" .";
WRITE_MESSAGE(
time2string(
MSNet::getInstance()->getCurrentTimeStep()) +
" MSDeterministicHiLevelTrafficLightLogic::getMeanSpeedForOutputLanes:: out" + i_str.str());)
139 if (newPolicy != oldPolicy) {
142 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() +
" .");)
151 double mean_vSpeed_in,
double mean_vSpeed_out) {
153 int index_maxStimulus = 0;
154 double maxStimulus = -1;
156 for (
int i = 0; i < (int)
getPolicies().size(); i++) {
157 double stimulus =
getPolicies()[i]->computeDesirability(mean_vSpeed_in,
159 if (stimulus > maxStimulus) {
160 maxStimulus = stimulus;
161 index_maxStimulus = i;
164 std::ostringstream so_str; so_str <<
" policy " <<
getPolicies()[i]->getName() <<
" stimulus " << stimulus;
WRITE_MESSAGE(
"MSDeterministicHiLevelTrafficLightLogic::choosePolicy::" + so_str.str());)
virtual int decideNextPhase(SUMOTime elapsed, const MSPhaseDefinition *stage, int currentPhaseIndex, int phaseMaxCTS, bool thresholdPassed, bool pushButtonPressed, int vehicleCount)
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.
~MSDeterministicHiLevelTrafficLightLogic()
Class for a low-level policy.
Representation of a lane in the micro simulation.
Class for low-level marching policy.
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
void decidePolicy()
Decide the current policy according to pheromone levels The decision reflects on currentPolicy value.
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.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
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.
A self-organizing high-level traffic light logic.
MSLaneID_set inputLanes
This pheronome is an indicator of congestion on input lanes. Its levels refer to the average speed of...
MSSOTLSensors * getSensors()
bool isPushButtonPressed()
virtual double meanVehiclesSpeed(MSLane *lane)=0
Class for low-level congestion policy.
double getMeanSpeedForInputLanes()
const std::string & getState() const
Returns the state within this phase.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
std::string time2string(SUMOTime t)
int getPhaseIndexWithMaxCTS()
MSSOTLPolicy * getCurrentPolicy()
Returns the low-level policy currently selected by this high-level tll.
int getCurrentPhaseIndex() const
Returns the current index within the program.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
Class for low-level phase policy.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
int countVehicles(MSPhaseDefinition phase)
MSLaneID_set outputLanes
This pheromone is an indicator of congestion on output lanes. Its levels refer to the average speed o...
std::vector< MSSOTLPolicy * > & getPolicies()
Returns the vector of the low-level policies used by this high-level tll.
void addPolicy(MSSOTLPolicy *policy)
double getMeanSpeedForOutputLanes()
virtual bool canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed, const MSPhaseDefinition *stage, int vehicleCount)=0
void choosePolicy(double mean_vSpeed_in, double mean_vSpeed_out)
A class that stores and controls tls and switching of their programs.
Class for low-level platoon policy.
void init(NLDetectorBuilder &nb)
Initialises the tls.
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
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 activate(MSSOTLPolicy *policy)
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.