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