-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This changes the API offered by decision_proceduret to solving under assumptions. Solving under assumptions has been popularised by MiniSat, and is a state-less alternative to context stacks. This change mimics the transition from check-sat to check-sat-assuming that SMT-LIB is undergoing.
- Loading branch information
Showing
17 changed files
with
118 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,21 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "decision_procedure.h" | ||
|
||
#include <util/std_expr.h> | ||
|
||
decision_proceduret::~decision_proceduret() | ||
{ | ||
} | ||
|
||
decision_proceduret::resultt decision_proceduret::operator()() | ||
{ | ||
return dec_solve(); | ||
return dec_solve(nil_exprt()); | ||
} | ||
|
||
decision_proceduret::resultt | ||
decision_proceduret::operator()(const exprt &assumption) | ||
{ | ||
return dec_solve(assumption); | ||
} | ||
|
||
void decision_proceduret::set_to_true(const exprt &expr) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,18 +17,19 @@ Author: Daniel Kroening, [email protected] | |
|
||
class exprt; | ||
|
||
/// An interface for a decision procedure for satisfiability problems. | ||
class decision_proceduret | ||
{ | ||
public: | ||
/// For a Boolean expression \p expr, add the constraint 'expr' if \p value | ||
/// is `true`, otherwise add 'not expr' | ||
virtual void set_to(const exprt &expr, bool value) = 0; | ||
virtual void set_to(const exprt &, bool value) = 0; | ||
|
||
/// For a Boolean expression \p expr, add the constraint 'expr' | ||
void set_to_true(const exprt &expr); | ||
void set_to_true(const exprt &); | ||
|
||
/// For a Boolean expression \p expr, add the constraint 'not expr' | ||
void set_to_false(const exprt &expr); | ||
void set_to_false(const exprt &); | ||
|
||
/// Generate a handle, which is an expression that | ||
/// has the same value as the argument in any model | ||
|
@@ -37,7 +38,7 @@ class decision_proceduret | |
/// \ref set_to. | ||
/// The returned expression may be the expression itself or a more compact | ||
/// but solver-specific representation. | ||
virtual exprt handle(const exprt &expr) = 0; | ||
virtual exprt handle(const exprt &) = 0; | ||
|
||
/// Result of running the decision procedure | ||
enum class resultt | ||
|
@@ -48,12 +49,18 @@ class decision_proceduret | |
}; | ||
|
||
/// Run the decision procedure to solve the problem | ||
/// This corresponds to SMT-LIB's check-sat. | ||
resultt operator()(); | ||
|
||
/// Run the decision procedure to solve the problem under | ||
/// the given assumption. | ||
/// This corresponds to SMT-LIB's check-sat-assuming. | ||
resultt operator()(const exprt &assumption); | ||
|
||
/// Return \p expr with variables replaced by values from satisfying | ||
/// assignment if available. | ||
/// Return `nil` if not available | ||
virtual exprt get(const exprt &expr) const = 0; | ||
virtual exprt get(const exprt &) const = 0; | ||
|
||
/// Print satisfying assignment to \p out | ||
virtual void print_assignment(std::ostream &out) const = 0; | ||
|
@@ -67,8 +74,8 @@ class decision_proceduret | |
virtual ~decision_proceduret(); | ||
|
||
protected: | ||
/// Run the decision procedure to solve the problem | ||
virtual resultt dec_solve() = 0; | ||
/// Implementation of the decision procedure. | ||
virtual resultt dec_solve(const exprt &assumption) = 0; | ||
}; | ||
|
||
/// Add Boolean constraint \p src to decision procedure \p dest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*******************************************************************\ | ||
Module: Unit tests for boolbvt | ||
Author: Daniel Kroening | ||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Unit tests for boolbvt | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/bitvector_types.h> | ||
#include <util/cout_message.h> | ||
#include <util/namespace.h> | ||
#include <util/std_expr.h> | ||
#include <util/symbol_table.h> | ||
|
||
#include <solvers/flattening/boolbv.h> | ||
#include <solvers/sat/satcheck.h> | ||
#include <testing-utils/use_catch.h> | ||
|
||
SCENARIO("boolbvt", "[core][solvers][flattening][boolbvt]") | ||
{ | ||
console_message_handlert message_handler; | ||
message_handler.set_verbosity(0); | ||
|
||
GIVEN("A satisfiable bit-vector formula f") | ||
{ | ||
satcheckt satcheck(message_handler); | ||
symbol_tablet symbol_table; | ||
namespacet ns(symbol_table); | ||
boolbvt boolbv(ns, satcheck, message_handler); | ||
|
||
unsignedbv_typet u32(32); | ||
boolbv << equal_exprt(symbol_exprt("x", u32), from_integer(10, u32)); | ||
|
||
THEN("is indeed satisfiable") | ||
{ | ||
REQUIRE(boolbv() == decision_proceduret::resultt::D_SATISFIABLE); | ||
} | ||
THEN("is unsatisfiable under an inconsistent assumption") | ||
{ | ||
auto assumption = | ||
equal_exprt(symbol_exprt("x", u32), from_integer(11, u32)); | ||
REQUIRE( | ||
boolbv(assumption) == decision_proceduret::resultt::D_UNSATISFIABLE); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters