1#ifndef STORM_SOLVER_Z3LPSOLVER
2#define STORM_SOLVER_Z3LPSOLVER
7#include "storm-config.h"
11#ifdef STORM_HAVE_Z3_OPTIMIZE
23template<
typename ValueType,
bool RawMode = false>
68 std::optional<ValueType>
const& upperBound = std::nullopt, ValueType objectiveFunctionCoefficient = 0)
override;
71 virtual void update()
const override;
78 virtual void optimize()
const override;
92 virtual void push()
override;
93 virtual void pop()
override;
96 virtual ValueType
getMILPGap(
bool relative)
const override;
101#ifdef STORM_HAVE_Z3_OPTIMIZE
104 std::unique_ptr<z3::context> context;
107 std::unique_ptr<z3::optimize> solver;
110 mutable bool lastCheckInfeasible;
111 mutable bool lastCheckUnbounded;
112 mutable std::unique_ptr<z3::expr> lastCheckObjectiveValue;
113 mutable std::unique_ptr<z3::model> lastCheckModel;
116 std::unique_ptr<storm::adapters::Z3ExpressionAdapter> expressionAdapter;
119 std::vector<storm::expressions::Expression> optimizationSummands;
125 std::vector<uint64_t> incrementaOptimizationSummandIndicators;
128 std::vector<storm::expressions::Variable> rawIndexToVariableMap;
An interface that captures the functionality of an LP solver.
std::conditional_t< RawMode, RawLpConstraint< ValueType >, storm::expressions::Expression > Constraint
std::conditional_t< RawMode, ValueType, storm::expressions::Expression > Constant
std::conditional_t< RawMode, typename RawLpConstraint< ValueType >::VariableIndexType, storm::expressions::Variable > Variable
VariableType
Enumerates the different types of variables.
A class that implements the LpSolver interface using Z3.
virtual ValueType getObjectiveValue() const override
Retrieves the value of the objective function.
typename LpSolver< ValueType, RawMode >::Variable Variable
virtual void update() const override
Updates the model to make the variables that have been declared since the last call to update usable.
virtual int_fast64_t getIntegerValue(Variable const &variable) const override
Retrieves the value of the integer 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.
typename LpSolver< ValueType, RawMode >::Constraint Constraint
virtual void writeModelToFile(std::string const &filename) const override
Writes the current LP problem to the given file.
typename LpSolver< ValueType, RawMode >::Constant Constant
virtual bool isUnbounded() const override
Retrieves whether the model was found to be infeasible.
virtual ValueType getContinuousValue(Variable const &variable) const override
Retrieves the value of the continuous variable with the given name.
Z3LpSolver()
Constructs a solver without a 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 ValueType getMILPGap(bool relative) const override
Returns the obtained gap after a call to optimize()
virtual void setMaximalMILPGap(ValueType const &gap, bool relative) override
Specifies the maximum difference between lower- and upper objective bounds that triggers termination.
virtual void push() override
Pushes a backtracking point on the solver's stack.
virtual void addConstraint(std::string const &name, Constraint const &constraint) override
Adds a the given constraint to the LP problem.
virtual bool isOptimal() const override
Retrieves whether the model was found to be optimal, i.e.
typename LpSolver< ValueType, RawMode >::VariableType VariableType
virtual ~Z3LpSolver()
Destructs a solver by freeing the pointers to Z3's structures.
virtual bool isInfeasible() const override
Retrieves whether the model was found to be infeasible.
virtual void pop() override
Pops a backtracking point from the solver's stack.
virtual bool getBinaryValue(Variable const &variable) const override
Retrieves the value of the binary variable with the given name.
virtual void optimize() const override
Optimizes the LP problem previously constructed.