Program Listing for File PursePlanner.hpp

Return to documentation for file (src/mimir/algorithm/PursePlanner.hpp)

#pragma once

#include <atomic>
#include <chrono>
#include <cinttypes>
#include <memory>

#include <boost/statechart/detail/memory.hpp>
#include <boost/statechart/fifo_scheduler.hpp>
#include <boost/statechart/event_base.hpp>

#include <yaml-cpp/yaml.h>

#ifdef _MSC_VER
#pragma warning(push, 0)
#endif
#include <dds/pub/Publisher.hpp>
#include <dds/sub/Subscriber.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include <mimir/IAlgorithm.hpp>

namespace mimir
{
  namespace algorithm
  {

    class PursePlanner : public IAlgorithm
    {
    public:

      explicit PursePlanner(
          const YAML::Node& config,
          boost::statechart::fifo_scheduler<>& scheduler,
          boost::statechart::fifo_scheduler<>::processor_handle machine,
          dds::pub::Publisher publisher,
          dds::sub::Subscriber subscriber);
      virtual ~PursePlanner();
      virtual void solve(const std::atomic<bool>& cancel_token);
      virtual void initialize(const std::atomic<bool>& cancel_token);
      virtual void timer(const std::atomic<bool>& cancel_token);
      virtual inline const char* name(){ return "PursePlanner"; }
      void event(boost::statechart::event_base * const event);
      PursePlanner(const PursePlanner&) = delete; // noncopyable
      PursePlanner& operator=(const PursePlanner&) = delete; // noncopyable
      PursePlanner(PursePlanner&&) = delete; // noncopyable
      PursePlanner& operator=(PursePlanner&&) = delete; // noncopyable
    private:
      inline void step_time() { m_next_step += m_time_step; }
      void plot(bool do_plot);
      void read_parameters();
      void read_inputs();
      PursePlanner() = delete;
      class Impl;
      std::unique_ptr<Impl> m_impl; // special attention if to allow move construct/assign
      inline Impl* model() { return m_impl.get(); }
      boost::statechart::fifo_scheduler<> & m_scheduler;
      boost::statechart::fifo_scheduler<>::processor_handle m_stateMachine;
      const std::chrono::milliseconds m_time_step;
      std::chrono::steady_clock::time_point m_t0,
        m_next_step;
      std::chrono::system_clock::time_point m_t0_wall;
      const YAML::Node m_config;
      std::uint8_t m_retries;
      bool m_keep_solution;
    };

  }
}