Program Listing for File bi_tab.hpp

Return to documentation for file (cosm/ta/ds/bi_tab.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <string>
#include <utility>

#include "rcppsw/er/client.hpp"
#include "rcppsw/math/rng.hpp"

#include "cosm/ta/metrics/bi_tab_metrics.hpp"
#include "cosm/ta/config/task_partition_config.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace cosm::ta {
class polled_task;

class subtask_sel_probability;
class partition_probability;
} /* namespace cosm::ta */

namespace cosm::ta::ds {

class bi_tdgraph;

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
class bi_tab final : public metrics::bi_tab_metrics,
                     public rer::client<bi_tab> {
 public:
  static inline const std::string kPartitionSrcExec = "exec";
  static inline const std::string kPartitionSrcInterface = "interface";
  static inline const std::string kSubtaskSelSrcExec = "exec";
  static inline const std::string kSubtaskSelSrcInterface = "interface";

  struct elements {
    const bi_tdgraph* graph;
    polled_task* root;
    polled_task* child1;
    polled_task* child2;
  };
  bi_tab(const struct elements* elts,
         const config::task_partition_config* partitioning,
         const config::src_sigmoid_sel_config* subtask_sel);

  ~bi_tab(void) override;

  /* Necessary for use in std::variant */
  bi_tab(const bi_tab& other) = delete;
  bi_tab& operator=(const bi_tab&) = delete;


  /* bi TAB metrics */
  bool subtask1_active(void) const override {
    return m_active_task == m_child1;
  }
  bool subtask2_active(void) const override {
    return m_active_task == m_child2;
  }
  bool employed_partitioning(void) const override {
    return m_employed_partitioning;
  }
  bool root_active(void) const override { return m_active_task == m_root; }

  void partition_prob_update(rmath::rng* rng);

  polled_task* task_allocate(rmath::rng* rng);

  const polled_task* active_task(void) const { return m_active_task; }

  void task_abort_update(polled_task* aborted, rmath::rng* rng);

  void task_finish_update(polled_task* finished, rmath::rng* rng);

  bool contains_task(const polled_task* task) const RCPPSW_PURE;

  bool task_is_root(const polled_task* task) const RCPPSW_PURE;

  bool task_is_child(const polled_task* task) const RCPPSW_PURE;

  const polled_task* root(void) const { return m_root; }

  const polled_task* child1(void) const { return m_child1; }

  const polled_task* child2(void) const { return m_child2; }

  const polled_task* last_task(void) const { return m_last_task; }

  void last_subtask(const polled_task* t) { m_last_subtask = t; }

  bool task_changed(void) const override {
    return m_active_task != m_last_task;
  }

  bool task_depth_changed(void) const override;

  double partition_prob(void) const override RCPPSW_PURE;

  double subtask_selection_prob(void) const override RCPPSW_PURE;

 private:
  polled_task* subtask_allocate(rmath::rng* rng);
  std::pair<double, double> subtask_sw_calc(rmath::rng* rng);


  /* clang-format off */
  const bool                               mc_always_partition;
  const bool                               mc_never_partition;
  const std::string                        mc_partition_input;
  const std::string                        mc_subtask_sel_input;
  const bi_tdgraph*                        mc_graph;

  polled_task* const                       m_root;
  polled_task* const                       m_child1;
  polled_task* const                       m_child2;
  bool                                     m_employed_partitioning{false};
  const polled_task*                       m_last_task{nullptr};
  const polled_task*                       m_last_subtask{nullptr};
  const polled_task*                       m_active_task{nullptr};

  std::unique_ptr<subtask_sel_probability> m_sel_prob{nullptr};
  std::unique_ptr<partition_probability>   m_partition_prob{nullptr};
  /* clang-format on */
};

} /* namespace cosm::ta::ds */