25 STORM_LOG_ASSERT(variable.getManager() == this->getManager(),
"Requested variable is managed by a different manager.");
29 this->checkVariable(variable);
31 "Cannot retrieve the Boolean value of variable '" << variable.
getName() <<
"' of non-Boolean type.");
32 return this->variableValues.getBooleanValue(variable);
36 this->checkVariable(variable);
40 "Cannot retrieve the integer value of variable '" << variable.
getName() <<
"' of non-integer type.");
41 return this->variableValues.getIntegerValue(variable);
45 this->checkVariable(variable);
47 "Cannot retrieve the rational value of variable '" << variable.
getName() <<
"' of non-rational type.");
48 return this->variableValues.getRationalValue(variable);
52 return this->variableValues.toString();
61 expressionAdapter(nullptr),
62 lastCheckAssumptions(false),
67 this->termManager = std::make_unique<cvc5::TermManager>();
68 this->
solver = std::make_unique<cvc5::Solver>(*this->termManager);
69 this->
solver->setOption(
"produce-models",
"true");
70 this->
solver->setOption(
"produce-unsat-assumptions",
"true");
71 this->
solver->setOption(
"incremental",
"true");
72 this->expressionAdapter = std::make_unique<storm::adapters::Cvc5ExpressionAdapter>(this->
getManager(), *this->
solver);
84 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
92 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
98 this->
solver->pop(
static_cast<uint32_t
>(n));
100 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
105#ifdef STORM_HAVE_CVC5
106 this->
solver->resetAssertions();
108 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
113#ifdef STORM_HAVE_CVC5
114 this->
solver->assertFormula(this->expressionAdapter->translateExpression(assertion));
116 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
121#ifdef STORM_HAVE_CVC5
123 "Unable to create model for formula that was not determined to be satisfiable.");
128 std::vector<storm::expressions::Variable> variables;
129 for (
auto const& variable : this->
getManager().getVariables()) {
130 variables.push_back(variable);
133 cvc5::Term notThisModel = this->createModelExpression(variables);
134 notThisModel = this->termManager->mkTerm(cvc5::Kind::NOT, {notThisModel});
138 this->
solver->assertFormula(notThisModel);
140 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
145#ifdef STORM_HAVE_CVC5
146 this->lastCheckAssumptions =
false;
147 this->lastResult = this->translateResult(this->
solver->checkSat());
148 return this->lastResult;
150 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
155#ifdef STORM_HAVE_CVC5
156 this->lastCheckAssumptions =
true;
157 std::vector<cvc5::Term> cvc5Assumptions;
159 cvc5Assumptions.push_back(this->expressionAdapter->translateExpression(assumption));
161 this->lastResult = this->translateResult(this->
solver->checkSatAssuming(cvc5Assumptions));
162 return this->lastResult;
164 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
169#ifdef STORM_HAVE_CVC5
170 this->lastCheckAssumptions =
true;
171 std::vector<cvc5::Term> cvc5Assumptions;
173 cvc5Assumptions.push_back(this->expressionAdapter->translateExpression(assumption));
175 this->lastResult = this->translateResult(this->
solver->checkSatAssuming(cvc5Assumptions));
176 return this->lastResult;
178 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
182#ifdef STORM_HAVE_CVC5
185 for (
auto const& variableValuePair : this->collectVariableValues()) {
187 cvc5::Term
const& value = variableValuePair.second;
189 stormModel.setBooleanValue(variable, value == this->termManager->mkBoolean(
true));
191 auto const& interpretation = this->expressionAdapter->translateExpression(value);
193 STORM_LOG_ASSERT(integerLiteral !=
nullptr,
"Variable interpretation in model is not an integer.");
194 stormModel.setIntegerValue(variable, integerLiteral->getValue());
199 cvc5::Term approximableValue = value;
200 if (value.isRealAlgebraicNumber()) {
201 STORM_LOG_WARN(
"Interpreting algebraic numbers as rational numbers. This is not an exact computation.");
202 approximableValue = value.getRealAlgebraicNumberLowerBound();
204 auto const& interpretation = this->expressionAdapter->translateExpression(approximableValue);
205 auto const* rationalLiteral =
dynamic_cast<storm::expressions::RationalLiteralExpression const*
>(&interpretation.getBaseExpression());
206 STORM_LOG_ASSERT(rationalLiteral !=
nullptr,
"Variable interpretation in model is not a rational number.");
207 if (rationalLiteral !=
nullptr) {
211 STORM_LOG_THROW(
false, storm::exceptions::ExpressionEvaluationException,
"Variable interpretation in model is not of type bool, int or rational.");
220#ifdef STORM_HAVE_CVC5
222 "Unable to create model for formula that was not determined to be satisfiable.");
223 return this->collectModelAsValuation();
225 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
230#ifdef STORM_HAVE_CVC5
232 "Unable to create model for formula that was not determined to be satisfiable.");
235 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
239std::vector<storm::expressions::SimpleValuation>
Cvc5SmtSolver::allSat(std::vector<storm::expressions::Variable>
const& important) {
240#ifdef STORM_HAVE_CVC5
241 std::vector<storm::expressions::SimpleValuation> valuations;
244 valuations.push_back(valuation);
249 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
255#ifdef STORM_HAVE_CVC5
257 STORM_LOG_THROW(variable.
hasBooleanType(), storm::exceptions::InvalidArgumentException,
"The important atoms for AllSat must be boolean variables.");
260 uint64_t numberOfModels = 0;
270 cvc5::Term modelExpr = this->createModelExpression(important);
274 cvc5::Term value = this->
solver->getValue(this->expressionAdapter->translateExpression(importantAtom));
275 valuation.
setBooleanValue(importantAtom, value == this->termManager->mkBoolean(
true));
279 proceed = callback(valuation);
281 this->
solver->assertFormula(this->termManager->mkTerm(cvc5::Kind::NOT, {modelExpr}));
287 return numberOfModels;
289 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
295#ifdef STORM_HAVE_CVC5
297 STORM_LOG_THROW(variable.
hasBooleanType(), storm::exceptions::InvalidArgumentException,
"The important atoms for AllSat must be boolean variables.");
300 uint64_t numberOfModels = 0;
310 cvc5::Term modelExpr = this->createModelExpression(important);
311 Cvc5ModelReference modelRef(this->
getManager(), this->collectModelAsValuation());
314 proceed = callback(modelRef);
316 this->
solver->assertFormula(this->termManager->mkTerm(cvc5::Kind::NOT, {modelExpr}));
321 return numberOfModels;
323 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
328#ifdef STORM_HAVE_CVC5
330 "Unable to generate unsatisfiable core of assumptions, because the last check did not determine the formulas to be unsatisfiable.");
331 STORM_LOG_THROW(this->lastCheckAssumptions, storm::exceptions::InvalidStateException,
332 "Unable to generate unsatisfiable core of assumptions, because the last check did not involve assumptions.");
334 std::vector<storm::expressions::Expression> unsatAssumptions;
335 for (
auto const& cvc5Assumption : this->
solver->getUnsatAssumptions()) {
336 unsatAssumptions.push_back(this->expressionAdapter->translateExpression(cvc5Assumption));
339 return unsatAssumptions;
341 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
346#ifdef STORM_HAVE_CVC5
347 this->
solver->setOption(
"tlimit-per", std::to_string(milliseconds));
350 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
355#ifdef STORM_HAVE_CVC5
356 this->
solver->setOption(
"tlimit-per",
"0");
359 STORM_LOG_THROW(
false, storm::exceptions::MissingLibraryException,
"Storm is compiled without cvc5 support.");
363#ifdef STORM_HAVE_CVC5
365 if (result.isSat()) {
367 }
else if (result.isUnsat()) {
373std::unordered_map<storm::expressions::Variable, cvc5::Term> Cvc5SmtSolver::collectVariableValues()
const {
374 std::unordered_map<storm::expressions::Variable, cvc5::Term> variableValues;
379 value = this->solver->getValue(this->expressionAdapter->translateExpression(variable));
380 }
catch (std::exception
const&) {
384 variableValues.insert({variable, value});
387 return variableValues;
390cvc5::Term Cvc5SmtSolver::createModelExpression(std::vector<storm::expressions::Variable>
const& variables)
const {
394 auto const modelValues = this->collectVariableValues();
396 cvc5::Term modelExpression = this->termManager->mkBoolean(
true);
397 for (
auto const& variable : variables) {
398 auto const& modelValue = modelValues.find(variable);
399 if (modelValue == modelValues.end()) {
403 cvc5::Term variableTerm = this->expressionAdapter->translateExpression(variable);
405 this->termManager->mkTerm(cvc5::Kind::AND, {modelExpression, this->termManager->mkTerm(cvc5::Kind::EQUAL, {variableTerm, modelValue->second})});
407 return modelExpression;
This class is responsible for managing a set of typed variables and all expressions using these varia...
A simple implementation of the valuation interface.
virtual void setBooleanValue(Variable const &booleanVariable, bool value) override
Sets the value of the given boolean variable to the provided value.
bool isBooleanType() const
Checks whether this type is a boolean type.
bool isIntegerType() const
Checks whether this type is an integral type.
bool isRationalType() const
Checks whether this type is a rational type.
bool hasBooleanType() const
Checks whether the variable is of boolean type.
Type const & getType() const
Retrieves the type of the variable.
std::string const & getName() const
Retrieves the name of the variable.
virtual double getRationalValue(storm::expressions::Variable const &variable) const override
Cvc5ModelReference(storm::expressions::ExpressionManager const &manager, storm::expressions::SimpleValuation variableValues)
Creates a new model reference that provides access to the values that the given model assigns.
virtual bool getBooleanValue(storm::expressions::Variable const &variable) const override
virtual int_fast64_t getIntegerValue(storm::expressions::Variable const &variable) const override
virtual std::string toString() const override
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 bool setTimeout(uint_fast64_t milliseconds) override
If supported by the solver, this will limit all subsequent satisfiability queries to the given number...
virtual void push() override
Pushes a backtracking point on the solver's stack.
virtual void addNotCurrentModel(bool performSolverReset=true) override
If supported by the solver, this function tells the SMT solver to produce a model different from the ...
virtual storm::expressions::SimpleValuation getModelAsValuation() override
If the last call to check() or checkWithAssumptions() returned Sat, this method retrieves a model tha...
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 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 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 void add(storm::expressions::Expression const &assertion) override
Adds an assertion to 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 pop() override
Pops a backtracking point from the solver's stack.
virtual bool unsetTimeout() override
If supported by the solver, this unsets a previous timeout.
Cvc5SmtSolver(storm::expressions::ExpressionManager &manager)
The base class for all model references.
ModelReference(storm::expressions::ExpressionManager const &manager)
Creates a model reference that uses the given expression manager.
storm::expressions::ExpressionManager const & getManager() const
Retrieves the expression manager associated with the solver.
SmtSolver(storm::expressions::ExpressionManager &manager)
Constructs a new Smt solver with the given options.
CheckResult
possible check results
#define STORM_LOG_WARN(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
std::set< Expression, ExpressionComparator > ExpressionSet
std::set< storm::RationalFunctionVariable > getVariables(SparseMatrix< storm::RationalFunction > const &matrix)
TargetType convertNumber(SourceType const &number)