Skip to content

Commit a84771b

Browse files
Incremental solver implementation for propt-based solvers
Allows us to use, e.g. bv_refinementt, incrementally with a push/pop interface.
1 parent 794fbc4 commit a84771b

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

src/solvers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ SRC = $(BOOLEFORCE_SRC) \
146146
bdd/miniBDD/miniBDD.cpp \
147147
prop/bdd_expr.cpp \
148148
prop/cover_goals.cpp \
149+
prop/incremental_prop_conv_solver.cpp \
149150
prop/incremental_solver.cpp \
150151
prop/literal.cpp \
151152
prop/minimize.cpp \
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************\
2+
3+
Module: Incremental wrapper for propt based refinement solvers
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Incremental wrapper for `propt`-based refinement solvers
11+
12+
#include "incremental_prop_conv_solver.h"
13+
14+
incremental_prop_conv_solvert::incremental_prop_conv_solvert(
15+
const namespacet &ns,
16+
prop_convt &prop_conv)
17+
: incremental_solvert(ns, prop_conv)
18+
{
19+
}
20+
21+
void incremental_prop_conv_solvert::set_to(const exprt &expr, bool value)
22+
{
23+
if(context_literals.empty())
24+
{
25+
// We are in the root context.
26+
prop_conv.set_to(expr, value);
27+
}
28+
else
29+
{
30+
// We have a child context. We add context_literal ==> expr to the formula.
31+
prop_conv.set_to(
32+
or_exprt(literal_exprt(!context_literals.back()), expr), value);
33+
}
34+
}
35+
36+
void incremental_prop_conv_solvert::push_context()
37+
{
38+
// We create a new context literal.
39+
literalt context_literal = prop_conv.convert(symbol_exprt(
40+
"symex::context$" + std::to_string(context_literal_counter++),
41+
bool_typet()));
42+
43+
context_literals.push_back(context_literal);
44+
prop_conv.set_assumptions(context_literals);
45+
}
46+
47+
void incremental_prop_conv_solvert::pop_context()
48+
{
49+
PRECONDITION(!context_literals.empty());
50+
51+
// We remove the last context literal from the stack.
52+
context_literals.pop_back();
53+
prop_conv.set_assumptions(context_literals);
54+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************\
2+
3+
Module: Incremental wrapper for propt based refinement solvers
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Incremental wrapper for `propt`-based refinement solvers
11+
12+
#ifndef CPROVER_SOLVERS_INCREMENTAL_PROP_CONV_SOLVER_H
13+
#define CPROVER_SOLVERS_INCREMENTAL_PROP_CONV_SOLVER_H
14+
15+
#include "incremental_solver.h"
16+
17+
/// Provides a push/pop-context interface for incremental solving
18+
/// to `propt`-based solvers such as `bv_refinementt`.
19+
class incremental_prop_conv_solvert : public incremental_solvert
20+
{
21+
public:
22+
incremental_prop_conv_solvert(const namespacet &ns, prop_convt &prop_conv);
23+
24+
void set_to(const exprt &expr, bool value) override;
25+
26+
void push_context() override;
27+
28+
void pop_context() override;
29+
30+
protected:
31+
// context literals used as assumptions
32+
bvt context_literals;
33+
34+
// unique context literal names
35+
std::size_t context_literal_counter = 0;
36+
};
37+
38+
#endif // CPROVER_SOLVERS_PROP_INCREMENTAL_PROP_CONV_SOLVER_H

0 commit comments

Comments
 (0)