cbc_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_CBC_INTERFACE_HPP
26 #define CASADI_CBC_INTERFACE_HPP
27 
28 #include "casadi/core/conic_impl.hpp"
29 #include <casadi/interfaces/cbc/casadi_conic_cbc_export.h>
30 
31 #include "OsiClpSolverInterface.hpp"
32 #include "CbcModel.hpp"
33 #include "CbcEventHandler.hpp"
34 #include <string>
35 
46 
47 namespace casadi {
48 
49  struct CbcMemory : public ConicMemory {
51  CbcMemory();
52 
54  ~CbcMemory();
55 
56  std::vector<int> colind, row;
57 
58  int return_status;
59  int secondary_return_status;
60 
61  casadi_int iter_count;
62  casadi_int node_count;
63 
64  };
65 
75  class CbcInterface : public Conic {
76  public:
78  static Conic* creator(const std::string& name,
79  const std::map<std::string, Sparsity>& st) {
80  return new CbcInterface(name, st);
81  }
82 
84  explicit CbcInterface(const std::string& name,
85  const std::map<std::string, Sparsity>& st);
86 
88  ~CbcInterface() override;
89 
90  // Get name of the plugin
91  const char* plugin_name() const override { return "cbc";}
92 
93  // Get name of the class
94  std::string class_name() const override { return "CbcInterface";}
95 
97 
98  static const Options options_;
99  const Options& get_options() const override { return options_;}
101 
102  // Initialize the solver
103  void init(const Dict& opts) override;
104 
106  void* alloc_mem() const override { return new CbcMemory();}
107 
109  int init_mem(void* mem) const override;
110 
112  void free_mem(void *mem) const override { delete static_cast<CbcMemory*>(mem);}
113 
115  Dict get_stats(void* mem) const override;
116 
117  // Solve the QP
118  int solve(const double** arg, double** res,
119  casadi_int* iw, double* w, void* mem) const override;
120 
122  static const std::string meta_doc;
123 
125  Dict opts_;
126 
127  void serialize_body(SerializingStream &s) const override;
128 
130  static ProtoFunction* deserialize(DeserializingStream& s) { return new CbcInterface(s); }
131 
133  bool integer_support() const override { return true;}
134 
135  protected:
137  explicit CbcInterface(DeserializingStream& s);
138 
139  private:
140  // Conversion of string to enum for options
141  static std::map<std::string, CbcModel::CbcIntParam> param_map_int;
142  static std::map<std::string, CbcModel::CbcDblParam> param_map_double;
143  static std::map<std::string, OsiIntParam> osi_param_map_int;
144  static std::map<std::string, OsiDblParam> osi_param_map_double;
145 
146  void copy_cbc_results(const CbcModel& model, double** res) const;
147 
148  // SOS structure
149  std::vector< std::vector<int> > sos_groups_;
150  std::vector< std::vector<double> > sos_weights_;
151  std::vector<casadi_int> sos_types_;
152 
153  bool hot_start_;
154 
155  };
156 } // end namespace casadi
158 #endif // CASADI_CBC_INTERFACE_HPP
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.