44 bool addValue(
const T newValue, T& replacedValue) {
57 T
at(
const int index)
const {
111 const std::string& programID,
const Phases& phases,
int step,
185 return "swarmBasedTrafficLogic";
312 void choosePolicy(
double phero_in,
double phero_out,
double dispersion_in,
double dispersion_out);
316 return getParameter(
"POLICIES",
"Platoon;Phase;Marching;Congestion");
330 std::vector<double> phero_values;
332 for (
int i = 0; i < lanes_in / 2; i++) {
335 for (
int i = lanes_in / 2; i < lanes_in; i++) {
336 phero_values.push_back(0.0);
339 double sum_avg_tmp = 0;
341 for (
int i = 0; i < (int)phero_values.size(); i++) {
342 sum_avg_tmp += phero_values[i];
345 const double mean = sum_avg_tmp / (double)phero_values.size();
347 double sum_dev_tmp = 0;
348 for (
int i = 0; i < (int)phero_values.size(); i++) {
349 sum_dev_tmp += pow(phero_values[i] - mean, 2);
352 const double deviation = sqrt(sum_dev_tmp / (
double)phero_values.size());
358 std::vector<double> phero_values;
360 for (
int i = 0; i < lanes_out / 2; i++) {
363 for (
int i = lanes_out / 2; i < lanes_out; i++) {
364 phero_values.push_back(0.0);
367 double sum_avg_tmp = 0;
368 for (
int i = 0; i < (int)phero_values.size(); i++) {
369 sum_avg_tmp += phero_values[i];
371 const double mean = sum_avg_tmp / (double)phero_values.size();
373 double sum_dev_tmp = 0;
375 for (
int i = 0; i < (int)phero_values.size(); i++) {
376 sum_dev_tmp += pow(phero_values[i] - mean, 2);
379 const double deviation = sqrt(sum_dev_tmp / (
double)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.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const override
gets a parameter
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()
Parameterised::Map m_pheroLevelLog
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
double getDispersionForInputLanes(double average_phero_in)
std::map< std::string, CircularBuffer< double > * > m_derivativeHistory
void resetPheromone()
Resets pheromone levels.
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.
std::map< std::string, std::string > Map
parameters map
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,...