lpinterface
 All Classes Namespaces Files Functions Variables Enumerations Enumerator
lp.hpp
Go to the documentation of this file.
1 
2 #ifndef LPINTERFACE_LP_H
3 #define LPINTERFACE_LP_H
4 
5 #include <iostream>
6 #include <vector>
7 
8 #include "data_objects.hpp"
9 #include "errors.hpp"
10 
11 #include "common.hpp"
12 
14 namespace lpint {
15 
17 enum class OptimizationType {
19  Minimize,
21  Maximize,
22 };
23 
24 // LCOV_EXCL_START
25 inline std::ostream& operator<<(std::ostream& os, const OptimizationType ot) {
26  switch (ot) {
28  os << "Maximize";
29  break;
31  os << "Minimize";
32  break;
33  default:
34  // TODO: make a more descriptive exception
35  // for this case
36  throw UnsupportedFeatureException();
37  }
38  return os;
39 }
40 // LCOV_EXCL_STOP
41 
54  public:
55  ILinearProgramHandle() = default;
58  ILinearProgramHandle& operator=(const ILinearProgramHandle&) = default;
59  ILinearProgramHandle& operator=(ILinearProgramHandle&&) = default;
60 
61  virtual ~ILinearProgramHandle() = default;
62 
66  virtual std::size_t num_vars() const = 0;
67 
71  virtual std::size_t num_constraints() const = 0;
72 
79  virtual void set_objective_sense(const OptimizationType objsense) = 0;
80 
87  virtual Variable variable(std::size_t i) const = 0;
88 
94  virtual std::vector<Variable> variables() const = 0;
95 
101  virtual void add_variables(const std::vector<Variable>& vars) = 0;
102 
107  virtual void add_variables(const std::size_t num_vars) = 0;
108 
113  virtual void add_constraints(
114  const std::vector<Constraint<double>>& constraints) = 0;
115 
121  virtual void remove_constraint(const std::size_t i) = 0;
122 
128  virtual void remove_variable(const std::size_t i) = 0;
129 
136  virtual OptimizationType optimization_type() const = 0;
137 
142  virtual void set_objective(const Objective<double>& objective) = 0;
143 
155  virtual Constraint<double> constraint(std::size_t i) const = 0;
156 
167  virtual std::vector<Constraint<double>> constraints() const = 0;
168 
179  virtual Objective<double> objective() const = 0;
180 };
181 
182 } // namespace lpint
183 
184 #endif // LPINTERFACE_LP_H
virtual std::vector< Constraint< double > > constraints() const =0
Retrieve the constraints of the internal LP. This method requests the constraints from the internal L...
Struct to represent right-hand side of LP constraints. In linear programming, we have constraints of ...
Definition: data_objects.hpp:192
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
virtual void set_objective_sense(const OptimizationType objsense)=0
Set the objective sense of this ILinearProgramHandle. The Optimization type can be either Optimizatio...
virtual std::size_t num_vars() const =0
Get the number of variables in the LP.
virtual Constraint< double > constraint(std::size_t i) const =0
Retrieve constraint i of the internal LP. This method requests a constraint from the internal LP solv...
Minimize the objective function value.
virtual void set_objective(const Objective< double > &objective)=0
Set the objective function to be used. This method must be called before calling add_constraints().
virtual Variable variable(std::size_t i) const =0
Retrieve variable i from the internal LP solver.
Maximize the objective function value.
virtual void add_constraints(const std::vector< Constraint< double >> &constraints)=0
Add a set of constraints to the LP formulation. This can only be called after calling set_objective()...
virtual Objective< double > objective() const =0
Retrieve the objective function of the internal LP. This method requests the objective function value...
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
virtual std::vector< Variable > variables() const =0
Retrieve the variables from the internal LP solver.
virtual void add_variables(const std::vector< Variable > &vars)=0
Add variables to the LP.
virtual void remove_constraint(const std::size_t i)=0
Remove a constraint from the LP.
virtual std::size_t num_constraints() const =0
Get the number of cosntraints in the LP.
virtual OptimizationType optimization_type() const =0
Retrieve the objective sense of this ILinearProgramHandle. The Optimization type can be either Optimi...
virtual void remove_variable(const std::size_t i)=0
Remove a variable from the LP.