lpinterface
 All Classes Namespaces Files Functions Variables Enumerations Enumerator
lphandle_gurobi.hpp
1 #ifndef LPINTERFACE_LPHANDLE_GUROBI_H
2 #define LPINTERFACE_LPHANDLE_GUROBI_H
3 
4 #include <cstddef>
5 #include <memory>
6 #include <type_traits>
7 #include <vector>
8 
9 #include "gurobi_c.h"
10 
11 #include "lpinterface/badge.hpp"
12 #include "lpinterface/gurobi/lputil_gurobi.hpp"
13 #include "lpinterface/lp.hpp"
14 
15 namespace lpint {
16 
17 class GurobiSolver;
18 
20  public:
22  std::shared_ptr<GRBmodel> grbmodel,
23  std::shared_ptr<GRBenv> grbenv)
24  : grb_env_(grbenv), grb_model_(grbmodel) {}
25 
26  std::size_t num_vars() const override;
27 
28  std::size_t num_constraints() const override;
29 
30  void set_objective_sense(const OptimizationType objsense) override;
31 
32  Variable variable(std::size_t i) const override;
33 
34  std::vector<Variable> variables() const override;
35 
36  void add_variables(const std::vector<Variable>& vars) override;
37 
38  void add_variables(const std::size_t num_vars) override;
39 
40  void add_constraints(
41  const std::vector<Constraint<double>>& constraints) override;
42 
43  void remove_variable(const std::size_t i) override;
44 
45  void remove_constraint(std::size_t i) override;
46 
47  OptimizationType optimization_type() const override;
48 
49  void set_objective(const Objective<double>& objective) override;
50 
51  virtual Constraint<double> constraint(std::size_t i) const override;
52 
53  std::vector<Constraint<double>> constraints() const override;
54 
55  Objective<double> objective() const override;
56 
57  std::shared_ptr<GRBmodel> gurobi_model(detail::Badge<GurobiSolver>) const;
58  std::shared_ptr<GRBenv> gurobi_env(detail::Badge<GurobiSolver>) const;
59 
60  // TODO: find a better way to do this!!!
61  void set_num_vars(detail::Badge<GurobiSolver>, std::size_t nvars) {
62  num_vars_ = nvars;
63  }
64 
65  private:
66  std::shared_ptr<GRBenv> grb_env_;
67  std::shared_ptr<GRBmodel> grb_model_;
68 
69  std::vector<double> upper_bounds;
70  std::vector<double> lower_bounds;
71 
72  std::size_t num_vars_ = 0;
73  std::size_t num_constraints_ = 0;
74 };
75 
76 } // namespace lpint
77 
78 #endif // LPINTERFACE_LPHANDLE_GUROBI_H
Struct to represent right-hand side of LP constraints. In linear programming, we have constraints of ...
Definition: data_objects.hpp:192
std::vector< Constraint< double > > constraints() const override
Retrieve the constraints of the internal LP. This method requests the constraints from the internal L...
void set_objective(const Objective< double > &objective) override
Set the objective function to be used. This method must be called before calling add_constraints().
OptimizationType
Objective sense for an LP.
Definition: lp.hpp:17
Interface representing linear program formulation. This interface represents linear programs of the f...
Definition: lp.hpp:53
std::size_t num_vars() const override
Get the number of variables in the LP.
std::vector< Variable > variables() const override
Retrieve the variables from the internal LP solver.
void set_objective_sense(const OptimizationType objsense) override
Set the objective sense of this ILinearProgramHandle. The Optimization type can be either Optimizatio...
Objective< double > objective() const override
Retrieve the objective function of the internal LP. This method requests the objective function value...
OptimizationType optimization_type() const override
Retrieve the objective sense of this ILinearProgramHandle. The Optimization type can be either Optimi...
virtual Constraint< double > constraint(std::size_t i) const override
Retrieve constraint i of the internal LP. This method requests a constraint from the internal LP solv...
Definition: badge.hpp:9
Class representing a variable in the LP.
Definition: data_objects.hpp:253
Struct representing the objective vector. A linear program has the canonical form This structure rep...
Definition: data_objects.hpp:223
Definition: lphandle_gurobi.hpp:19
void add_variables(const std::vector< Variable > &vars) override
Add variables to the LP.
Variable variable(std::size_t i) const override
Retrieve variable i from the internal LP solver.
void remove_constraint(std::size_t i) override
Remove a constraint from the LP.
std::size_t num_constraints() const override
Get the number of cosntraints in the LP.
void add_constraints(const std::vector< Constraint< double >> &constraints) override
Add a set of constraints to the LP formulation. This can only be called after calling set_objective()...
void remove_variable(const std::size_t i) override
Remove a variable from the LP.