Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Z3LpSolver.cpp
Go to the documentation of this file.
2
3#include <memory>
4#include <numeric>
5
12#include "storm/io/file.h"
19
20namespace storm {
21namespace solver {
22
23#ifdef STORM_HAVE_Z3
24
25template<typename ValueType, bool RawMode>
26Z3LpSolver<ValueType, RawMode>::Z3LpSolver(std::string const& name, OptimizationDirection const& optDir)
27 : LpSolver<ValueType, RawMode>(optDir), isIncremental(false) {
28 z3::config config;
29 config.set("model", true);
30 context = std::make_unique<z3::context>(config);
31 solver = std::make_unique<z3::optimize>(*context);
32 expressionAdapter = std::make_unique<storm::adapters::Z3ExpressionAdapter>(*this->manager, *context);
33}
34
35template<typename ValueType, bool RawMode>
36Z3LpSolver<ValueType, RawMode>::Z3LpSolver(std::string const& name) : Z3LpSolver(name, OptimizationDirection::Minimize) {
37 // Intentionally left empty.
38}
39
40template<typename ValueType, bool RawMode>
41Z3LpSolver<ValueType, RawMode>::Z3LpSolver(OptimizationDirection const& optDir) : Z3LpSolver("", optDir) {
42 // Intentionally left empty.
43}
44
45template<typename ValueType, bool RawMode>
46Z3LpSolver<ValueType, RawMode>::Z3LpSolver() : Z3LpSolver("", OptimizationDirection::Minimize) {
47 // Intentionally left empty.
48}
49
50template<typename ValueType, bool RawMode>
51Z3LpSolver<ValueType, RawMode>::~Z3LpSolver() {
52 // Intentionally left empty.
53}
54
55template<typename ValueType, bool RawMode>
56void Z3LpSolver<ValueType, RawMode>::update() const {
57 // Since the model changed, we erase the optimality flag.
58 lastCheckObjectiveValue.reset(nullptr);
59 lastCheckModel.reset(nullptr);
60 this->currentModelHasBeenOptimized = false;
61}
62
63template<typename ValueType, bool RawMode>
64typename Z3LpSolver<ValueType, RawMode>::Variable Z3LpSolver<ValueType, RawMode>::addVariable(std::string const& name, VariableType const& type,
65 std::optional<ValueType> const& lowerBound,
66 std::optional<ValueType> const& upperBound,
67 ValueType objectiveFunctionCoefficient) {
68 STORM_LOG_ASSERT(isIncremental || !this->manager->hasVariable(name), "Variable with name " << name << " already exists.");
69 storm::expressions::Variable newVariable = this->declareOrGetExpressionVariable(name, type);
70 if (type == VariableType::Binary) {
71 solver->add(expressionAdapter->translateExpression(newVariable.getExpression() >= this->manager->integer(0)));
72 solver->add(expressionAdapter->translateExpression(newVariable.getExpression() <= this->manager->integer(1)));
73 }
74 if (lowerBound) {
75 solver->add(expressionAdapter->translateExpression(newVariable.getExpression() >= this->manager->rational(*lowerBound)));
76 }
77 if (upperBound) {
78 solver->add(expressionAdapter->translateExpression(newVariable.getExpression() <= this->manager->rational(*upperBound)));
79 }
80 if (!storm::utility::isZero(objectiveFunctionCoefficient)) {
81 optimizationSummands.push_back(this->manager->rational(objectiveFunctionCoefficient) * newVariable);
82 }
83
84 if constexpr (RawMode) {
85 rawIndexToVariableMap.push_back(newVariable);
86 return rawIndexToVariableMap.size() - 1;
87 } else {
88 return newVariable;
89 }
90}
91
92template<typename ValueType, bool RawMode>
93void Z3LpSolver<ValueType, RawMode>::addConstraint(std::string const& name, Constraint const& constraint) {
94 if constexpr (RawMode) {
95 // Generate expression from raw constraint
96 STORM_LOG_ASSERT(constraint.lhsVariableIndices.size() == constraint.lhsCoefficients.size(), "Number of variables and coefficients do not match.");
97 std::vector<storm::expressions::Expression> lhsSummands;
98 lhsSummands.reserve(constraint.lhsVariableIndices.size());
99 auto varIt = constraint.lhsVariableIndices.cbegin();
100 auto varItEnd = constraint.lhsVariableIndices.cend();
101 auto coefIt = constraint.lhsCoefficients.cbegin();
102 for (; varIt != varItEnd; ++varIt, ++coefIt) {
103 lhsSummands.push_back(rawIndexToVariableMap[*varIt] * this->manager->rational(*coefIt));
104 }
105 if (lhsSummands.empty()) {
106 lhsSummands.push_back(this->manager->rational(storm::utility::zero<ValueType>()));
107 }
109 storm::expressions::sum(lhsSummands), this->manager->rational(constraint.rhs), constraint.relationType);
110 solver->add(expressionAdapter->translateExpression(constraintExpr));
111 } else {
112 STORM_LOG_THROW(constraint.isRelationalExpression(), storm::exceptions::InvalidArgumentException, "Illegal constraint is not a relational expression.");
113 STORM_LOG_THROW(constraint.getOperator() != storm::expressions::OperatorType::NotEqual, storm::exceptions::InvalidArgumentException,
114 "Illegal constraint uses inequality operator.");
115 solver->add(expressionAdapter->translateExpression(constraint));
116 }
117}
118
119template<typename ValueType, bool RawMode>
120void Z3LpSolver<ValueType, RawMode>::addIndicatorConstraint(std::string const& name, Variable indicatorVariable, bool indicatorValue,
121 Constraint const& constraint) {
122 if constexpr (RawMode) {
123 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Indicator constraints not implemented in RawMode.");
124 } else {
125 // binary variables are encoded as integer variables with domain {0,1}.
126 STORM_LOG_THROW(indicatorVariable.hasIntegerType(), storm::exceptions::InvalidArgumentException,
127 "Variable " << indicatorVariable.getName() << " is not binary.");
128 STORM_LOG_THROW(constraint.isRelationalExpression(), storm::exceptions::InvalidArgumentException, "Illegal constraint is not a relational expression.");
129 STORM_LOG_THROW(constraint.getOperator() != storm::expressions::OperatorType::NotEqual, storm::exceptions::InvalidArgumentException,
130 "Illegal constraint uses inequality operator.");
131
132 storm::expressions::Expression invertedIndicatorVal =
133 this->getConstant(indicatorValue ? storm::utility::zero<ValueType>() : storm::utility::one<ValueType>());
134 auto indicatorConstraint = (indicatorVariable.getExpression() == invertedIndicatorVal) || constraint;
135 solver->add(expressionAdapter->translateExpression(indicatorConstraint));
136 }
137}
138
139template<typename ValueType, bool RawMode>
140void Z3LpSolver<ValueType, RawMode>::optimize() const {
141 // First incorporate all recent changes.
142 this->update();
143
144 // Invoke push() as we want to be able to erase the current optimization function after checking
145 solver->push();
146
147 storm::expressions::Expression optimizationFunction = this->manager->integer(0);
148 // Solve the optimization problem depending on the optimization direction
149 if (!optimizationSummands.empty()) {
150 optimizationFunction = storm::expressions::sum(optimizationSummands);
151 }
152 z3::optimize::handle optFuncHandle = this->getOptimizationDirection() == OptimizationDirection::Minimize
153 ? solver->minimize(expressionAdapter->translateExpression(optimizationFunction))
154 : solver->maximize(expressionAdapter->translateExpression(optimizationFunction));
155
156 z3::check_result chkRes = solver->check();
157 STORM_LOG_THROW(chkRes != z3::unknown, storm::exceptions::InvalidStateException, "Unable to solve LP problem with Z3: Check result is unknown.");
158
159 // We need to store the resulting information at this point. Otherwise, the information would be lost after calling pop() ...
160
161 // Check feasibility
162 lastCheckInfeasible = (chkRes == z3::unsat);
163 if (lastCheckInfeasible) {
164 lastCheckUnbounded = false;
165 } else {
166 // Get objective result
167 lastCheckObjectiveValue = std::make_unique<z3::expr>(solver->upper(optFuncHandle));
168 // Check boundedness
169 STORM_LOG_ASSERT(lastCheckObjectiveValue->is_app(), "Failed to convert Z3 expression. Encountered unknown expression type.");
170 lastCheckUnbounded = (lastCheckObjectiveValue->decl().decl_kind() != Z3_OP_ANUM);
171 if (lastCheckUnbounded) {
172 lastCheckObjectiveValue.reset(nullptr);
173 } else {
174 // Assert that the upper approximation equals the lower one
175 STORM_LOG_ASSERT(std::string(Z3_get_numeral_string(*context, *lastCheckObjectiveValue)) ==
176 std::string(Z3_get_numeral_string(*context, solver->lower(optFuncHandle))),
177 "Lower and Upper Approximation of z3LPSolver result do not match.");
178 lastCheckModel = std::make_unique<z3::model>(solver->get_model());
179 }
180 }
181
182 solver->pop(); // removes current optimization function
183 this->currentModelHasBeenOptimized = true;
184}
185
186template<typename ValueType, bool RawMode>
187bool Z3LpSolver<ValueType, RawMode>::isInfeasible() const {
188 STORM_LOG_THROW(this->currentModelHasBeenOptimized, storm::exceptions::InvalidStateException,
189 "Illegal call to Z3LpSolver<ValueType, RawMode>::isInfeasible: model has not been optimized.");
190 return lastCheckInfeasible;
191}
192
193template<typename ValueType, bool RawMode>
194bool Z3LpSolver<ValueType, RawMode>::isUnbounded() const {
195 STORM_LOG_THROW(this->currentModelHasBeenOptimized, storm::exceptions::InvalidStateException,
196 "Illegal call to Z3LpSolver<ValueType, RawMode>::isUnbounded: model has not been optimized.");
197 return lastCheckUnbounded;
198}
199
200template<typename ValueType, bool RawMode>
201bool Z3LpSolver<ValueType, RawMode>::isOptimal() const {
202 STORM_LOG_THROW(this->currentModelHasBeenOptimized, storm::exceptions::InvalidStateException,
203 "Illegal call to Z3LpSolver<ValueType, RawMode>::isOptimal: model has not been optimized.");
204 return !lastCheckInfeasible && !lastCheckUnbounded;
205}
206
207template<typename ValueType, bool RawMode>
208storm::expressions::Expression Z3LpSolver<ValueType, RawMode>::getValue(Variable const& variable) const {
209 if (!this->isOptimal()) {
210 STORM_LOG_THROW(!this->isInfeasible(), storm::exceptions::InvalidAccessException, "Unable to get Z3 solution from infeasible model.");
211 STORM_LOG_THROW(!this->isUnbounded(), storm::exceptions::InvalidAccessException, "Unable to get Z3 solution from unbounded model.");
212 STORM_LOG_THROW(false, storm::exceptions::InvalidAccessException, "Unable to get Z3 solution from unoptimized model.");
213 }
214 STORM_LOG_ASSERT(lastCheckModel, "Model has not been stored.");
215
216 if constexpr (RawMode) {
217 STORM_LOG_ASSERT(variable < rawIndexToVariableMap.size(), "Requested variable out of range.");
218 z3::expr z3Var = this->expressionAdapter->translateExpression(rawIndexToVariableMap[variable]);
219 return this->expressionAdapter->translateExpression(lastCheckModel->eval(z3Var, true));
220 } else {
221 STORM_LOG_ASSERT(variable.getManager() == this->getManager(), "Requested variable is managed by a different manager.");
222 z3::expr z3Var = this->expressionAdapter->translateExpression(variable);
223 return this->expressionAdapter->translateExpression(lastCheckModel->eval(z3Var, true));
224 }
225}
226
227template<typename ValueType, bool RawMode>
228ValueType Z3LpSolver<ValueType, RawMode>::getContinuousValue(Variable const& variable) const {
229 storm::expressions::Expression value = getValue(variable);
232 }
233 STORM_LOG_THROW(value.getBaseExpression().isRationalLiteralExpression(), storm::exceptions::ExpressionEvaluationException,
234 "Expected a rational literal while obtaining the value of a continuous variable. Got " << value << "instead.");
236}
237
238template<typename ValueType, bool RawMode>
239int_fast64_t Z3LpSolver<ValueType, RawMode>::getIntegerValue(Variable const& variable) const {
240 storm::expressions::Expression value = getValue(variable);
241 STORM_LOG_THROW(value.getBaseExpression().isIntegerLiteralExpression(), storm::exceptions::ExpressionEvaluationException,
242 "Expected an integer literal while obtaining the value of an integer variable. Got " << value << "instead.");
244}
245
246template<typename ValueType, bool RawMode>
247bool Z3LpSolver<ValueType, RawMode>::getBinaryValue(Variable const& variable) const {
248 storm::expressions::Expression value = getValue(variable);
249 // Binary variables are in fact represented as integer variables!
250 STORM_LOG_THROW(value.getBaseExpression().isIntegerLiteralExpression(), storm::exceptions::ExpressionEvaluationException,
251 "Expected an integer literal while obtaining the value of a binary variable. Got " << value << "instead.");
252 int_fast64_t val = value.getBaseExpression().asIntegerLiteralExpression().getValue();
253 STORM_LOG_THROW((val == 0 || val == 1), storm::exceptions::ExpressionEvaluationException,
254 "Tried to get a binary value for a variable that is neither 0 nor 1.");
255 return val == 1;
256}
257
258template<typename ValueType, bool RawMode>
259ValueType Z3LpSolver<ValueType, RawMode>::getObjectiveValue() const {
260 if (!this->isOptimal()) {
261 STORM_LOG_THROW(!this->isInfeasible(), storm::exceptions::InvalidAccessException, "Unable to get Z3 solution from infeasible model.");
262 STORM_LOG_THROW(!this->isUnbounded(), storm::exceptions::InvalidAccessException, "Unable to get Z3 solution from unbounded model.");
263 STORM_LOG_THROW(false, storm::exceptions::InvalidAccessException, "Unable to get Z3 solution from unoptimized model.");
264 }
265 STORM_LOG_ASSERT(lastCheckObjectiveValue, "Objective value has not been stored.");
266
267 storm::expressions::Expression result = this->expressionAdapter->translateExpression(*lastCheckObjectiveValue);
270 }
271 STORM_LOG_THROW(result.getBaseExpression().isRationalLiteralExpression(), storm::exceptions::ExpressionEvaluationException,
272 "Expected a rational literal while obtaining the objective result. Got " << result << "instead.");
274}
275
276template<typename ValueType, bool RawMode>
277void Z3LpSolver<ValueType, RawMode>::writeModelToFile(std::string const& filename) const {
278 std::ofstream stream;
279 storm::io::openFile(filename, stream);
280 stream << Z3_optimize_to_string(*context, *solver);
281 storm::io::closeFile(stream);
282}
283
284template<typename ValueType, bool RawMode>
285void Z3LpSolver<ValueType, RawMode>::push() {
286 STORM_LOG_THROW(!RawMode, storm::exceptions::NotImplementedException, "Incremental solving is not supported in Raw mode.");
287 incrementaOptimizationSummandIndicators.push_back(optimizationSummands.size());
288 solver->push();
289}
290
291template<typename ValueType, bool RawMode>
292void Z3LpSolver<ValueType, RawMode>::pop() {
293 STORM_LOG_THROW(!RawMode, storm::exceptions::NotImplementedException, "Incremental solving is not supported in Raw mode.");
294 STORM_LOG_ASSERT(!incrementaOptimizationSummandIndicators.empty(), "Tried to pop() without push()ing first.");
295 solver->pop();
296 // Delete summands of the optimization function that have been added since the last call to push()
297 optimizationSummands.resize(incrementaOptimizationSummandIndicators.back());
298 incrementaOptimizationSummandIndicators.pop_back();
299 isIncremental = true;
300}
301
302template<typename ValueType, bool RawMode>
303void Z3LpSolver<ValueType, RawMode>::setMaximalMILPGap(ValueType const&, bool) {
304 // Since the solver is always exact, setting a gap has no effect.
305 // Intentionally left empty.
306}
307
308template<typename ValueType, bool RawMode>
309ValueType Z3LpSolver<ValueType, RawMode>::getMILPGap(bool relative) const {
310 // Since the solver is precise, the milp gap is always zero.
312}
313#else
314template<typename ValueType, bool RawMode>
316 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
317 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
318 "requires this support.");
319}
320
321template<typename ValueType, bool RawMode>
323 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
324 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
325 "requires this support.");
326}
327
328template<typename ValueType, bool RawMode>
330 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
331 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
332 "requires this support.");
333}
334
335template<typename ValueType, bool RawMode>
337 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
338 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
339 "requires this support.");
340}
341
342template<typename ValueType, bool RawMode>
344
345template<typename ValueType, bool RawMode>
347 std::optional<ValueType> const&, std::optional<ValueType> const&,
348 ValueType) {
349 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
350 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
351 "requires this support.");
352}
353
354template<typename ValueType, bool RawMode>
356 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
357 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
358 "requires this support.");
359}
360
361template<typename ValueType, bool RawMode>
363 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
364 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
365 "requires this support.");
366}
367
368template<typename ValueType, bool RawMode>
370 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
371 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
372 "requires this support.");
373}
374
375template<typename ValueType, bool RawMode>
377 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
378 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
379 "requires this support.");
380}
381
382template<typename ValueType, bool RawMode>
384 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
385 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
386 "requires this support.");
387}
388
389template<typename ValueType, bool RawMode>
391 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
392 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
393 "requires this support.");
394}
395
396template<typename ValueType, bool RawMode>
398 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
399 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
400 "requires this support.");
401}
402
403template<typename ValueType, bool RawMode>
404storm::expressions::Expression Z3LpSolver<ValueType, RawMode>::getValue(Variable const& variable) const {
405 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
406 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
407 "requires this support.");
408}
409
410template<typename ValueType, bool RawMode>
412 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
413 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
414 "requires this support.");
415}
416
417template<typename ValueType, bool RawMode>
419 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
420 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
421 "requires this support.");
422}
423
424template<typename ValueType, bool RawMode>
426 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
427 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
428 "requires this support.");
429}
430
431template<typename ValueType, bool RawMode>
433 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
434 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
435 "requires this support.");
436}
437
438template<typename ValueType, bool RawMode>
439void Z3LpSolver<ValueType, RawMode>::writeModelToFile(std::string const& filename) const {
440 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
441 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
442 "requires this support.");
443}
444
445template<typename ValueType, bool RawMode>
447 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
448 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
449 "requires this support.");
450}
451
452template<typename ValueType, bool RawMode>
454 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
455 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
456 "requires this support.");
457}
458
459template<typename ValueType, bool RawMode>
461 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
462 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
463 "requires this support.");
464}
465
466template<typename ValueType, bool RawMode>
467ValueType Z3LpSolver<ValueType, RawMode>::getMILPGap(bool relative) const {
468 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
469 "This version of storm was compiled without Z3 or the version of Z3 does not support optimization. Yet, a method was called that "
470 "requires this support.");
471}
472#endif
473
474template class Z3LpSolver<double, false>;
476template class Z3LpSolver<double, true>;
478} // namespace solver
479} // namespace storm
IntegerLiteralExpression const & asIntegerLiteralExpression() const
RationalLiteralExpression const & asRationalLiteralExpression() const
virtual bool isRationalLiteralExpression() const
virtual bool isIntegerLiteralExpression() const
BaseExpression const & getBaseExpression() const
Retrieves the base expression underlying this expression object.
int_fast64_t getValue() const
Retrieves the value of the integer literal.
storm::RationalNumber getValue() const
Retrieves the value of the double literal.
storm::expressions::Expression getExpression() const
Retrieves an expression that represents the variable.
Definition Variable.cpp:34
An interface that captures the functionality of an LP solver.
Definition LpSolver.h:50
A class that implements the LpSolver interface using Z3.
Definition Z3LpSolver.h:23
virtual ValueType getObjectiveValue() const override
Retrieves the value of the objective function.
typename LpSolver< ValueType, RawMode >::Variable Variable
Definition Z3LpSolver.h:26
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
typename LpSolver< ValueType, RawMode >::Constraint Constraint
Definition Z3LpSolver.h:28
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.
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.
Z3LpSolver(std::string const &name, OptimizationDirection const &optDir)
Constructs a solver with the given name and optimization direction.
virtual bool isOptimal() const override
Retrieves whether the model was found to be optimal, i.e.
typename LpSolver< ValueType, RawMode >::VariableType VariableType
Definition Z3LpSolver.h:25
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.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
SFTBDDChecker::ValueType ValueType
Expression makeBinaryRelationExpression(Expression const &first, Expression const &second, RelationType const &reltype)
Expression sum(std::vector< storm::expressions::Expression > const &expressions)
void closeFile(std::ofstream &stream)
Close the given file after writing.
Definition file.h:47
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18
SettingsManager const & manager()
Retrieves the settings manager.
bool isZero(ValueType const &a)
Definition constants.cpp:42
ValueType zero()
Definition constants.cpp:24
ValueType one()
Definition constants.cpp:19
TargetType convertNumber(SourceType const &number)