Program Listing for File PursePlannerFormulation.hpp

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

#pragma once

#include <atomic>
#include <casadi/casadi.hpp>
#include <yaml-cpp/yaml.h>

#include <mimir/program/Config.hpp>
#include "mimir/FkinDds.hpp"

namespace mimir
{
  namespace algorithm
  {

    struct NlpProblemBuilder
    {
      casadi::DaeBuilder daeP;
      std::vector<std::string> constraints,
                               objectives;
      std::map<std::string, std::vector<bool>> x_inits;
      std::map<std::string, casadi::DaeBuilder> sub_system;
      std::vector<std::string> sub_system_names;
      std::map<std::string, casadi::Slice> decision_parameter_slice,
                                           parameter_slice;
      casadi_int parameter_dimension,
        decision_parameter_dimension;
      std::map<std::string, std::map<std::string, casadi::Slice>> state_slice,
                                                                  input_slice;
      std::map<std::string, casadi_int> state_dimension,
                                        input_dimension;
    };

    struct NlpStructure {
      NlpStructure() : problem_dimension(0) {}
      std::map<std::string, casadi::Slice> variable_slice;
      std::map<std::string, casadi::MX> discrete_variable;
      casadi_int problem_dimension;
    };

    class PursePlannerFormulation
    {
    public:

      PursePlannerFormulation(const YAML::Node& config_schema);
      PursePlannerFormulation() = default;
      ~PursePlannerFormulation();
      PursePlannerFormulation(const PursePlannerFormulation& other) = delete;
      PursePlannerFormulation& operator=(const PursePlannerFormulation& other) = delete;
      PursePlannerFormulation(PursePlannerFormulation&& other) = default;
      PursePlannerFormulation& operator=(PursePlannerFormulation&& other) = default;

      casadi::Slice get_slice(const std::string& name, const std::vector<casadi::MX>& vars);
      void set_variable(const std::string& name, const casadi::DM& value);
      fkin::OptiStats stats();
      void set_abort(const std::atomic<bool>& cancel_token);
      inline const fkin::NlpConfig& nlp_config() const { return m_nlp_config; }
      NlpProblemBuilder nlp_builder;
      casadi::NlpBuilder nlp_problem;
      casadi::Function nlp_solver;

      std::map<std::string, std::map<std::string, casadi::Function>> mpc;
      class NlpCallback;
      std::unique_ptr<NlpCallback> nlp_callback;
      double omega_max;
      std::uint32_t N2;
    private:
      fkin::NlpConfig m_nlp_config;
      NlpStructure m_nlp_structure;
    };
  }
}