Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SoplexLpSolver.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <type_traits>
6// To detect whether the usage of Soplex is possible, this include is neccessary.
7#include "storm-config.h"
8
9#ifdef STORM_HAVE_SOPLEX
10#include "soplex.h"
11#endif
12
13namespace storm::solver {
14
15template<typename ValueType, bool RawMode = false>
16class SoplexLpSolver : public LpSolver<ValueType, RawMode> {
17 public:
29 SoplexLpSolver(std::string const& name, OptimizationDirection const& optDir);
30
37 SoplexLpSolver(std::string const& name);
38
45 SoplexLpSolver(OptimizationDirection const& optDir = OptimizationDirection::Minimize);
46
52
56 virtual ~SoplexLpSolver();
57
58 // Methods to add variables.
59 virtual Variable addVariable(std::string const& name, VariableType const& type, std::optional<ValueType> const& lowerBound = std::nullopt,
60 std::optional<ValueType> const& upperBound = std::nullopt, ValueType objectiveFunctionCoefficient = 0) override;
61
62 // Methods to incorporate recent changes.
63 virtual void update() const override;
64
65 // Methods to add constraints
66 virtual void addConstraint(std::string const& name, Constraint const& constraint) override;
67 virtual void addIndicatorConstraint(std::string const& name, Variable indicatorVariable, bool indicatorValue, Constraint const& constraint) override;
68
69 // Methods to optimize and retrieve optimality status.
70 virtual void optimize() const override;
71 virtual bool isInfeasible() const override;
72 virtual bool isUnbounded() const override;
73 virtual bool isOptimal() const override;
74
75 // Methods to retrieve values of variables and the objective function in the optimal solutions.
76 virtual ValueType getContinuousValue(Variable const& name) const override;
77 virtual ValueType getObjectiveValue() const override;
78 // Methods to print the LP problem to a file.
79 virtual void writeModelToFile(std::string const& filename) const override;
80
81 virtual void push() override;
82 virtual void pop() override;
83
85 // MILP related methods not supported by SoPlex
87 virtual void setMaximalMILPGap(ValueType const& gap, bool relative) override;
88 virtual ValueType getMILPGap(bool relative) const override;
89 virtual int_fast64_t getIntegerValue(Variable const& name) const override;
90 virtual bool getBinaryValue(Variable const& name) const override;
91
92 private:
93 void ensureSolved() const;
94
95#ifdef STORM_HAVE_SOPLEX
96 typedef std::conditional_t<std::is_same_v<ValueType, double>, soplex::DVector, soplex::DVectorRational> TypedDVector;
97 typedef std::conditional_t<std::is_same_v<ValueType, double>, soplex::DSVector, soplex::DSVectorRational> TypedDSVector;
98
99 uint64_t nextVariableIndex = 0;
100 uint64_t nextConstraintIndex = 0;
101 // Mutable because signature requires optimize to be const...
102 mutable soplex::SoPlex solver;
103
104 mutable soplex::SPxSolver::Status status;
105
106 //
107 mutable TypedDVector primalSolution;
108
109 // Variables;
110 TypedDSVector variables = TypedDSVector(0);
111 // A mapping from variables to their indices.
112 std::map<storm::expressions::Variable, uint64_t> variableToIndexMap;
113#endif
114};
115} // namespace storm::solver
An interface that captures the functionality of an LP solver.
Definition LpSolver.h:51
std::conditional_t< RawMode, RawLpConstraint< ValueType >, storm::expressions::Expression > Constraint
Definition LpSolver.h:55
std::conditional_t< RawMode, ValueType, storm::expressions::Expression > Constant
Definition LpSolver.h:54
std::conditional_t< RawMode, typename RawLpConstraint< ValueType >::VariableIndexType, storm::expressions::Variable > Variable
Definition LpSolver.h:53
VariableType
Enumerates the different types of variables.
Definition LpSolver.h:60
typename LpSolver< ValueType, RawMode >::Variable Variable
virtual void pop() override
Pops a backtracking point from the solver's stack.
virtual ValueType getMILPGap(bool relative) const override
Returns the obtained gap after a call to optimize()
virtual ValueType getObjectiveValue() const override
Retrieves the value of the objective function.
virtual int_fast64_t getIntegerValue(Variable const &name) const override
Retrieves the value of the integer variable with the given name.
virtual void addIndicatorConstraint(std::string const &name, Variable indicatorVariable, bool indicatorValue, Constraint const &constraint) override
Adds the given indicator constraint to the LP problem: "If indicatorVariable == indicatorValue,...
virtual bool isInfeasible() const override
Retrieves whether the model was found to be infeasible.
typename LpSolver< ValueType, RawMode >::VariableType VariableType
virtual bool isOptimal() const override
Retrieves whether the model was found to be optimal, i.e.
virtual void writeModelToFile(std::string const &filename) const override
Writes the current LP problem to the given file.
virtual bool isUnbounded() const override
Retrieves whether the model was found to be infeasible.
typename LpSolver< ValueType, RawMode >::Constant Constant
SoplexLpSolver(SoplexLpSolver< ValueType > const &other)
Creates a (deep) copy of this solver.
virtual void push() override
Pushes a backtracking point on the solver's stack.
virtual ~SoplexLpSolver()
Destructs a solver by freeing the pointers to Gurobi's structures.
virtual ValueType getContinuousValue(Variable const &name) const override
Retrieves the value of the continuous variable with the given name.
virtual Variable addVariable(std::string const &name, VariableType const &type, std::optional< ValueType > const &lowerBound=std::nullopt, std::optional< ValueType > const &upperBound=std::nullopt, ValueType objectiveFunctionCoefficient=0) override
Registers a variable of the given type.
virtual void addConstraint(std::string const &name, Constraint const &constraint) override
Adds a the given constraint to the LP problem.
virtual void update() const override
Updates the model to make the variables that have been declared since the last call to update usable.
virtual void optimize() const override
Optimizes the LP problem previously constructed.
virtual void setMaximalMILPGap(ValueType const &gap, bool relative) override
Specifies the maximum difference between lower- and upper objective bounds that triggers termination.
typename LpSolver< ValueType, RawMode >::Constraint Constraint
virtual bool getBinaryValue(Variable const &name) const override
Retrieves the value of the binary variable with the given name.