4#include "downward/lp/solver_interface.h"
6#include "downward/algorithms/named_vector.h"
14enum class LPSolverType { CPLEX, SOPLEX };
16enum class LPObjectiveSense { MAXIMIZE, MINIMIZE };
21 std::vector<int> variables;
22 std::vector<double> coefficients;
27 LPConstraint(
double lower_bound,
double upper_bound);
29 const std::vector<int>& get_variables()
const {
return variables; }
30 const std::vector<double>& get_coefficients()
const {
return coefficients; }
32 double get_lower_bound()
const {
return lower_bound; }
33 void set_lower_bound(
double lb) { lower_bound = lb; }
34 double get_upper_bound()
const {
return upper_bound; }
35 void set_upper_bound(
double ub) { upper_bound = ub; }
40 void insert(
int index,
double coefficient);
41 double remove(
int index);
44 dump(std::ostream& stream,
const LinearProgram* program =
nullptr)
const;
50 double objective_coefficient;
56 double objective_coefficient,
57 bool is_integer =
false);
61 LPObjectiveSense sense;
62 std::string objective_name;
64 named_vector::NamedVector<LPVariable> variables;
65 named_vector::NamedVector<LPConstraint> constraints;
72 LPObjectiveSense sense,
73 named_vector::NamedVector<LPVariable>&& variables,
74 named_vector::NamedVector<LPConstraint>&& constraints,
77 , variables(
std::move(variables))
78 , constraints(
std::move(constraints))
88 named_vector::NamedVector<LPVariable>& get_variables();
89 named_vector::NamedVector<LPConstraint>& get_constraints();
90 const named_vector::NamedVector<LPVariable>& get_variables()
const;
91 const named_vector::NamedVector<LPConstraint>& get_constraints()
const;
92 double get_infinity()
const;
93 LPObjectiveSense get_sense()
const;
94 void set_objective_name(
const std::string& name);
95 const std::string& get_objective_name()
const;
99 std::unique_ptr<SolverInterface> pimpl;
102 explicit LPSolver(LPSolverType solver_type);
104 void load_problem(
const LinearProgram& lp);
105 void add_temporary_constraints(
106 const named_vector::NamedVector<LPConstraint>& constraints);
107 void clear_temporary_constraints();
108 double get_infinity()
const;
110 void set_objective_coefficients(
const std::vector<double>& coefficients);
111 void set_objective_coefficient(
int index,
double coefficient);
112 void set_constraint_lower_bound(
int index,
double bound);
113 void set_constraint_upper_bound(
int index,
double bound);
114 void set_variable_lower_bound(
int index,
double bound);
115 void set_variable_upper_bound(
int index,
double bound);
117 void set_mip_gap(
double gap);
120 void write_lp(
const std::string& filename)
const;
121 void print_failure_analysis()
const;
122 bool is_infeasible()
const;
123 bool is_unbounded()
const;
132 bool has_optimal_solution()
const;
139 double get_objective_value()
const;
147 std::vector<double> extract_solution()
const;
149 int get_num_variables()
const;
150 int get_num_constraints()
const;
151 int has_temporary_constraints()
const;
152 void print_statistics()
const;
158 std::vector<double> extract_dual_solution()
const;
161 const LPVariable& var,
162 const std::vector<int>& constraint_ids,
163 const std::vector<double>& coefficients,
164 std::string_view name =
"");
166 void add_constraint(
const LPConstraint& constraint, std::string_view =
"");