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);
196 return "swarmBasedTrafficLogic";
327 return getParameter(
"POLICIES",
"Platoon;Phase;Marching;Congestion");
341 std::vector<SUMOReal> phero_values;
343 for (
int i = 0; i < lanes_in / 2; i++) {
346 for (
int i = lanes_in / 2; i < lanes_in; i++) {
347 phero_values.push_back(0.0);
352 for (
int i = 0; i < (int)phero_values.size(); i++) {
353 sum_avg_tmp += phero_values[i];
356 SUMOReal mean = sum_avg_tmp / phero_values.size();
359 for (
int i = 0; i < (int)phero_values.size(); i++) {
360 sum_dev_tmp += pow(phero_values[i] - mean, 2);
363 SUMOReal deviation = sqrt(sum_dev_tmp / phero_values.size());
369 std::vector<SUMOReal> phero_values;
371 for (
int i = 0; i < lanes_out / 2; i++) {
374 for (
int i = lanes_out / 2; i < lanes_out; i++) {
375 phero_values.push_back(0.0);
379 for (
int i = 0; i < (int)phero_values.size(); i++) {
380 sum_avg_tmp += phero_values[i];
382 SUMOReal mean = sum_avg_tmp / phero_values.size();
386 for (
int i = 0; i < (int)phero_values.size(); i++) {
387 sum_dev_tmp += pow(phero_values[i] - mean, 2);
390 SUMOReal deviation = sqrt(sum_dev_tmp / phero_values.size());
virtual SUMOTime computeReturnTime()
void initScaleFactorDispersionOut(int lanes_out)
Builds detectors for microsim.
std::map< std::string, CircularBuffer< SUMOReal > * > m_derivativeHistory
SUMOReal getScaleFactorDispersionOut()
static SUMOReal _2SUMOReal(const E *const data)
converts a char-type array into the SUMOReal value described by it
int getReinforcementMode()
std::map< std::string, CircularBuffer< SUMOReal > * > m_meanSpeedHistory
MSSwarmTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &subid, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > ¶meters)
Constructor without sensors passed.
SUMOTime getMaxCongestionDuration()
SUMOReal getLearningCox()
std::string getPoliciesParam()
bool allowLine(MSLane *)
Check if a lane is allowed to be added to the maps pheromoneInputLanes and pheromoneOutputLanes Contr...
std::ofstream swarmLogFile
void updatePheromoneLevels()
Update pheromone levels Pheromone on input lanes is costantly updated Pheromone follows a discrete-ti...
void updateSensitivities()
SUMOReal getDispersionForInputLanes(SUMOReal average_phero_in)
SUMOTime congestion_steps
LaneIdVector targetLanes
A copy of the target lanes of this phase.
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
std::map< MSLane *, bool > LaneCheckMap
SUMOReal getPheromoneForInputLanes()
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...
T at(const int index) const
SUMOReal calculatePhi(int factor)
Method that should calculate the valor of phi a coefficient to amplify/attenuate eta based on a facto...
virtual ~CircularBuffer()
std::string getLaneLightState(const std::string &laneId)
SUMOReal calculateEtaRatio()
std::map< std::string, SUMOReal > MSLaneId_PheromoneMap
std::map< std::string, std::string > m_pheroLevelLog
SUMOReal getPheromoneForOutputLanes()
SUMOReal m_derivativeAlpha
bool skipEta
When true indicates that we can skip the evaluation of eta since we've a congestion policy that is la...
void decidePolicy()
Decide the current policy according to pheromone levels The decision reflects on currentPolicy value...
const std::string getLogicType() const
Returns the type of the logic as a string.
SUMOReal getScaleFactorDispersionIn()
SUMOReal scaleFactorDispersionIn
bool gotTargetLane
When true indicates that we've already acquired the target lanes for this particular phase...
SUMOReal getForgettingCox()
SUMOReal getDispersionForOutputLanes(SUMOReal average_phero_out)
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...
~MSSwarmTrafficLightLogic()
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 init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
void insert(const T &value)
SUMOReal getPheroMaxVal()
void choosePolicy(SUMOReal phero_in, SUMOReal phero_out, SUMOReal dispersion_in, SUMOReal dispersion_out)
MSLaneId_PheromoneMap pheromoneInputLanes
This pheronome is an indicator of congestion on input lanes. Its levels refer to the average speed of...
SUMOReal getDistanceOfMaxPheroForInputLanes()
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.
std::vector< std::string > LaneIdVector
SUMOReal calculateEtaDiff()
Method that should calculate the valor of eta a coefficient to evaluate the current policy's work...
Representation of a lane in the micro simulation.
std::map< std::string, std::vector< int > > m_laneIndexMap
SUMOReal scaleFactorDispersionOut
void resetPheromone()
Resets pheromone levels.
SUMOReal getDistanceOfMaxPheroForOutputLanes()
SUMOReal getChangePlanProbability()