18 #ifndef MSSwarmTrafficLightLogic_h 19 #define MSSwarmTrafficLightLogic_h 48 bool addValue(
const T newValue, T& replacedValue) {
61 T
at(
const int index)
const {
93 m_buffer[m_currentIndex++] = value;
94 if (m_currentIndex == m_size) {
115 const std::string& programID,
const Phases& phases,
int step,
117 const std::map<std::string, std::string>& parameters);
178 return scaleFactorDispersionIn;
182 return scaleFactorDispersionOut;
189 return "swarmBasedTrafficLogic";
221 int decideNextPhase();
237 void resetPheromone();
242 double getPheromoneForInputLanes();
247 double getPheromoneForOutputLanes();
252 double getDispersionForInputLanes(
double average_phero_in);
257 double getDispersionForOutputLanes(
double average_phero_out);
262 double getDistanceOfMaxPheroForInputLanes();
267 double getDistanceOfMaxPheroForOutputLanes();
273 void updatePheromoneLevels();
285 void updateSensitivities();
299 double calculatePhi(
int factor);
307 double calculateEtaDiff();
309 double calculateEtaRatio();
315 void resetLaneCheck();
316 void choosePolicy(
double phero_in,
double phero_out,
double dispersion_in,
double dispersion_out);
317 void choosePolicy(
double phero_in,
double phero_out);
320 return getParameter(
"POLICIES",
"Platoon;Phase;Marching;Congestion");
334 std::vector<double> phero_values;
336 for (
int i = 0; i < lanes_in / 2; i++) {
337 phero_values.push_back(getPheroMaxVal());
339 for (
int i = lanes_in / 2; i < lanes_in; i++) {
340 phero_values.push_back(0.0);
343 double sum_avg_tmp = 0;
345 for (
int i = 0; i < (int)phero_values.size(); i++) {
346 sum_avg_tmp += phero_values[i];
349 double mean = sum_avg_tmp / phero_values.size();
351 double sum_dev_tmp = 0;
352 for (
int i = 0; i < (int)phero_values.size(); i++) {
353 sum_dev_tmp += pow(phero_values[i] - mean, 2);
356 double deviation = sqrt(sum_dev_tmp / phero_values.size());
358 scaleFactorDispersionIn = getPheroMaxVal() / deviation;
362 std::vector<double> phero_values;
364 for (
int i = 0; i < lanes_out / 2; i++) {
365 phero_values.push_back(getPheroMaxVal());
367 for (
int i = lanes_out / 2; i < lanes_out; i++) {
368 phero_values.push_back(0.0);
371 double sum_avg_tmp = 0;
372 for (
int i = 0; i < (int)phero_values.size(); i++) {
373 sum_avg_tmp += phero_values[i];
375 double mean = sum_avg_tmp / phero_values.size();
377 double sum_dev_tmp = 0;
379 for (
int i = 0; i < (int)phero_values.size(); i++) {
380 sum_dev_tmp += pow(phero_values[i] - mean, 2);
383 double deviation = sqrt(sum_dev_tmp / phero_values.size());
385 scaleFactorDispersionOut = getPheroMaxVal() / deviation;
435 std::string getLaneLightState(
const std::string& laneId);
std::map< std::string, double > MSLaneId_PheromoneMap
virtual SUMOTime computeReturnTime()
void initScaleFactorDispersionOut(int lanes_out)
Builds detectors for microsim.
int getReinforcementMode()
SUMOTime getMaxCongestionDuration()
std::string getPoliciesParam()
double getChangePlanProbability()
std::ofstream swarmLogFile
SUMOTime congestion_steps
LaneIdVector targetLanes
A copy of the target lanes of this phase.
const std::string getLogicType() const
Returns the type of the logic as a string.
T at(const int index) const
std::map< MSLane *, bool > LaneCheckMap
A self-organizing high-level traffic light logic.
bool addValue(const T newValue, T &replacedValue)
A class that stores and controls tls and switching of their programs.
bool mustChange
When true, indicates that the current policy MUST be changed. It's used to force the exit from the co...
virtual ~CircularBuffer()
double scaleFactorDispersionOut
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
std::map< std::string, std::string > m_pheroLevelLog
bool skipEta
When true indicates that we can skip the evaluation of eta since we've a congestion policy that is la...
std::map< std::string, CircularBuffer< double > *> m_meanSpeedHistory
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
bool gotTargetLane
When true indicates that we've already acquired the target lanes for this particular phase...
double getScaleFactorDispersionIn()
void push_front(const T value)
MSLaneId_PheromoneMap pheromoneOutputLanes
This pheromone is an indicator of congestion on output lanes. Its levels refer to the average speed o...
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
void insert(const T &value)
double getForgettingCox()
MSLaneId_PheromoneMap pheromoneInputLanes
This pheronome is an indicator of congestion on input lanes. Its levels refer to the average speed of...
SUMOTime lastThetaSensitivityUpdate
bool m_useVehicleTypesWeights
void initScaleFactorDispersionIn(int lanes_in)
LaneCheckMap laneCheck
Map to check if a lane was already controlled during the elaboration of eta.
double getScaleFactorDispersionOut()
double scaleFactorDispersionIn
std::vector< std::string > LaneIdVector
Representation of a lane in the micro simulation.
std::map< std::string, std::vector< int > > m_laneIndexMap
std::map< std::string, CircularBuffer< double > *> m_derivativeHistory