PandA-2024.02
meilp_solver.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
45 #ifndef MEILP_SOLVER_HPP
46 #define MEILP_SOLVER_HPP
47 
49 #include "config_HAVE_COIN_OR.hpp"
50 #include "config_HAVE_GLPK.hpp"
51 #include "config_HAVE_LP_SOLVE.hpp"
52 
53 #include <cstddef>
54 #include <iosfwd>
55 #include <string>
56 #include <vector>
57 
59 #include "custom_map.hpp"
60 #include "refcount.hpp"
61 
69 
74 {
75  public:
79  enum ilp_sign
80  {
81  G,
82  L,
83  E
84  };
85 
86  private:
88  size_t nel;
89 
90  protected:
92  double* real_buffer;
93 
95  int* int_buffer;
96 
99 
101  int MAX_time;
102 
105 
107  std::map<int, int> priority;
108 
111 
114 
118  meilp_solver();
119 
124  void resize(size_t count);
125 
130  virtual void copy(const std::map<int, double>& i_coeffs);
131 
135  virtual void set_all_bounds() = 0;
136 
141  virtual void print(std::ostream& os) = 0;
142 
143  public:
148  {
149 #if HAVE_GLPK
150  GLPK,
151 #endif
152 #if HAVE_COIN_OR
153  COIN_OR,
154 #endif
155 #if HAVE_LP_SOLVE
156  LP_SOLVE
157 #endif
158  };
159 
163  enum ilp_dir
164  {
165  min,
167  };
168 
172  virtual ~meilp_solver();
173 
178  virtual void make(int nvars) = 0;
179 
183  virtual int solve() = 0;
184 
188  virtual int solve_ilp() = 0;
189 
197  virtual void add_row(std::map<int, double>& i_coeffs, double i_rhs, ilp_sign i_sign, const std::string& name) = 0;
198 
204  virtual void objective_add(std::map<int, double>& i_coeffs, ilp_dir dir) = 0;
205 
210  virtual void set_binary(int i);
211 
216  virtual void set_int(int i) = 0;
217 
224  virtual void set_bnds(int var, double lowbo, double upbo);
225 
231  virtual void set_lowbo(int var, double bound);
232 
238  virtual void set_upbo(int var, double bound);
239 
244  virtual void get_vars_solution(std::map<int, double>& vars) const = 0;
245 
250  virtual int get_number_constraints() const = 0;
251 
256  virtual int get_number_variables() const = 0;
257 
263  virtual void set_col_name(int var, const std::string& name) = 0;
264 
270  virtual std::string get_col_name(int var) = 0;
271 
275  virtual int add_empty_column() = 0;
276 
280  void setMaximumSeconds(int MAX_t)
281  {
282  MAX_time = MAX_t;
283  }
284 
288  void set_debug_level(int dl);
289 
294  void set_priority(const std::map<int, int>& _priority);
295 
302  static meilp_solverRef create_solver(supported_solvers solver_type);
303 
308  virtual void print_to_file(const std::string& file_name) = 0;
309 };
310 
311 #endif
Less then.
virtual void set_bnds(int var, double lowbo, double upbo)
Set lower and upper bound of a variable.
virtual int solve()=0
Solve the linear problem.
virtual void copy(const std::map< int, double > &i_coeffs)
REF_FORWARD_DECL(meilp_solver)
RefCount type definition of the meilp_solver class structure.
CustomUnorderedMap< int, double > upper_bounds
The upper bound of the variables. They will be really set by solve method.
Minimization.
CustomUnorderedMap< int, double > lower_bounds
The lower bound of the variables. They will be really set by solve method.
void setMaximumSeconds(int MAX_t)
???
virtual void set_upbo(int var, double bound)
Set upper bound of a variable.
virtual void add_row(std::map< int, double > &i_coeffs, double i_rhs, ilp_sign i_sign, const std::string &name)=0
Add a constraint to the ilp formulation.
virtual std::string get_col_name(int var)=0
Get name of a variable (column)
int unique_column_id
unique column identifier
Maximization.
virtual void objective_add(std::map< int, double > &i_coeffs, ilp_dir dir)=0
Set the objective function.
meilp_solver()
Constructor.
redefinition of map to manage ordered/unordered structures
virtual int get_number_variables() const =0
Return the number of variables.
virtual void set_binary(int i)
Set a variable to have only binary values.
void resize(size_t count)
std::map< int, int > priority
variables priority
void set_priority(const std::map< int, int > &_priority)
Set the variable priority.
ilp_dir
Type of objective function.
int dl
Definition: adpcm.c:212
virtual int solve_ilp()=0
Solve the integer linear problem.
int debug_level
debug_level
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
virtual ~meilp_solver()
virtual destructor
int * int_buffer
indexes in the constraint buffer
void set_debug_level(int dl)
Set the verbosity (debug_level)
virtual void print_to_file(const std::string &file_name)=0
Print the problem.
Base class providing several methods to encapsulate the interface to several ilp solver.
virtual void set_all_bounds()=0
Set the lower and upper of the variables using lower_bounds and upper_bounds.
supported_solvers
List of currently supported solvers.
virtual void set_int(int i)=0
Set a variable to have only integer values.
virtual void get_vars_solution(std::map< int, double > &vars) const =0
Return the solution of the problem.
Template definition of refcount.
static meilp_solverRef create_solver(supported_solvers solver_type)
Factory static member function.
Greater then.
virtual int add_empty_column()=0
Add an empty column ???
virtual void print(std::ostream &os)=0
Print the problem.
size_t nel
number of elements in the constraint buffer
virtual void make(int nvars)=0
???
int MAX_time
Time-out value.
virtual int get_number_constraints() const =0
Return the number of constraints.
ilp_sign
Possible operator in constraints.
double * real_buffer
values in the constraint buffer
virtual void set_col_name(int var, const std::string &name)=0
Set name of a variable (column)
virtual void set_lowbo(int var, double bound)
Set lower bound of a variable.

Generated on Mon Feb 12 2024 13:02:54 for PandA-2024.02 by doxygen 1.8.13