delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
SoplexLpSolver.h
1
7#pragma once
8
9#ifndef DELPI_ENABLED_SOPLEX
10#error SoPlex is not enabled. Please enable it by adding "--//tools:enable_soplex" 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/soplex.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 SoplexLpSolver final : public LpSolver {
30 public:
31 explicit SoplexLpSolver(Config config = {}, const std::string& class_name = "SoplexLpSolver");
32
33 [[nodiscard]] int num_columns() const override;
34 [[nodiscard]] int num_rows() const override;
35
36 [[nodiscard]] Column column(ColumnIndex column_idx) const override;
37 [[nodiscard]] Row row(RowIndex row_idx) const override;
38 void ReserveColumns(int num_columns) override;
39 void ReserveRows(int num_rows) override;
40 ColumnIndex AddColumn(const Variable& var, const mpq_class& obj, const mpq_class& lb, const mpq_class& ub) override;
41 RowIndex AddRow(const std::vector<Expression::Addend>& addends, const mpq_class& lb, const mpq_class& ub) override;
42 RowIndex AddRow(const Expression::Addends& lhs, FormulaKind sense, const mpq_class& rhs) override;
43 void SetBound(Variable var, const mpq_class& lb, const mpq_class& ub) override;
44 void SetCoefficient(RowIndex row, ColumnIndex column, const mpq_class& value) override;
45 void SetObjective(int column, const mpq_class& value) override;
46
47#ifndef NDEBUG
48 void Dump() override;
49#endif
50
51 private:
52 LpResult SolveCore() override;
58 template <TypedIterable<std::pair<const Variable, mpq_class>> T>
59 soplex::DSVectorRational ParseRowCoeff(const T& literal_monomials);
68 void SetVarCoeff(soplex::DSVectorRational& coeffs, const Variable& var, const mpq_class& value) const;
69
77 void UpdateFeasible(const soplex::Rational& max_violation);
78
79 protected:
80 void EnsureSenseCore() override;
81
82 private:
83#if 0
95 void UpdateInfeasible();
96#endif
97
99
100 soplex::SoPlex spx_;
101
102 soplex::LPColSetRational spx_cols_;
103 soplex::LPRowSetRational spx_rows_;
104
105 soplex::Rational rninfinity_;
106 soplex::Rational rinfinity_;
107};
108
109} // 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 SetCoefficient(RowIndex row, ColumnIndex column, const mpq_class &value) override
Set the coefficient of the row constraint to apply at the column decisional variable.
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...
soplex::SoPlex spx_
SoPlex LP solver.
soplex::DSVectorRational ParseRowCoeff(const T &literal_monomials)
Parse a sequence of literal_monomials and set the coefficient for each decisional variable appearing ...
void ReserveRows(int num_rows) override
Reserve space for the given number of rows.
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 EnsureSenseCore() override
Make sure the LP solvers are aware of the sense of the LP problem (minimisation or maximisation).
bool consolidated_
Whether the LP problem has been consolidated.
soplex::LPColSetRational spx_cols_
Columns of the LP problem.
void UpdateFeasible(const soplex::Rational &max_violation)
Use the result from the lp solver to update the solution vector and objective value.
void ReserveColumns(int num_columns) override
Reserve space for the given number of columns and rows.
void SetVarCoeff(soplex::DSVectorRational &coeffs, const Variable &var, const mpq_class &value) const
Set the coefficients to apply to var on a specific row.
Column column(ColumnIndex column_idx) const override
Get the column at the given column_idx index.
void SetObjective(int column, const mpq_class &value) override
The the objective coefficient of the given column to the given value.
LpResult SolveCore() override
Internal method that optimises the LP problem with the given delta.
soplex::Rational rninfinity_
Rational negative infinity.
Row row(RowIndex row_idx) const override
Get the row at the given row_idx index.
soplex::LPRowSetRational spx_rows_
Rows of the LP problem.
soplex::Rational rinfinity_
Rational positive infinity.
Real symbolic variable.
Definition Variable.h:20
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