20 #ifndef MSSwarmTrafficLightLogic_h 21 #define MSSwarmTrafficLightLogic_h 54 bool addValue(
const T newValue, T& replacedValue) {
67 T
at(
const int index)
const {
99 m_buffer[m_currentIndex++] = value;
100 if (m_currentIndex == m_size) {
121 const std::string& subid,
const Phases& phases,
int step,
123 const std::map<std::string, std::string>& parameters);
184 return scaleFactorDispersionIn;
188 return scaleFactorDispersionOut;
195 return "swarmBasedTrafficLogic";
227 int decideNextPhase();
243 void resetPheromone();
248 double getPheromoneForInputLanes();
253 double getPheromoneForOutputLanes();
258 double getDispersionForInputLanes(
double average_phero_in);
263 double getDispersionForOutputLanes(
double average_phero_out);
268 double getDistanceOfMaxPheroForInputLanes();
273 double getDistanceOfMaxPheroForOutputLanes();
279 void updatePheromoneLevels();
291 void updateSensitivities();
305 double calculatePhi(
int factor);
313 double calculateEtaDiff();
315 double calculateEtaRatio();
321 void resetLaneCheck();
322 void choosePolicy(
double phero_in,
double phero_out,
double dispersion_in,
double dispersion_out);
323 void choosePolicy(
double phero_in,
double phero_out);
326 return getParameter(
"POLICIES",
"Platoon;Phase;Marching;Congestion");
340 std::vector<double> phero_values;
342 for (
int i = 0; i < lanes_in / 2; i++) {
343 phero_values.push_back(getPheroMaxVal());
345 for (
int i = lanes_in / 2; i < lanes_in; i++) {
346 phero_values.push_back(0.0);
349 double sum_avg_tmp = 0;
351 for (
int i = 0; i < (int)phero_values.size(); i++) {
352 sum_avg_tmp += phero_values[i];
355 double mean = sum_avg_tmp / phero_values.size();
357 double sum_dev_tmp = 0;
358 for (
int i = 0; i < (int)phero_values.size(); i++) {
359 sum_dev_tmp += pow(phero_values[i] - mean, 2);
362 double deviation = sqrt(sum_dev_tmp / phero_values.size());
364 scaleFactorDispersionIn = getPheroMaxVal() / deviation;
368 std::vector<double> phero_values;
370 for (
int i = 0; i < lanes_out / 2; i++) {
371 phero_values.push_back(getPheroMaxVal());
373 for (
int i = lanes_out / 2; i < lanes_out; i++) {
374 phero_values.push_back(0.0);
377 double sum_avg_tmp = 0;
378 for (
int i = 0; i < (int)phero_values.size(); i++) {
379 sum_avg_tmp += phero_values[i];
381 double mean = sum_avg_tmp / phero_values.size();
383 double sum_dev_tmp = 0;
385 for (
int i = 0; i < (int)phero_values.size(); i++) {
386 sum_dev_tmp += pow(phero_values[i] - mean, 2);
389 double deviation = sqrt(sum_dev_tmp / phero_values.size());
391 scaleFactorDispersionOut = getPheroMaxVal() / deviation;
441 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
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
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.
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
void insert(const T &value)
double getForgettingCox()
static double _2double(const E *const data)
converts a char-type array into the double value described by it
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