Storm
A Modern Probabilistic Model Checker
|
An interface that captures the functionality of an LP solver. More...
#include <LpSolver.h>
Public Types | |
enum class | VariableType { Continuous , Integer , Binary } |
Enumerates the different types of variables. More... | |
using | Variable = std::conditional_t< RawMode, typename RawLpConstraint< ValueType >::VariableIndexType, storm::expressions::Variable > |
using | Constant = std::conditional_t< RawMode, ValueType, storm::expressions::Expression > |
using | Constraint = std::conditional_t< RawMode, RawLpConstraint< ValueType >, storm::expressions::Expression > |
Public Member Functions | |
LpSolver () | |
Creates an empty LP solver. | |
LpSolver (OptimizationDirection const &optDir) | |
Creates an empty LP solver with the given model sense. | |
virtual | ~LpSolver ()=default |
Variable | addBoundedContinuousVariable (std::string const &name, ValueType lowerBound, ValueType upperBound, ValueType objectiveFunctionCoefficient=0) |
Registers an upper- and lower-bounded continuous variable, i.e. | |
Variable | addLowerBoundedContinuousVariable (std::string const &name, ValueType lowerBound, ValueType objectiveFunctionCoefficient=0) |
Registers a lower-bounded continuous variable, i.e. | |
Variable | addUpperBoundedContinuousVariable (std::string const &name, ValueType upperBound, ValueType objectiveFunctionCoefficient=0) |
Registers an upper-bounded continuous variable, i.e. | |
Variable | addUnboundedContinuousVariable (std::string const &name, ValueType objectiveFunctionCoefficient=0) |
Registers a unbounded continuous variable, i.e. | |
Variable | addContinuousVariable (std::string const &name, std::optional< ValueType > const &lowerBound=std::nullopt, std::optional< ValueType > const &upperBound=std::nullopt, ValueType objectiveFunctionCoefficient=0) |
Registers a continuous variable, i.e. | |
Variable | addBoundedIntegerVariable (std::string const &name, ValueType lowerBound, ValueType upperBound, ValueType objectiveFunctionCoefficient=0) |
Registers an upper- and lower-bounded integer variable, i.e. | |
Variable | addLowerBoundedIntegerVariable (std::string const &name, ValueType lowerBound, ValueType objectiveFunctionCoefficient=0) |
Registers a lower-bounded integer variable, i.e. | |
Variable | addUpperBoundedIntegerVariable (std::string const &name, ValueType upperBound, ValueType objectiveFunctionCoefficient=0) |
Registers an upper-bounded integer variable, i.e. | |
Variable | addUnboundedIntegerVariable (std::string const &name, ValueType objectiveFunctionCoefficient=0) |
Registers an unbounded integer variable, i.e. | |
Variable | addIntegerVariable (std::string const &name, std::optional< ValueType > const &lowerBound=std::nullopt, std::optional< ValueType > const &upperBound=std::nullopt, ValueType objectiveFunctionCoefficient=0) |
Registers an integer variable, i.e. | |
Variable | addBinaryVariable (std::string const &name, ValueType objectiveFunctionCoefficient=0) |
Registers a boolean variable, i.e. | |
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)=0 |
Registers a variable of the given type. | |
Constant | getConstant (ValueType value) const |
Retrieves an expression that characterizes the given constant value. | |
virtual void | update () const =0 |
Updates the model to make the variables that have been declared since the last call to update usable. | |
virtual void | addConstraint (std::string const &name, Constraint const &constraint)=0 |
Adds a the given constraint to the LP problem. | |
virtual void | addIndicatorConstraint (std::string const &name, Variable indicatorVariable, bool indicatorValue, Constraint const &constraint)=0 |
Adds the given indicator constraint to the LP problem: "If indicatorVariable == indicatorValue, then constraint". | |
virtual void | optimize () const =0 |
Optimizes the LP problem previously constructed. | |
virtual bool | isInfeasible () const =0 |
Retrieves whether the model was found to be infeasible. | |
virtual bool | isUnbounded () const =0 |
Retrieves whether the model was found to be infeasible. | |
virtual bool | isOptimal () const =0 |
Retrieves whether the model was found to be optimal, i.e. | |
virtual int_fast64_t | getIntegerValue (Variable const &variable) const =0 |
Retrieves the value of the integer variable with the given name. | |
virtual bool | getBinaryValue (Variable const &variable) const =0 |
Retrieves the value of the binary variable with the given name. | |
virtual ValueType | getContinuousValue (Variable const &variable) const =0 |
Retrieves the value of the continuous variable with the given name. | |
virtual ValueType | getObjectiveValue () const =0 |
Retrieves the value of the objective function. | |
virtual void | writeModelToFile (std::string const &filename) const =0 |
Writes the current LP problem to the given file. | |
void | setOptimizationDirection (OptimizationDirection const &optimizationDirection) |
Sets whether the objective function of this model is to be minimized or maximized. | |
OptimizationDirection | getOptimizationDirection () const |
Retrieves whether the objective function of this model is to be minimized or maximized. | |
storm::expressions::ExpressionManager const & | getManager () const |
Retrieves the manager for the variables created for this solver. | |
virtual void | push ()=0 |
Pushes a backtracking point on the solver's stack. | |
virtual void | pop ()=0 |
Pops a backtracking point from the solver's stack. | |
virtual void | setMaximalMILPGap (ValueType const &gap, bool relative)=0 |
Specifies the maximum difference between lower- and upper objective bounds that triggers termination. | |
virtual ValueType | getMILPGap (bool relative) const =0 |
Returns the obtained gap after a call to optimize() | |
Protected Member Functions | |
storm::expressions::Variable | declareOrGetExpressionVariable (std::string const &name, VariableType const &type) |
Protected Attributes | |
std::shared_ptr< storm::expressions::ExpressionManager > | manager |
bool | currentModelHasBeenOptimized |
An interface that captures the functionality of an LP solver.
RawMode | If set, variables are given as indices and constraints as RawConstraints. This avoids overhead introduced by storm::expression's |
Definition at line 51 of file LpSolver.h.
using storm::solver::LpSolver< ValueType, RawMode >::Constant = std::conditional_t<RawMode, ValueType, storm::expressions::Expression> |
Definition at line 54 of file LpSolver.h.
using storm::solver::LpSolver< ValueType, RawMode >::Constraint = std::conditional_t<RawMode, RawLpConstraint<ValueType>, storm::expressions::Expression> |
Definition at line 55 of file LpSolver.h.
using storm::solver::LpSolver< ValueType, RawMode >::Variable = std::conditional_t<RawMode, typename RawLpConstraint<ValueType>::VariableIndexType, storm::expressions::Variable> |
Definition at line 53 of file LpSolver.h.
|
strong |
Enumerates the different types of variables.
Enumerator | |
---|---|
Continuous | |
Integer | |
Binary |
Definition at line 60 of file LpSolver.h.
storm::solver::LpSolver< ValueType, RawMode >::LpSolver | ( | ) |
Creates an empty LP solver.
By default the objective function is assumed to be minimized.
Definition at line 26 of file LpSolver.cpp.
storm::solver::LpSolver< ValueType, RawMode >::LpSolver | ( | OptimizationDirection const & | optDir | ) |
Creates an empty LP solver with the given model sense.
optDir | A value indicating whether the objective function of this model is to be minimized or maximized. |
Definition at line 32 of file LpSolver.cpp.
|
virtualdefault |
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addBinaryVariable | ( | std::string const & | name, |
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers a boolean variable, i.e.
a variable that may be either 0 or 1.
name | The name of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 103 of file LpSolver.cpp.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addBoundedContinuousVariable | ( | std::string const & | name, |
ValueType | lowerBound, | ||
ValueType | upperBound, | ||
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers an upper- and lower-bounded continuous variable, i.e.
a variable that may take all real values within its bounds.
name | The name of the variable. |
lowerBound | The lower bound of the variable. |
upperBound | The upper bound of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 38 of file LpSolver.cpp.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addBoundedIntegerVariable | ( | std::string const & | name, |
ValueType | lowerBound, | ||
ValueType | upperBound, | ||
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers an upper- and lower-bounded integer variable, i.e.
a variable that may take all integer values within its bounds.
name | The name of the variable. |
lowerBound | The lower bound of the variable. |
upperBound | The upper bound of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 71 of file LpSolver.cpp.
|
pure virtual |
Adds a the given constraint to the LP problem.
name | The name of the constraint. If empty, the constraint has no name. |
constraint | An expression that represents the constraint. The given constraint must be a linear (in)equality over the registered variables. |
Implemented in storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addContinuousVariable | ( | std::string const & | name, |
std::optional< ValueType > const & | lowerBound = std::nullopt , |
||
std::optional< ValueType > const & | upperBound = std::nullopt , |
||
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers a continuous variable, i.e.
a variable that may take all real values within its bounds (if given).
name | The name of the variable. |
lowerBound | The lower bound of the variable (unbounded if not given). |
upperBound | The upper bound of the variable (unbounded if not given). |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 63 of file LpSolver.cpp.
|
pure virtual |
Adds the given indicator constraint to the LP problem: "If indicatorVariable == indicatorValue, then constraint".
name | The name of the constraint. If empty, the constraint has no name. |
indicatorVariable | must be a registered binary |
indicatorValue | |
constraint | An expression that represents the constraint. The given constraint must be a linear (in)equality over the registered variables. |
Implemented in storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addIntegerVariable | ( | std::string const & | name, |
std::optional< ValueType > const & | lowerBound = std::nullopt , |
||
std::optional< ValueType > const & | upperBound = std::nullopt , |
||
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers an integer variable, i.e.
a variable that may take all integer values within its bounds (if given).
name | The name of the variable. |
lowerBound | The lower bound of the variable. |
upperBound | The upper bound of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 96 of file LpSolver.cpp.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addLowerBoundedContinuousVariable | ( | std::string const & | name, |
ValueType | lowerBound, | ||
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers a lower-bounded continuous variable, i.e.
a variable that may take all real values up to its lower bound.
name | The name of the variable. |
lowerBound | The lower bound of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 45 of file LpSolver.cpp.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addLowerBoundedIntegerVariable | ( | std::string const & | name, |
ValueType | lowerBound, | ||
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers a lower-bounded integer variable, i.e.
a variable that may take all integer values up to its lower bound.
name | The name of the variable. |
lowerBound | The lower bound of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 78 of file LpSolver.cpp.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addUnboundedContinuousVariable | ( | std::string const & | name, |
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers a unbounded continuous variable, i.e.
a variable that may take all real values.
name | The name of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 57 of file LpSolver.cpp.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addUnboundedIntegerVariable | ( | std::string const & | name, |
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers an unbounded integer variable, i.e.
a variable that may take all integer values.
name | The name of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 90 of file LpSolver.cpp.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addUpperBoundedContinuousVariable | ( | std::string const & | name, |
ValueType | upperBound, | ||
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers an upper-bounded continuous variable, i.e.
a variable that may take all real values up to its upper bound.
name | The name of the variable. |
upperBound | The upper bound of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 51 of file LpSolver.cpp.
LpSolver< ValueType, RawMode >::Variable storm::solver::LpSolver< ValueType, RawMode >::addUpperBoundedIntegerVariable | ( | std::string const & | name, |
ValueType | upperBound, | ||
ValueType | objectiveFunctionCoefficient = 0 |
||
) |
Registers an upper-bounded integer variable, i.e.
a variable that may take all integer values up to its lower bound.
name | The name of the variable. |
upperBound | The upper bound of the variable. |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Definition at line 84 of file LpSolver.cpp.
|
pure virtual |
Registers a variable of the given type.
name | The name of the variable. |
type | The type of the variable |
lowerBound | The optional lower bound |
upperBound | The optional upper bound |
objectiveFunctionCoefficient | The coefficient with which the variable appears in the objective function. If omitted (or set to zero), the variable is irrelevant for the objective value. |
Implemented in storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
protected |
Definition at line 137 of file LpSolver.cpp.
|
pure virtual |
Retrieves the value of the binary variable with the given name.
Note that this may only be called, if the model was found to be optimal, i.e. iff isOptimal() returns true.
variable | The variable whose integer value (in the optimal solution) to retrieve. |
Implemented in storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
LpSolver< ValueType, RawMode >::Constant storm::solver::LpSolver< ValueType, RawMode >::getConstant | ( | ValueType | value | ) | const |
Retrieves an expression that characterizes the given constant value.
In RawMode, this just returns the given value
value | The value of the constant. |
Definition at line 109 of file LpSolver.cpp.
|
pure virtual |
Retrieves the value of the continuous variable with the given name.
Note that this may only be called, if the model was found to be optimal, i.e. iff isOptimal() returns true.
variable | The variable whose integer value (in the optimal solution) to retrieve. |
Implemented in storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Retrieves the value of the integer variable with the given name.
Note that this may only be called, if the model was found to be optimal, i.e. iff isOptimal() returns true.
variable | The variable whose integer value (in the optimal solution) to retrieve. |
Implemented in storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
storm::expressions::ExpressionManager const & storm::solver::LpSolver< ValueType, RawMode >::getManager | ( | ) | const |
Retrieves the manager for the variables created for this solver.
Definition at line 131 of file LpSolver.cpp.
|
pure virtual |
Returns the obtained gap after a call to optimize()
Implemented in storm::solver::GlpkLpSolver, storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Retrieves the value of the objective function.
Note that this may only be called, if the model was found to be optimal, i.e. iff isOptimal() returns true.
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
OptimizationDirection storm::solver::LpSolver< ValueType, RawMode >::getOptimizationDirection | ( | ) | const |
Retrieves whether the objective function of this model is to be minimized or maximized.
Definition at line 126 of file LpSolver.cpp.
|
pure virtual |
Retrieves whether the model was found to be infeasible.
This can only be called after the model has been optimized and not modified afterwards. Otherwise, an exception is thrown.
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Retrieves whether the model was found to be optimal, i.e.
neither infeasible nor unbounded. This can only be called after the model has been optimized and not modified afterwards. Otherwise, an exception is thrown.
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Retrieves whether the model was found to be infeasible.
This can only be called after the model has been optimized and not modified afterwards. Otherwise, an exception is thrown.
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Optimizes the LP problem previously constructed.
Afterwards, the methods isInfeasible, isUnbounded and isOptimal can be used to query the optimality status.
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Pops a backtracking point from the solver's stack.
This deletes all assertions from the solver's stack that were added after the last call to push().
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Pushes a backtracking point on the solver's stack.
A following call to pop() deletes exactly those assertions from the solver's stack that were added after this call.
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Specifies the maximum difference between lower- and upper objective bounds that triggers termination.
That means a solution is considered optimal if upperBound - lowerBound < gap * (relative ? |upperBound| : 1). Only relevant for programs with integer/boolean variables.
Implemented in storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
void storm::solver::LpSolver< ValueType, RawMode >::setOptimizationDirection | ( | OptimizationDirection const & | optimizationDirection | ) |
Sets whether the objective function of this model is to be minimized or maximized.
modelSense | The model sense to use. |
Definition at line 118 of file LpSolver.cpp.
|
pure virtual |
Updates the model to make the variables that have been declared since the last call to update
usable.
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
pure virtual |
Writes the current LP problem to the given file.
filename | The file to which to write the string representation of the LP. |
Implemented in storm::solver::GlpkLpSolver, storm::solver::GurobiLpSolver< ValueType, RawMode >, storm::solver::SoplexLpSolver< ValueType, RawMode >, and storm::solver::Z3LpSolver< ValueType, RawMode >.
|
mutableprotected |
Definition at line 394 of file LpSolver.h.
|
protected |
Definition at line 391 of file LpSolver.h.