AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
solver_interface.h
1#ifndef LP_SOLVER_INTERFACE_H
2#define LP_SOLVER_INTERFACE_H
3
4#include <string>
5#include <string_view>
6#include <vector>
7
8namespace named_vector {
9template <typename T>
10class NamedVector;
11}
12
13namespace lp {
14class LinearProgram;
15struct LPVariable;
16class LPConstraint;
17
18class SolverInterface {
19public:
20 virtual ~SolverInterface() = default;
21
22 virtual void load_problem(const LinearProgram& lp) = 0;
23 virtual void add_temporary_constraints(
24 const named_vector::NamedVector<LPConstraint>& constraints) = 0;
25 virtual void clear_temporary_constraints() = 0;
26 virtual double get_infinity() const = 0;
27
28 virtual void
29 set_objective_coefficients(const std::vector<double>& coefficients) = 0;
30 virtual void set_objective_coefficient(int index, double coefficient) = 0;
31 virtual void set_constraint_lower_bound(int index, double bound) = 0;
32 virtual void set_constraint_upper_bound(int index, double bound) = 0;
33 virtual void set_variable_lower_bound(int index, double bound) = 0;
34 virtual void set_variable_upper_bound(int index, double bound) = 0;
35
36 virtual void set_mip_gap(double gap) = 0;
37
38 virtual void solve() = 0;
39 virtual void write_lp(const std::string& filename) const = 0;
40 virtual void print_failure_analysis() const = 0;
41 virtual bool is_infeasible() const = 0;
42 virtual bool is_unbounded() const = 0;
43
44 /*
45 Return true if the solving the LP showed that it is bounded feasible and
46 the discovered solution is guaranteed to be optimal. We test for
47 optimality explicitly because solving the LP sometimes finds suboptimal
48 solutions due to numerical difficulties.
49 The LP has to be solved with a call to solve() before calling this method.
50 */
51 virtual bool has_optimal_solution() const = 0;
52
53 /*
54 Return the objective value found after solving an LP.
55 The LP has to be solved with a call to solve() and has to have an optimal
56 solution before calling this method.
57 */
58 virtual double get_objective_value() const = 0;
59
60 /*
61 Return the solution found after solving an LP as a vector with one entry
62 per variable.
63 The LP has to be solved with a call to solve() and has to have an optimal
64 solution before calling this method.
65 */
66 virtual std::vector<double> extract_solution() const = 0;
67
68 virtual int get_num_variables() const = 0;
69 virtual int get_num_constraints() const = 0;
70 virtual bool has_temporary_constraints() const = 0;
71 virtual void print_statistics() const = 0;
72
73 virtual std::vector<double> extract_dual_solution() const = 0;
74
75 virtual void add_variable(
76 const LPVariable& var,
77 const std::vector<int>& constraints,
78 const std::vector<double>& coefficients,
79 std::string_view name = "") = 0;
80
81 virtual void add_constraint(
82 const LPConstraint& constraint,
83 std::string_view name = "") = 0;
84};
85} // namespace lp
86
87#endif