Program Listing for File pheromone_density.hpp
↰ Return to documentation for file (cosm/repr/pheromone_density.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <algorithm>
#include "rcppsw/er/client.hpp"
#include "rcppsw/math/expression.hpp"
#include "rcppsw/rcppsw.hpp"
/*******************************************************************************
* Namespaces/Decls
******************************************************************************/
namespace cosm::repr {
/*******************************************************************************
* Class Definitions
******************************************************************************/
class pheromone_density final : public rmath::expression<double>,
public rer::client<pheromone_density> {
public:
static constexpr const double kUNIT_QUANTITY = 1.0;
pheromone_density(void) : pheromone_density{ -1.0 } {}
explicit pheromone_density(double rho)
: ER_CLIENT_INIT("cosm.repr.pheromone"), m_delta(0), m_rho(rho) {}
void rho(double rho) { m_rho = rho; }
void reset(void) {
eval(0.0);
m_delta = 0.0;
}
double update(void) {
ER_ASSERT(m_rho > 0, "Bad rho: %f", m_rho);
double res = std::max<double>((1.0 - m_rho) * v() + m_delta, 0.0);
m_delta = 0;
return eval(res);
}
void pheromone_add(double val) { m_delta += val; }
void pheromone_set(double val) {
eval(val);
m_delta = 0;
}
pheromone_density operator-(const pheromone_density& other) const {
pheromone_density res(*this);
res -= other;
return res;
}
pheromone_density& operator-=(const pheromone_density& other) {
this->eval(this->v() - other.v());
return *this;
}
pheromone_density operator+(const pheromone_density& other) const {
pheromone_density res(*this);
res += other;
return res;
}
pheromone_density& operator+=(const pheromone_density& other) {
this->eval(this->v() + other.v());
return *this;
}
pheromone_density operator/(double div) const {
pheromone_density res(*this);
res.eval(this->v() / div);
return res;
}
private:
/* clang-format off */
double m_delta;
double m_rho;
/* clang-format on */
};
} /* namespace cosm::repr */