46 bool addValue(
const T newValue, T& replacedValue) {
59 T
at(
const int index)
const {
113 const std::string& programID,
const Phases& phases,
int step,
115 const std::map<std::string, std::string>& parameters);
187 return "swarmBasedTrafficLogic";
314 void choosePolicy(
double phero_in,
double phero_out,
double dispersion_in,
double dispersion_out);
318 return getParameter(
"POLICIES",
"Platoon;Phase;Marching;Congestion");
332 std::vector<double> phero_values;
334 for (
int i = 0; i < lanes_in / 2; i++) {
337 for (
int i = lanes_in / 2; i < lanes_in; i++) {
338 phero_values.push_back(0.0);
341 double sum_avg_tmp = 0;
343 for (
int i = 0; i < (int)phero_values.size(); i++) {
344 sum_avg_tmp += phero_values[i];
347 double mean = sum_avg_tmp / phero_values.size();
349 double sum_dev_tmp = 0;
350 for (
int i = 0; i < (int)phero_values.size(); i++) {
351 sum_dev_tmp += pow(phero_values[i] - mean, 2);
354 double deviation = sqrt(sum_dev_tmp / phero_values.size());
360 std::vector<double> phero_values;
362 for (
int i = 0; i < lanes_out / 2; i++) {
365 for (
int i = lanes_out / 2; i < lanes_out; i++) {
366 phero_values.push_back(0.0);
369 double sum_avg_tmp = 0;
370 for (
int i = 0; i < (int)phero_values.size(); i++) {
371 sum_avg_tmp += phero_values[i];
373 double mean = sum_avg_tmp / phero_values.size();
375 double sum_dev_tmp = 0;
377 for (
int i = 0; i < (int)phero_values.size(); i++) {
378 sum_dev_tmp += pow(phero_values[i] - mean, 2);
381 double deviation = sqrt(sum_dev_tmp / phero_values.size());
std::map< std::string, double > MSLaneId_PheromoneMap
std::map< MSLane *, bool > LaneCheckMap
std::vector< std::string > LaneIdVector
virtual ~CircularBuffer()
bool addValue(const T newValue, T &replacedValue)
T at(const int index) const
void push_front(const T value)
void insert(const T &value)
Representation of a lane in the micro simulation.
A self-organizing high-level traffic light logic.
std::string getPoliciesParam()
virtual SUMOTime computeReturnTime()
double getPheromoneForInputLanes()
double scaleFactorDispersionOut
MSLaneId_PheromoneMap pheromoneOutputLanes
This pheromone is an indicator of congestion on output lanes. Its levels refer to the average speed o...
bool mustChange
When true, indicates that the current policy MUST be changed. It's used to force the exit from the co...
bool allowLine(MSLane *)
Check if a lane is allowed to be added to the maps pheromoneInputLanes and pheromoneOutputLanes Contr...
bool gotTargetLane
When true indicates that we've already acquired the target lanes for this particular phase.
int getReinforcementMode()
void updatePheromoneLevels()
Update pheromone levels Pheromone on input lanes is costantly updated Pheromone follows a discrete-ti...
void choosePolicy(double phero_in, double phero_out, double dispersion_in, double dispersion_out)
void initScaleFactorDispersionIn(int lanes_in)
double getForgettingCox()
double calculateEtaRatio()
LaneIdVector targetLanes
A copy of the target lanes of this phase.
~MSSwarmTrafficLightLogic()
double getDispersionForOutputLanes(double average_phero_out)
bool skipEta
When true indicates that we can skip the evaluation of eta since we've a congestion policy that is la...
void updateSensitivities()
double getDistanceOfMaxPheroForInputLanes()
SUMOTime getMaxCongestionDuration()
double calculateEtaDiff()
Method that should calculate the valor of eta a coefficient to evaluate the current policy's work....
double getChangePlanProbability()
std::map< std::string, CircularBuffer< double > * > m_meanSpeedHistory
std::map< std::string, std::string > m_pheroLevelLog
double getDispersionForInputLanes(double average_phero_in)
std::map< std::string, CircularBuffer< double > * > m_derivativeHistory
void resetPheromone()
Resets pheromone levels.
MSSwarmTrafficLightLogic(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.
MSLaneId_PheromoneMap pheromoneInputLanes
This pheronome is an indicator of congestion on input lanes. Its levels refer to the average speed of...
double scaleFactorDispersionIn
std::string getLaneLightState(const std::string &laneId)
double getScaleFactorDispersionOut()
double getDistanceOfMaxPheroForOutputLanes()
double getScaleFactorDispersionIn()
bool m_useVehicleTypesWeights
void initScaleFactorDispersionOut(int lanes_out)
std::ofstream swarmLogFile
std::map< std::string, std::vector< int > > m_laneIndexMap
SUMOTime lastThetaSensitivityUpdate
void decidePolicy()
Decide the current policy according to pheromone levels The decision reflects on currentPolicy value.
LaneCheckMap laneCheck
Map to check if a lane was already controlled during the elaboration of eta.
double calculatePhi(int factor)
Method that should calculate the valor of phi a coefficient to amplify/attenuate eta based on a facto...
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
SUMOTime congestion_steps
double getPheromoneForOutputLanes()
const std::string getLogicType() const
Returns the type of the logic as a string.
A class that stores and controls tls and switching of their programs.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Builds detectors for microsim.
const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...