clp_interface.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #ifndef CASADI_CLP_INTERFACE_HPP
26 #define CASADI_CLP_INTERFACE_HPP
27 
28 #include "casadi/core/conic_impl.hpp"
29 #include <casadi/interfaces/clp/casadi_conic_clp_export.h>
30 
31 #include "ClpSimplex.hpp"
32 #include "ClpFactorization.hpp"
33 #include "ClpNetworkMatrix.hpp"
34 #include "ClpEventHandler.hpp"
35 
36 #include <string>
37 
48 
49 namespace casadi {
50 
51  struct ClpMemory : public ConicMemory {
53  ClpMemory();
54 
56  ~ClpMemory();
57 
58  std::vector<int> colind, row;
59 
60  int return_status;
61  int secondary_return_status;
62 
63  };
64 
74  class ClpInterface : public Conic {
75  public:
77  static Conic* creator(const std::string& name,
78  const std::map<std::string, Sparsity>& st) {
79  return new ClpInterface(name, st);
80  }
81 
83  explicit ClpInterface(const std::string& name,
84  const std::map<std::string, Sparsity>& st);
85 
87  ~ClpInterface() override;
88 
89  // Get name of the plugin
90  const char* plugin_name() const override { return "clp";}
91 
92  // Get name of the class
93  std::string class_name() const override { return "ClpInterface";}
94 
96 
97  static const Options options_;
98  const Options& get_options() const override { return options_;}
100 
101  // Initialize the solver
102  void init(const Dict& opts) override;
103 
105  void* alloc_mem() const override { return new ClpMemory();}
106 
108  int init_mem(void* mem) const override;
109 
111  void free_mem(void *mem) const override { delete static_cast<ClpMemory*>(mem);}
112 
114  Dict get_stats(void* mem) const override;
115 
116  // Solve the QP
117  int solve(const double** arg, double** res,
118  casadi_int* iw, double* w, void* mem) const override;
119 
121  static const std::string meta_doc;
122 
124  Dict opts_;
125 
126  void serialize_body(SerializingStream &s) const override;
127 
129  static ProtoFunction* deserialize(DeserializingStream& s) { return new ClpInterface(s); }
130 
131  protected:
133  explicit ClpInterface(DeserializingStream& s);
134 
135  private:
136  // Conversion of string to enum for options
137  static std::map<std::string, ClpIntParam> param_map_int;
138  static std::map<std::string, ClpDblParam> param_map_double;
139  static std::map<std::string, ClpSolve::SolveType> param_map_solvetype;
140  static std::map<std::string, ClpSolve::PresolveType> param_map_presolvetype;
141 
142  };
143 } // end namespace casadi
145 #endif // CASADI_CLP_INTERFACE_HPP
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.