delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
QsoptexLpSolver.h
1
7#pragma once
8
9#ifndef DELPI_ENABLED_QSOPTEX
10#error QSopt_ex is not enabled. Please enable it by adding "--//tools:enable_qsoptex" to the bazel command.
11#endif
12
13#include <string>
14#include <utility>
15#include <vector>
16
17#include "delpi/libs/gmp.h"
18#include "delpi/libs/qsopt_ex.h"
19#include "delpi/solver/LpSolver.h"
20#include "delpi/symbolic/Expression.h"
21#include "delpi/symbolic/Variable.h"
22#include "delpi/util/concepts.h"
23
24namespace delpi {
25
29class QsoptexLpSolver final : public LpSolver {
30 public:
31 explicit QsoptexLpSolver(Config config = {}, const std::string& class_name = "QsoptexLpSolver");
32 ~QsoptexLpSolver() override;
33
34 [[nodiscard]] int num_columns() const override;
35 [[nodiscard]] int num_rows() const override;
36
37 [[nodiscard]] Column column(int column_idx) const override;
38 [[nodiscard]] Row row(int row_idx) const override;
39 ColumnIndex AddColumn(const Variable& var, const mpq_class& obj, const mpq_class& lb, const mpq_class& ub) override;
40 RowIndex AddRow(const std::vector<Expression::Addend>& addends, const mpq_class& lb, const mpq_class& ub) override;
41 RowIndex AddRow(const Expression::Addends& lhs, FormulaKind sense, const mpq_class& rhs) override;
42 void SetBound(Variable var, const mpq_class& lb, const mpq_class& ub) override;
43 void SetCoefficient(RowIndex row, ColumnIndex column, const mpq_class& value) override;
44 void SetObjective(int column, const mpq_class& value) override;
45
51 void UpdateStats(unsigned int precision);
52
53#ifndef NDEBUG
54 void Dump() final;
55#endif
56
57 private:
58 LpResult SolveCore() override;
59
60 template <TypedIterable<std::pair<const Variable, mpq_class>> T>
61 int AddRow(const T& addends, char sense, const mpq_class& rhs);
68 template <TypedIterable<std::pair<const Variable, mpq_class>> T>
69 void SetRowCoeff(int row, const T& literal_monomials);
76 void SetVarCoeff(int row, const Variable& var, const mpq_class& value) const;
77
84 void UpdateFeasible();
85
86 protected:
87 void EnsureSenseCore() override;
88
89 private:
90#if 0
103 void UpdateInfeasible();
104#endif
105
106 mpq_QSprob qsx_;
107 QSbasis basis_;
108
111};
112
113} // namespace delpi
Simple dataclass used to store the configuration of the program.
Definition Config.h:36
const Variable & var(const int column) const
Shorthand notation to get the real variable linked with column column.
Definition LpSolver.h:205
LpSolver(mpq_class ninfinity, mpq_class infinity, Config config={}, const std::string &class_name="LpSolver")
Construct a new LpSolver object with the given config.
Definition LpSolver.cpp:41
void SetObjective(int column, const mpq_class &value) override
The the objective coefficient of the given column to the given value.
void SetRowCoeff(int row, const T &literal_monomials)
Parse a sequence of literal_monomials and set the coefficient for each decisional variable appearing ...
void UpdateFeasible()
Use the result from the lp solver to update the solution vector and objective value.
qsopt_ex::MpqArray ray_
Ray of the last infeasible solution.
void UpdateStats(unsigned int precision)
Update the lp stats from the QSopt_ex solver.
void SetVarCoeff(int row, const Variable &var, const mpq_class &value) const
Set the coefficients to apply to var on a specific row.
void EnsureSenseCore() override
Make sure the LP solvers are aware of the sense of the LP problem (minimisation or maximisation).
ColumnIndex AddColumn(const Variable &var, const mpq_class &obj, const mpq_class &lb, const mpq_class &ub) override
Add a new bounded column to the LP problem, ensuring that the variable var is in the range and has t...
void SetBound(Variable var, const mpq_class &lb, const mpq_class &ub) override
Set the bounds of a var in the LP problem to the given lb and ub.
void SetCoefficient(RowIndex row, ColumnIndex column, const mpq_class &value) override
Set the coefficient of the row constraint to apply at the column decisional variable.
QSbasis basis_
Last basis.
qsopt_ex::MpqArray x_
Solution vector.
mpq_QSprob qsx_
QSopt_ex LP solver.
Column column(int column_idx) const override
Get the column at the given column_idx index.
LpResult SolveCore() override
Internal method that optimises the LP problem with the given delta.
Row row(int row_idx) const override
Get the row at the given row_idx index.
Real symbolic variable.
Definition Variable.h:20
A wrapper around an array of mpq_t elements.
Definition qsopt_ex.h:66
Global namespace for the delpi library.
LpResult
Possible outcomes of the LP solver.
Definition LpResult.h:14
FormulaKind
Kinds of symbolic formulas.
Definition FormulaKind.h:14
Convenient structure representing a column in the LP solver.
Definition Column.h:23
Structure representing a row in the LP solver in the form of a linear combination of variables.
Definition Row.h:24