alpaqa_interface.hpp
1 #include <alpaqa/panoc-alm.hpp>
2 #include <alpaqa/problem/box-constr-problem.hpp>
3 #include <alpaqa/problem/problem-with-counters.hpp>
4 
5 #include <casadi/interfaces/alpaqa/casadi_nlpsol_alpaqa_export.h>
6 #include "casadi/core/nlpsol_impl.hpp"
7 #include "casadi/core/timing.hpp"
8 #include "alpaqa_problem.hpp"
9 
10 using Direction = alpaqa::LBFGSDirection<alpaqa::DefaultConfig>;
11 using InnerSolver = alpaqa::PANOCSolver<Direction>;
12 using OuterSolver = alpaqa::ALMSolver<InnerSolver>;
13 
14 namespace casadi {
15 
16  class AlpaqaInterface;
17 
18  struct AlpaqaMemory : public NlpsolMemory {
19 
20  alpaqa::ALMSolver<InnerSolver>* solver;
21 
23  };
24 
25  class AlpaqaInterface : public Nlpsol {
26  friend class AlpaqaProblem;
27  private:
28  void clear_mem_at(AlpaqaMemory* m) const;
29 
30  public:
31  explicit AlpaqaInterface(const std::string& name, const Function& nlp);
32  ~AlpaqaInterface() override;
33 
34  static Nlpsol* creator(const std::string& name, const Function& nlp) {
35  return new AlpaqaInterface(name, nlp);
36  }
37 
38  const char* plugin_name() const override { return "alpaqa";}
39 
40  // Get name of the class
41  std::string class_name() const override { return "AlpaqaInterface";}
42 
43  static const Options options_;
44  static const std::string meta_doc;
45 
46  const Options& get_options() const override { return options_;}
48 
49  // Initialize the solver
50  void init(const Dict& opts) override;
51 
53  void* alloc_mem() const override { return new AlpaqaMemory();}
54 
56  int init_mem(void* mem) const override;
57 
59  void free_mem(void *mem) const override;
60 
62  Dict get_stats(void* mem) const override;
63 
65  void set_work(void* mem, const double**& arg, double**& res,
66  casadi_int*& iw, double*& w) const override;
67 
68  // Solve the NLP
69  int solve(void* mem) const override;
70 
72 
75 
77  void serialize_body(SerializingStream &s) const override;
78 
80  static ProtoFunction* deserialize(DeserializingStream& s) { return new AlpaqaInterface(s); }
81 
82  protected:
85 
86 
87  };
88 };
AlpaqaInterface(const std::string &name, const Function &nlp)
int solve(void *mem) const override
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Dict get_stats(void *mem) const override
Get all statistics.
std::string class_name() const override
AlpaqaInterface(DeserializingStream &s)
Deserializing constructor.
Dict opts_
All Alpaqa options.
static const Options options_
void free_mem(void *mem) const override
Free memory block.
int init_mem(void *mem) const override
Initalize memory block.
void init(const Dict &opts) override
const char * plugin_name() const override
const Options & get_options() const override
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
static Nlpsol * creator(const std::string &name, const Function &nlp)
static const std::string meta_doc
void * alloc_mem() const override
Create memory block.
Helper class for Serialization.
Function object.
Definition: function.hpp:60
Helper class for Serialization.
General sparsity class.
Definition: sparsity.hpp:99
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
const AlpaqaInterface * interface
alpaqa::ALMSolver< InnerSolver > * solver