Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MathsatSmtSolver.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/container/flat_map.hpp>
4#include <chrono>
5#include <optional>
6#include "storm-config.h"
9
10#ifdef STORM_HAVE_MATHSAT
11#include <mathsat.h>
12#endif
13
14namespace storm {
15namespace solver {
17 public:
36
37#ifdef STORM_HAVE_MATHSAT
38 class MathsatAllsatModelReference : public SmtSolver::ModelReference {
39 public:
40 MathsatAllsatModelReference(storm::expressions::ExpressionManager const& manager, msat_env const& env, msat_term* model,
41 std::unordered_map<storm::expressions::Variable, uint_fast64_t> const& variableNameToSlotMapping);
42
43 virtual bool getBooleanValue(storm::expressions::Variable const& variable) const override;
44 virtual int_fast64_t getIntegerValue(storm::expressions::Variable const& variable) const override;
45 virtual double getRationalValue(storm::expressions::Variable const& variable) const override;
46 virtual std::string toString() const override;
47
48 private:
49 msat_env const& env;
50 msat_term* model;
51 std::unordered_map<storm::expressions::Variable, uint_fast64_t> const& variableToSlotMapping;
52 };
53#endif
54
55#ifdef STORM_HAVE_MATHSAT
56 class MathsatModelReference : public SmtSolver::ModelReference {
57 public:
58 MathsatModelReference(storm::expressions::ExpressionManager const& manager, msat_env const& env,
59 storm::adapters::MathsatExpressionAdapter& expressionAdapter);
60
61 virtual bool getBooleanValue(storm::expressions::Variable const& variable) const override;
62 virtual int_fast64_t getIntegerValue(storm::expressions::Variable const& variable) const override;
63 virtual double getRationalValue(storm::expressions::Variable const& variable) const override;
64 virtual std::string toString() const override;
65
66 private:
67 msat_env const& env;
68 storm::adapters::MathsatExpressionAdapter& expressionAdapter;
69 };
70#endif
71
72 MathsatSmtSolver(storm::expressions::ExpressionManager& manager, Options const& options = Options());
73
74 virtual ~MathsatSmtSolver();
75
76 virtual void push() override;
77
78 virtual void pop() override;
79
80 virtual void pop(uint_fast64_t n) override;
81
82 virtual void reset() override;
83
84 virtual void add(storm::expressions::Expression const& assertion) override;
85
86 virtual CheckResult check() override;
87
88 virtual CheckResult checkWithAssumptions(storm::expressions::ExpressionSet const& assumptions) override;
89
90 virtual CheckResult checkWithAssumptions(std::initializer_list<storm::expressions::Expression> const& assumptions) override;
91
93
94 virtual std::shared_ptr<SmtSolver::ModelReference> getModel() override;
95
96 virtual std::vector<storm::expressions::SimpleValuation> allSat(std::vector<storm::expressions::Variable> const& important) override;
97
98 virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important,
99 std::function<bool(storm::expressions::SimpleValuation&)> const& callback) override;
100
101 virtual uint_fast64_t allSat(std::vector<storm::expressions::Variable> const& important, std::function<bool(ModelReference&)> const& callback) override;
102
103 virtual std::vector<storm::expressions::Expression> getUnsatAssumptions() override;
104
105 virtual void setInterpolationGroup(uint_fast64_t group) override;
106
107 virtual storm::expressions::Expression getInterpolant(std::vector<uint_fast64_t> const& groupsA) override;
108
109 virtual void setTimeout(uint_fast64_t milliseconds) override;
110
111 virtual void unsetTimeout() override;
112
113 private:
114 storm::expressions::SimpleValuation convertMathsatModelToValuation();
115
116#ifdef STORM_HAVE_MATHSAT
120 void startTimeoutClock();
121
125 bool isTimeoutExceeded() const;
126
136 uint_fast64_t processAllSatResult(int result, uint_fast64_t numberOfModels, bool abortedByCallback) const;
137
144 static int terminationTest(void* userData);
145
146 // The MathSAT environment.
147 msat_env env;
148
149 // The expression adapter used to translate expressions to MathSAT's format. This has to be a pointer, since
150 // it must be initialized after creating the environment, but the adapter class has no default constructor.
151 std::unique_ptr<storm::adapters::MathsatExpressionAdapter> expressionAdapter;
152
153 // The timeout for each query (if any).
154 std::optional<std::chrono::milliseconds> timeout;
155
156 // The point in time at which the current query is aborted. Only relevant if a timeout is set.
157 std::chrono::steady_clock::time_point deadline;
158#endif
159
160 // A flag storing whether the last call was a check involving assumptions.
161 bool lastCheckAssumptions;
162
163 // The result of the last call to any of the check methods.
164 CheckResult lastResult;
165
166 // A mapping of interpolation group indices to their MathSAT identifier.
167 typedef boost::container::flat_map<uint_fast64_t, int> InterpolationGroupMapType;
168 InterpolationGroupMapType interpolationGroups;
169};
170} // namespace solver
171} // namespace storm
This class is responsible for managing a set of typed variables and all expressions using these varia...
A simple implementation of the valuation interface.
Options(bool enableModelGeneration=true, bool enableUnsatCoreGeneration=false, bool enableInterpolantGeneration=false)
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.
virtual uint_fast64_t allSat(std::vector< storm::expressions::Variable > const &important, std::function< bool(ModelReference &)> const &callback) override
Performs AllSat over the (provided) important atoms.
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
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
std::set< Expression, ExpressionComparator > ExpressionSet
Definition Expression.h:515
std::string toString(GurobiSolverMethod const &method)
Yields a string representation of the GurobiSolverMethod.
The contract of a DD backend.