Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MathsatSmtSolver.cpp
Go to the documentation of this file.
2
9
10namespace storm {
11namespace solver {
12
13#ifdef STORM_HAVE_MATHSAT
14MathsatSmtSolver::MathsatAllsatModelReference::MathsatAllsatModelReference(
15 storm::expressions::ExpressionManager const& manager, msat_env const& env, msat_term* model,
16 std::unordered_map<storm::expressions::Variable, uint_fast64_t> const& variableToSlotMapping)
17 : ModelReference(manager), env(env), model(model), variableToSlotMapping(variableToSlotMapping) {
18 // Intentionally left empty.
19}
20
21bool MathsatSmtSolver::MathsatAllsatModelReference::getBooleanValue(storm::expressions::Variable const& variable) const {
22 std::unordered_map<storm::expressions::Variable, uint_fast64_t>::const_iterator variableSlotPair = variableToSlotMapping.find(variable);
23 STORM_LOG_THROW(variableSlotPair != variableToSlotMapping.end(), storm::exceptions::InvalidArgumentException,
24 "Cannot retrieve value of unknown variable '" << variable.getName() << "' from model.");
25 msat_term selectedTerm = model[variableSlotPair->second];
26
27 if (msat_term_is_not(env, selectedTerm)) {
28 return false;
29 } else {
30 return true;
31 }
32}
33
34int_fast64_t MathsatSmtSolver::MathsatAllsatModelReference::getIntegerValue(storm::expressions::Variable const&) const {
35 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Unable to retrieve integer value from model that only contains boolean values.");
36}
37
38double MathsatSmtSolver::MathsatAllsatModelReference::getRationalValue(storm::expressions::Variable const&) const {
39 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "Unable to retrieve double value from model that only contains boolean values.");
40}
41
42std::string MathsatSmtSolver::MathsatAllsatModelReference::toString() const {
43 std::stringstream str;
44 bool first = true;
45 str << "[";
46 for (auto const& varSlot : variableToSlotMapping) {
47 if (first) {
48 first = false;
49 } else {
50 str << ", ";
51 }
52 str << varSlot.first.getName() << "=" << std::boolalpha << getBooleanValue(varSlot.first);
53 }
54 str << "]";
55 return str.str();
56}
57
58MathsatSmtSolver::MathsatModelReference::MathsatModelReference(storm::expressions::ExpressionManager const& manager, msat_env const& env,
59 storm::adapters::MathsatExpressionAdapter& expressionAdapter)
60 : ModelReference(manager), env(env), expressionAdapter(expressionAdapter) {
61 // Intentionally left empty.
62}
63
64bool MathsatSmtSolver::MathsatModelReference::getBooleanValue(storm::expressions::Variable const& variable) const {
65 STORM_LOG_ASSERT(variable.hasBooleanType(), "Variable is non-boolean type.");
66 msat_term msatVariable = expressionAdapter.translateExpression(variable);
67 msat_term msatValue = msat_get_model_value(env, msatVariable);
69 !MSAT_ERROR_TERM(msatValue),
70 "Unable to retrieve value of variable in model. This could be caused by calls to the solver between checking for satisfiability and model retrieval.");
71 storm::expressions::Expression value = expressionAdapter.translateExpression(msatValue);
72 return value.evaluateAsBool();
73}
74
75int_fast64_t MathsatSmtSolver::MathsatModelReference::getIntegerValue(storm::expressions::Variable const& variable) const {
76 STORM_LOG_ASSERT(variable.hasIntegerType(), "Variable is non-boolean type.");
77 msat_term msatVariable = expressionAdapter.translateExpression(variable);
78 msat_term msatValue = msat_get_model_value(env, msatVariable);
80 !MSAT_ERROR_TERM(msatValue),
81 "Unable to retrieve value of variable in model. This could be caused by calls to the solver between checking for satisfiability and model retrieval.");
82 storm::expressions::Expression value = expressionAdapter.translateExpression(msatValue);
83 return value.evaluateAsInt();
84}
85
86double MathsatSmtSolver::MathsatModelReference::getRationalValue(storm::expressions::Variable const& variable) const {
87 STORM_LOG_ASSERT(variable.hasRationalType(), "Variable is non-boolean type.");
88 msat_term msatVariable = expressionAdapter.translateExpression(variable);
89 msat_term msatValue = msat_get_model_value(env, msatVariable);
91 !MSAT_ERROR_TERM(msatValue),
92 "Unable to retrieve value of variable in model. This could be caused by calls to the solver between checking for satisfiability and model retrieval.");
93 storm::expressions::Expression value = expressionAdapter.translateExpression(msatValue);
94 return value.evaluateAsDouble();
95}
96
97std::string MathsatSmtSolver::MathsatModelReference::toString() const {
98 std::stringstream str;
99 bool first = true;
100 str << "[";
101 for (auto const& varDecl : expressionAdapter.getAllDeclaredVariables()) {
102 if (first) {
103 first = false;
104 } else {
105 str << ", ";
106 }
107 msat_term msatValue = msat_get_model_value(env, expressionAdapter.translateExpression(varDecl.first));
108 STORM_LOG_ASSERT(!MSAT_ERROR_TERM(msatValue),
109 "Unable to retrieve value of variable in model. This could be caused by calls to the solver between checking for satisfiability and "
110 "model retrieval.");
111 str << varDecl.first.getName() << "=" << expressionAdapter.translateExpression(msatValue);
112 }
113 str << "]";
114 return str.str();
115}
116
117#endif
118
120 : SmtSolver(manager)
121#ifdef STORM_HAVE_MATHSAT
122 ,
123 expressionAdapter(nullptr),
124 lastCheckAssumptions(false),
125 lastResult(CheckResult::Unknown)
126#endif
127{
128#ifdef STORM_HAVE_MATHSAT
129 msat_config config = msat_create_config();
130 if (options.enableInterpolantGeneration) {
131 msat_set_option(config, "interpolation", "true");
132 }
133 if (options.enableModelGeneration) {
134 msat_set_option(config, "model_generation", "true");
135 }
136 if (options.enableUnsatCoreGeneration) {
137 msat_set_option(config, "unsat_core_generation", "true");
138 }
139 STORM_LOG_THROW(!MSAT_ERROR_CONFIG(config), storm::exceptions::UnexpectedException, "Unable to create Mathsat configuration.");
140
141 // Based on the configuration, build the environment, check for errors and destroy the configuration.
142 env = msat_create_env(config);
143 STORM_LOG_THROW(!MSAT_ERROR_ENV(env), storm::exceptions::UnexpectedException, "Unable to create Mathsat environment.");
144 msat_destroy_config(config);
145
146 // Register the termination test that realizes timeouts.
147 msat_set_termination_test(env, &MathsatSmtSolver::terminationTest, this);
148
149 expressionAdapter = std::make_unique<storm::adapters::MathsatExpressionAdapter>(manager, env);
150#else
151 (void)options;
152#endif
153}
154
156#ifdef STORM_HAVE_MATHSAT
157 if (!MSAT_ERROR_ENV(env)) {
158 msat_destroy_env(env);
159 } else {
160 STORM_LOG_ERROR("Trying to destroy illegal MathSAT environment.");
161 }
162#else
163 // Empty.
164#endif
165}
166
168#ifdef STORM_HAVE_MATHSAT
169 msat_push_backtrack_point(env);
170#else
171 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
172#endif
173}
174
176#ifdef STORM_HAVE_MATHSAT
177 msat_pop_backtrack_point(env);
178#else
179 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
180#endif
181}
182
183void MathsatSmtSolver::pop(uint_fast64_t n) {
184#ifdef STORM_HAVE_MATHSAT
186#else
187 (void)n;
188 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
189#endif
190}
191
193#ifdef STORM_HAVE_MATHSAT
194 msat_reset_env(env);
195 // Make sure that the termination test survives the reset.
196 msat_set_termination_test(env, &MathsatSmtSolver::terminationTest, this);
197#else
198 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
199#endif
200}
201
203#ifdef STORM_HAVE_MATHSAT
204 msat_term expression = expressionAdapter->translateExpression(e);
205 msat_assert_formula(env, expression);
206 if (expressionAdapter->hasAdditionalConstraints()) {
207 for (auto const& constraint : expressionAdapter->getAdditionalConstraints()) {
208 msat_assert_formula(env, constraint);
209 }
210 }
211#else
212 (void)e;
213 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
214#endif
215}
216
218#ifdef STORM_HAVE_MATHSAT
219 lastCheckAssumptions = false;
220 startTimeoutClock();
221 switch (msat_solve(env)) {
222 case MSAT_SAT:
223 this->lastResult = SmtSolver::CheckResult::Sat;
224 break;
225 case MSAT_UNSAT:
226 this->lastResult = SmtSolver::CheckResult::Unsat;
227 break;
228 default:
229 this->lastResult = SmtSolver::CheckResult::Unknown;
230 break;
231 }
232 return this->lastResult;
233#else
234 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
235#endif
236}
237
239#ifdef STORM_HAVE_MATHSAT
240 lastCheckAssumptions = true;
241 std::vector<msat_term> mathSatAssumptions;
242 mathSatAssumptions.reserve(assumptions.size());
243
244 for (storm::expressions::Expression assumption : assumptions) {
245 mathSatAssumptions.push_back(this->expressionAdapter->translateExpression(assumption));
246 }
247
248 startTimeoutClock();
249 switch (msat_solve_with_assumptions(env, mathSatAssumptions.data(), mathSatAssumptions.size())) {
250 case MSAT_SAT:
251 this->lastResult = SmtSolver::CheckResult::Sat;
252 break;
253 case MSAT_UNSAT:
254 this->lastResult = SmtSolver::CheckResult::Unsat;
255 break;
256 default:
257 this->lastResult = SmtSolver::CheckResult::Unknown;
258 break;
259 }
260 return this->lastResult;
261#else
262 (void)assumptions;
263 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
264#endif
265}
266
267SmtSolver::CheckResult MathsatSmtSolver::checkWithAssumptions(std::initializer_list<storm::expressions::Expression> const& assumptions) {
268#ifdef STORM_HAVE_MATHSAT
269 lastCheckAssumptions = true;
270 std::vector<msat_term> mathSatAssumptions;
271 mathSatAssumptions.reserve(assumptions.size());
272
273 for (storm::expressions::Expression assumption : assumptions) {
274 mathSatAssumptions.push_back(this->expressionAdapter->translateExpression(assumption));
275 }
276
277 startTimeoutClock();
278 switch (msat_solve_with_assumptions(env, mathSatAssumptions.data(), mathSatAssumptions.size())) {
279 case MSAT_SAT:
280 this->lastResult = SmtSolver::CheckResult::Sat;
281 break;
282 case MSAT_UNSAT:
283 this->lastResult = SmtSolver::CheckResult::Unsat;
284 break;
285 default:
286 this->lastResult = SmtSolver::CheckResult::Unknown;
287 break;
288 }
289 return this->lastResult;
290#else
291 (void)assumptions;
292 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
293#endif
294}
295
297#ifdef STORM_HAVE_MATHSAT
298 STORM_LOG_THROW(this->lastResult == SmtSolver::CheckResult::Sat, storm::exceptions::InvalidStateException,
299 "Unable to create model for formula that was not determined to be satisfiable.");
300 return this->convertMathsatModelToValuation();
301#else
302 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
303#endif
304}
305
306std::shared_ptr<SmtSolver::ModelReference> MathsatSmtSolver::getModel() {
307#ifdef STORM_HAVE_MATHSAT
308 STORM_LOG_THROW(this->lastResult == SmtSolver::CheckResult::Sat, storm::exceptions::InvalidStateException,
309 "Unable to create model for formula that was not determined to be satisfiable.");
310 return std::shared_ptr<SmtSolver::ModelReference>(new MathsatModelReference(this->getManager(), env, *expressionAdapter));
311#else
312 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
313#endif
314}
315
316#ifdef STORM_HAVE_MATHSAT
317storm::expressions::SimpleValuation MathsatSmtSolver::convertMathsatModelToValuation() {
318 storm::expressions::SimpleValuation stormModel(this->getManager().getSharedPointer());
319
320 msat_model_iterator modelIterator = msat_create_model_iterator(env);
321 STORM_LOG_THROW(!MSAT_ERROR_MODEL_ITERATOR(modelIterator), storm::exceptions::UnexpectedException, "MathSat returned an illegal model iterator.");
322
323 while (msat_model_iterator_has_next(modelIterator)) {
324 msat_term t, v;
325 msat_model_iterator_next(modelIterator, &t, &v);
326
327 storm::expressions::Expression variableInterpretation = this->expressionAdapter->translateExpression(v);
328 storm::expressions::Variable stormVariable = this->expressionAdapter->getVariable(msat_term_get_decl(t));
329
330 if (stormVariable.hasBooleanType()) {
331 stormModel.setBooleanValue(stormVariable, variableInterpretation.isTrue());
332 } else if (stormVariable.hasIntegerType()) {
333 stormModel.setIntegerValue(stormVariable, variableInterpretation.evaluateAsInt());
334 } else if (stormVariable.hasRationalType()) {
335 stormModel.setRationalValue(stormVariable, variableInterpretation.evaluateAsDouble());
336 } else {
337 STORM_LOG_THROW(false, storm::exceptions::ExpressionEvaluationException, "Variable interpretation in model is not of type bool, int or rational.");
338 }
339 }
340
341 return stormModel;
342}
343#endif
344
345std::vector<storm::expressions::SimpleValuation> MathsatSmtSolver::allSat(std::vector<storm::expressions::Variable> const& important) {
346#ifdef STORM_HAVE_MATHSAT
347 std::vector<storm::expressions::SimpleValuation> valuations;
348 this->allSat(important, [&valuations](storm::expressions::SimpleValuation const& valuation) -> bool {
349 valuations.push_back(valuation);
350 return true;
351 });
352 return valuations;
353#else
354 (void)important;
355 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
356#endif
357}
358
359#ifdef STORM_HAVE_MATHSAT
360class AllsatValuationCallbackUserData {
361 public:
362 AllsatValuationCallbackUserData(storm::expressions::ExpressionManager const& manager, storm::adapters::MathsatExpressionAdapter& adapter, msat_env& env,
363 std::function<bool(storm::expressions::SimpleValuation&)> const& callback)
364 : manager(manager), adapter(adapter), env(env), callback(callback) {
365 // Intentionally left empty.
366 }
367
368 static int allsatValuationsCallback(msat_term* model, int size, void* user_data) {
369 AllsatValuationCallbackUserData* user = reinterpret_cast<AllsatValuationCallbackUserData*>(user_data);
370
371 storm::expressions::SimpleValuation valuation(user->manager.getSharedPointer());
372 for (int i = 0; i < size; ++i) {
373 bool currentTermValue = true;
374 msat_term currentTerm = model[i];
375 if (msat_term_is_not(user->env, currentTerm)) {
376 currentTerm = msat_term_get_arg(currentTerm, 0);
377 currentTermValue = false;
378 }
379 storm::expressions::Variable stormVariable = user->adapter.getVariable(msat_term_get_decl(currentTerm));
380 valuation.setBooleanValue(stormVariable, currentTermValue);
381 }
382
383 ++user->numberOfModels;
384 if (user->callback(valuation)) {
385 return 1;
386 } else {
387 user->abortedByCallback = true;
388 return 0;
389 }
390 }
391
392 // The number of models that were passed to the callback.
393 uint_fast64_t numberOfModels = 0;
394
395 // Whether the callback aborted the enumeration.
396 bool abortedByCallback = false;
397
398 protected:
399 // The manager responsible for the expression.s
400 storm::expressions::ExpressionManager const& manager;
401
402 // The adapter to use for expression translation.
403 storm::adapters::MathsatExpressionAdapter& adapter;
404
405 // The MathSAT environment. It is used to retrieve the values of the atoms in a model.
406 msat_env& env;
407
408 // The function that is to be called when the MathSAT model has been translated to a valuation.
409 std::function<bool(storm::expressions::SimpleValuation&)> const& callback;
410};
411
412class AllsatModelReferenceCallbackUserData {
413 public:
414 AllsatModelReferenceCallbackUserData(storm::expressions::ExpressionManager const& manager, msat_env& env,
415 std::unordered_map<storm::expressions::Variable, uint_fast64_t> const& atomToSlotMapping,
416 std::function<bool(storm::solver::SmtSolver::ModelReference&)> const& callback)
417 : manager(manager), env(env), atomToSlotMapping(atomToSlotMapping), callback(callback) {
418 // Intentionally left empty.
419 }
420
421 static int allsatModelReferenceCallback(msat_term* model, int, void* user_data) {
422 AllsatModelReferenceCallbackUserData* user = reinterpret_cast<AllsatModelReferenceCallbackUserData*>(user_data);
423 MathsatSmtSolver::MathsatAllsatModelReference modelReference(user->manager, user->env, model, user->atomToSlotMapping);
424 ++user->numberOfModels;
425 if (user->callback(modelReference)) {
426 return 1;
427 } else {
428 user->abortedByCallback = true;
429 return 0;
430 }
431 }
432
433 // The number of models that were passed to the callback.
434 uint_fast64_t numberOfModels = 0;
435
436 // Whether the callback aborted the enumeration.
437 bool abortedByCallback = false;
438
439 protected:
440 // The manager responsible for the expression.s
441 storm::expressions::ExpressionManager const& manager;
442
443 // The MathSAT environment. It is used to retrieve the values of the atoms in a model.
444 msat_env& env;
445
446 // Store a mapping from atoms to their slots in the model.
447 std::unordered_map<storm::expressions::Variable, uint_fast64_t> const& atomToSlotMapping;
448
449 // The function that is to be called when the MathSAT model has been translated to a valuation.
450 std::function<bool(storm::solver::SmtSolver::ModelReference&)> const& callback;
451};
452#endif
453
454uint_fast64_t MathsatSmtSolver::allSat(std::vector<storm::expressions::Variable> const& important,
455 std::function<bool(storm::expressions::SimpleValuation&)> const& callback) {
456#ifdef STORM_HAVE_MATHSAT
457 // Create a backtracking point, because MathSAT will modify the assertions stack during its AllSat procedure.
458 this->push();
459
460 std::vector<msat_term> msatImportant;
461 msatImportant.reserve(important.size());
462
463 for (storm::expressions::Variable const& variable : important) {
464 STORM_LOG_THROW(variable.hasBooleanType(), storm::exceptions::InvalidArgumentException, "The important atoms for AllSat must be boolean variables.");
465 msatImportant.push_back(expressionAdapter->translateExpression(variable));
466 }
467
468 AllsatValuationCallbackUserData allSatUserData(this->getManager(), *expressionAdapter, env, callback);
469 startTimeoutClock();
470 int result = msat_all_sat(env, msatImportant.data(), msatImportant.size(), &AllsatValuationCallbackUserData::allsatValuationsCallback, &allSatUserData);
471
472 // Restore original assertion stack and return.
473 this->pop();
474 return processAllSatResult(result, allSatUserData.numberOfModels, allSatUserData.abortedByCallback);
475#else
476 (void)important;
477 (void)callback;
478 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
479#endif
480}
481
482uint_fast64_t MathsatSmtSolver::allSat(std::vector<storm::expressions::Variable> const& important,
483 std::function<bool(SmtSolver::ModelReference&)> const& callback) {
484#ifdef STORM_HAVE_MATHSAT
485 // Create a backtracking point, because MathSAT will modify the assertions stack during its AllSat procedure.
486 this->push();
487
488 std::vector<msat_term> msatImportant;
489 msatImportant.reserve(important.size());
490 std::unordered_map<storm::expressions::Variable, uint_fast64_t> atomToSlotMapping;
491
492 for (storm::expressions::Variable const& variable : important) {
493 STORM_LOG_THROW(variable.hasBooleanType(), storm::exceptions::InvalidArgumentException, "The important atoms for AllSat must be boolean variables.");
494 msatImportant.push_back(expressionAdapter->translateExpression(variable));
495 atomToSlotMapping[variable] = msatImportant.size() - 1;
496 }
497
498 AllsatModelReferenceCallbackUserData allSatUserData(this->getManager(), env, atomToSlotMapping, callback);
499 startTimeoutClock();
500 int result =
501 msat_all_sat(env, msatImportant.data(), msatImportant.size(), &AllsatModelReferenceCallbackUserData::allsatModelReferenceCallback, &allSatUserData);
502
503 // Restore original assertion stack and return.
504 this->pop();
505 return processAllSatResult(result, allSatUserData.numberOfModels, allSatUserData.abortedByCallback);
506#else
507 (void)important;
508 (void)callback;
509 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
510#endif
511}
512
513std::vector<storm::expressions::Expression> MathsatSmtSolver::getUnsatAssumptions() {
514#ifdef STORM_HAVE_MATHSAT
515 STORM_LOG_THROW(lastResult == SmtSolver::CheckResult::Unsat, storm::exceptions::InvalidStateException,
516 "Unable to generate unsatisfiable core of assumptions, because the last check did not determine the formulas to be unsatisfiable.");
517 STORM_LOG_THROW(lastCheckAssumptions, storm::exceptions::InvalidStateException,
518 "Unable to generate unsatisfiable core of assumptions, because the last check did not involve assumptions.");
519
520 size_t numUnsatAssumpations;
521 msat_term* msatUnsatAssumptions = msat_get_unsat_assumptions(env, &numUnsatAssumpations);
522
523 std::vector<storm::expressions::Expression> unsatAssumptions;
524 unsatAssumptions.reserve(numUnsatAssumpations);
525
526 for (unsigned int i = 0; i < numUnsatAssumpations; ++i) {
527 unsatAssumptions.push_back(this->expressionAdapter->translateExpression(msatUnsatAssumptions[i]));
528 }
529
530 return unsatAssumptions;
531#else
532 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
533#endif
534}
535
537#ifdef STORM_HAVE_MATHSAT
538 auto groupIter = this->interpolationGroups.find(group);
539 if (groupIter == this->interpolationGroups.end()) {
540 int newGroup = msat_create_itp_group(env);
541 auto insertResult = this->interpolationGroups.insert(std::make_pair(group, newGroup));
542 groupIter = insertResult.first;
543 }
544 msat_set_itp_group(env, groupIter->second);
545#else
546 (void)group;
547 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
548#endif
549}
550
552#ifdef STORM_HAVE_MATHSAT
553 STORM_LOG_THROW(lastResult == SmtSolver::CheckResult::Unsat, storm::exceptions::InvalidStateException,
554 "Unable to generate interpolant, because the last check did not determine the formulas to be unsatisfiable.");
555 STORM_LOG_THROW(!lastCheckAssumptions, storm::exceptions::InvalidStateException,
556 "Unable to generate interpolant, because the last check for satisfiability involved assumptions.");
557
558 std::vector<int> msatInterpolationGroupsA;
559 msatInterpolationGroupsA.reserve(groupsA.size());
560 for (auto groupOfA : groupsA) {
561 auto groupIter = this->interpolationGroups.find(groupOfA);
562 STORM_LOG_THROW(groupIter != this->interpolationGroups.end(), storm::exceptions::InvalidArgumentException,
563 "Unable to generate interpolant, because an unknown interpolation group was referenced.");
564 msatInterpolationGroupsA.push_back(groupIter->second);
565 }
566 msat_term interpolant = msat_get_interpolant(env, msatInterpolationGroupsA.data(), msatInterpolationGroupsA.size());
567
568 STORM_LOG_THROW(!MSAT_ERROR_TERM(interpolant), storm::exceptions::UnexpectedException, "Unable to retrieve an interpolant.");
569
570 return this->expressionAdapter->translateExpression(interpolant);
571#else
572 (void)groupsA;
573 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
574#endif
575}
576
577void MathsatSmtSolver::setTimeout(uint_fast64_t milliseconds) {
578#ifdef STORM_HAVE_MATHSAT
579 timeout = std::chrono::milliseconds(milliseconds);
580#else
581 (void)milliseconds;
582 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
583#endif
584}
585
587#ifdef STORM_HAVE_MATHSAT
588 timeout.reset();
589#else
590 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException, "Storm is compiled without MathSAT support.");
591#endif
592}
593
594#ifdef STORM_HAVE_MATHSAT
595void MathsatSmtSolver::startTimeoutClock() {
596 if (timeout) {
597 deadline = std::chrono::steady_clock::now() + timeout.value();
598 }
599}
600
601bool MathsatSmtSolver::isTimeoutExceeded() const {
602 return timeout && std::chrono::steady_clock::now() >= deadline;
603}
604
605int MathsatSmtSolver::terminationTest(void* userData) {
606 return static_cast<MathsatSmtSolver const*>(userData)->isTimeoutExceeded() ? 1 : 0;
607}
608
609uint_fast64_t MathsatSmtSolver::processAllSatResult(int result, uint_fast64_t numberOfModels, bool abortedByCallback) const {
610 if (result < 0) {
611 // MathSAT reports an error if the enumeration was aborted, either by the callback or by the termination test.
612 bool const timedOut = isTimeoutExceeded();
613 STORM_LOG_THROW(timedOut || abortedByCallback, storm::exceptions::UnexpectedException, "MathSAT failed to perform AllSat.");
614 STORM_LOG_WARN_COND(!timedOut || abortedByCallback, "AllSat was aborted because of the timeout. Only " << numberOfModels << " models were found.");
615 }
616 // Return the number of models passed to the callback, which is the number of models found so far even if the enumeration was aborted.
617 return numberOfModels;
618}
619#endif
620} // namespace solver
621} // namespace storm
int_fast64_t evaluateAsInt(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of variables given by the valuation and returns the resu...
bool evaluateAsBool(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of variables given by the valuation and returns the resu...
double evaluateAsDouble(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of variables given by the valuation and returns the resu...
bool isTrue() const
Checks if the expression is equal to the boolean literal true.
This class is responsible for managing a set of typed variables and all expressions using these varia...
A simple implementation of the valuation interface.
bool hasBooleanType() const
Checks whether the variable is of boolean type.
Definition Variable.cpp:59
bool hasIntegerType() const
Checks whether the variable is of integral type.
Definition Variable.cpp:63
bool hasRationalType() const
Checks whether the variable is of rational type.
Definition Variable.cpp:71
std::string const & getName() const
Retrieves the name of the variable.
Definition Variable.cpp:46
A class that captures options that may be passed to the Mathsat solver.
virtual std::vector< storm::expressions::Expression > getUnsatAssumptions() override
If the last call to checkWithAssumptions() returned Unsat, this function can be used to retrieve a su...
virtual CheckResult checkWithAssumptions(storm::expressions::ExpressionSet const &assumptions) override
Checks whether the conjunction of assertions that are currently on the solver's stack together with t...
virtual storm::expressions::Expression getInterpolant(std::vector< uint_fast64_t > const &groupsA) override
If the last call to check() returned Unsat, the solver has been instantiated with support for interpo...
virtual std::shared_ptr< SmtSolver::ModelReference > getModel() override
If the last call to check() or checkWithAssumptions() returned Sat, this method retrieves a model tha...
virtual void setTimeout(uint_fast64_t milliseconds) override
Limits each subsequent satisfiability query to the given number of milliseconds.
virtual void add(storm::expressions::Expression const &assertion) override
Adds an assertion to the solver's stack.
MathsatSmtSolver(storm::expressions::ExpressionManager &manager, Options const &options=Options())
virtual void pop() override
Pops a backtracking point from the solver's stack.
virtual CheckResult check() override
Checks whether the conjunction of assertions that are currently on the solver's stack is satisfiable.
virtual void reset() override
Removes all assertions from the solver's stack.
virtual std::vector< storm::expressions::SimpleValuation > allSat(std::vector< storm::expressions::Variable > const &important) override
Performs AllSat over the (provided) important atoms.
virtual void push() override
Pushes a backtracking point on the solver's stack.
virtual void unsetTimeout() override
Unsets a previous timeout such that subsequent queries are no longer limited in time.
virtual storm::expressions::SimpleValuation getModelAsValuation() override
If the last call to check() or checkWithAssumptions() returned Sat, this method retrieves a model tha...
virtual void setInterpolationGroup(uint_fast64_t group) override
Sets the current interpolation group.
The base class for all model references.
Definition SmtSolver.h:30
virtual void pop()=0
Pops a backtracking point from the solver's stack.
storm::expressions::ExpressionManager const & getManager() const
Retrieves the expression manager associated with the solver.
Definition SmtSolver.cpp:79
SmtSolver(storm::expressions::ExpressionManager &manager)
Constructs a new Smt solver with the given options.
Definition SmtSolver.cpp:17
CheckResult
possible check results
Definition SmtSolver.h:24
#define STORM_LOG_ERROR(message)
Definition logging.h:36
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:54
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
std::set< Expression, ExpressionComparator > ExpressionSet
Definition Expression.h:515
SettingsManager const & manager()
Retrieves the settings manager.
The contract of a DD backend.