21 #ifndef MSSwarmTrafficLightLogic_h 22 #define MSSwarmTrafficLightLogic_h 55 bool addValue(
const T newValue, T& replacedValue) {
68 T
at(
const int index)
const {
100 m_buffer[m_currentIndex++] = value;
101 if (m_currentIndex == m_size) {
122 const std::string& subid,
const Phases& phases,
int step,
124 const std::map<std::string, std::string>& parameters);
185 return scaleFactorDispersionIn;
189 return scaleFactorDispersionOut;
196 return "swarmBasedTrafficLogic";
228 int decideNextPhase();
244 void resetPheromone();
249 double getPheromoneForInputLanes();
254 double getPheromoneForOutputLanes();
259 double getDispersionForInputLanes(
double average_phero_in);
264 double getDispersionForOutputLanes(
double average_phero_out);
269 double getDistanceOfMaxPheroForInputLanes();
274 double getDistanceOfMaxPheroForOutputLanes();
280 void updatePheromoneLevels();
292 void updateSensitivities();
306 double calculatePhi(
int factor);
314 double calculateEtaDiff();
316 double calculateEtaRatio();
322 void resetLaneCheck();
323 void choosePolicy(
double phero_in,
double phero_out,
double dispersion_in,
double dispersion_out);
324 void choosePolicy(
double phero_in,
double phero_out);
327 return getParameter(
"POLICIES",
"Platoon;Phase;Marching;Congestion");
341 std::vector<double> phero_values;
343 for (
int i = 0; i < lanes_in / 2; i++) {
344 phero_values.push_back(getPheroMaxVal());
346 for (
int i = lanes_in / 2; i < lanes_in; i++) {
347 phero_values.push_back(0.0);
350 double sum_avg_tmp = 0;
352 for (
int i = 0; i < (int)phero_values.size(); i++) {
353 sum_avg_tmp += phero_values[i];
356 double mean = sum_avg_tmp / phero_values.size();
358 double sum_dev_tmp = 0;
359 for (
int i = 0; i < (int)phero_values.size(); i++) {
360 sum_dev_tmp += pow(phero_values[i] - mean, 2);
363 double deviation = sqrt(sum_dev_tmp / phero_values.size());
365 scaleFactorDispersionIn = getPheroMaxVal() / deviation;
369 std::vector<double> phero_values;
371 for (
int i = 0; i < lanes_out / 2; i++) {
372 phero_values.push_back(getPheroMaxVal());
374 for (
int i = lanes_out / 2; i < lanes_out; i++) {
375 phero_values.push_back(0.0);
378 double sum_avg_tmp = 0;
379 for (
int i = 0; i < (int)phero_values.size(); i++) {
380 sum_avg_tmp += phero_values[i];
382 double mean = sum_avg_tmp / phero_values.size();
384 double sum_dev_tmp = 0;
386 for (
int i = 0; i < (int)phero_values.size(); i++) {
387 sum_dev_tmp += pow(phero_values[i] - mean, 2);
390 double deviation = sqrt(sum_dev_tmp / phero_values.size());
392 scaleFactorDispersionOut = getPheroMaxVal() / deviation;
442 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