Program Listing for File convergence_calculator.hpp

Return to documentation for file (cosm/convergence/convergence_calculator.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <boost/optional.hpp>
#include <memory>
#include <vector>

#include "rcppsw/er/client.hpp"
#include "rcppsw/math/radians.hpp"
#include "rcppsw/math/vector2.hpp"
#include "rcppsw/mpl/typelist.hpp"

#include "cosm/convergence/config/convergence_config.hpp"
#include "cosm/convergence/metrics/convergence_metrics.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace rcppsw::ds {
template <typename Typelist>
class type_map;
} /* namespace rcppsw::ds */

namespace cosm::convergence {

class angular_order;
class interactivity;
class positional_entropy;
class task_dist_entropy;
class velocity;

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
class convergence_calculator final : public metrics::convergence_metrics,
                                     public rer::client<convergence_calculator> {
 public:
  using headings_calc_cb_type =
      std::function<std::vector<rmath::radians>(size_t)>;

  using nn_calc_cb_type = std::function<std::vector<double>(size_t)>;

  using pos_calc_cb_type = std::function<std::vector<rmath::vector2d>(size_t)>;

  using tasks_calc_cb_type = std::function<std::vector<int>(size_t)>;

  explicit convergence_calculator(const config::convergence_config* config);
  ~convergence_calculator(void) override;

  /* convergence metrics */
  conv_status_t swarm_interactivity(void) const override;
  conv_status_t swarm_angular_order(void) const override;
  conv_status_t swarm_positional_entropy(void) const override;
  conv_status_t swarm_task_dist_entropy(void) const override;
  conv_status_t swarm_velocity(void) const override;
  double swarm_conv_epsilon(void) const override { return mc_config.epsilon; }
  void reset_metrics(void) override;

  void angular_order_init(const headings_calc_cb_type& cb);

  void interactivity_init(const nn_calc_cb_type& cb);

  void task_dist_entropy_init(const tasks_calc_cb_type& cb);

  void positional_entropy_init(const pos_calc_cb_type& cb);

  void velocity_init(const pos_calc_cb_type& cb);

  bool converged(void) const RCPPSW_PURE;

  void update(void);

 private:
  using measure_typelist = rmpl::typelist<positional_entropy,
                                          task_dist_entropy,
                                          angular_order,
                                          interactivity,
                                          velocity>;
  /* clang-format off */
  const config::convergence_config                 mc_config;

  std::unique_ptr<rds::type_map<measure_typelist>> m_measures{nullptr};
  boost::optional<headings_calc_cb_type>           m_headings_calc{nullptr};
  boost::optional<nn_calc_cb_type>                 m_nn_calc{nullptr};
  boost::optional<pos_calc_cb_type>                m_pos_calc{nullptr};
  boost::optional<tasks_calc_cb_type>              m_tasks_calc{nullptr};
  /* clang-format on */
};

} /* namespace cosm::convergence */