Skip to content

Commit 794fbc4

Browse files
Add incremental solver interface
1 parent 8159961 commit 794fbc4

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-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_solver.cpp \
149150
prop/literal.cpp \
150151
prop/minimize.cpp \
151152
prop/prop.cpp \
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*******************************************************************\
2+
3+
Module: Incremental Solver Interface
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Interface for incremental solvers
11+
12+
#include "incremental_solver.h"
13+
14+
incremental_solvert::incremental_solvert(
15+
const namespacet &ns,
16+
prop_convt &prop_conv)
17+
: prop_convt(ns), prop_conv(prop_conv)
18+
{
19+
}
20+
21+
decision_proceduret::resultt incremental_solvert::dec_solve()
22+
{
23+
solver_calls++;
24+
return prop_conv.dec_solve();
25+
}
26+
27+
literalt incremental_solvert::convert(const exprt& expr)
28+
{
29+
return prop_conv.convert(expr);
30+
}
31+
32+
exprt incremental_solvert::get(const exprt& expr) const
33+
{
34+
return prop_conv.get(expr);
35+
}
36+
37+
tvt incremental_solvert::l_get(literalt l) const
38+
{
39+
return prop_conv.l_get(l);
40+
}
41+
42+
std::string incremental_solvert::decision_procedure_text() const
43+
{
44+
return prop_conv.decision_procedure_text();
45+
}
46+
47+
void incremental_solvert::print_assignment(std::ostream &out) const
48+
{
49+
prop_conv.print_assignment(out);
50+
}
51+
52+
std::size_t incremental_solvert::get_number_of_solver_calls() const
53+
{
54+
return solver_calls;
55+
}
56+
57+
prop_convt &incremental_solvert::get_solver() const
58+
{
59+
return prop_conv;
60+
}

src/solvers/prop/incremental_solver.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*******************************************************************\
2+
3+
Module: Incremental Solver Interface
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Interface for incremental solvers
11+
12+
#ifndef CPROVER_SOLVERS_INCREMENTAL_SOLVER_H
13+
#define CPROVER_SOLVERS_INCREMENTAL_SOLVER_H
14+
15+
#include "prop_conv.h"
16+
17+
/// A `prop_convt` that wraps another `prop_convt` and provides
18+
/// a push/pop-context interface for incremental solving
19+
class incremental_solvert : public prop_convt
20+
{
21+
public:
22+
virtual ~incremental_solvert() = default;
23+
24+
/// Push a new context on the stack
25+
/// This context becomes a child context nested in the current context.
26+
virtual void push_context() = 0;
27+
28+
/// Pop the current context
29+
virtual void pop_context() = 0;
30+
31+
/// Add \p expr to the formula within the current context
32+
void set_to(const exprt &expr, bool value) override = 0;
33+
34+
/// Solve the current formula
35+
decision_proceduret::resultt dec_solve() override;
36+
37+
/// Convert a boolean expression \p expr
38+
literalt convert(const exprt &expr) override;
39+
40+
/// Replace the variables in \p expr by values from the model
41+
exprt get(const exprt &expr) const override;
42+
43+
/// Return the value of the given literal in the model
44+
tvt l_get(literalt) const override;
45+
46+
// return a textual description of the decision procedure
47+
std::string decision_procedure_text() const override;
48+
49+
// print satisfying assignment
50+
void print_assignment(std::ostream &out) const override;
51+
52+
std::size_t get_number_of_solver_calls() const;
53+
54+
/// Returns the underlying solver
55+
prop_convt &get_solver() const;
56+
57+
protected:
58+
incremental_solvert(const namespacet &ns, prop_convt &prop_conv);
59+
60+
prop_convt &prop_conv;
61+
std::size_t solver_calls = 0;
62+
};
63+
64+
#endif // CPROVER_SOLVERS_PROP_INCREMENTAL_SOLVER_H

0 commit comments

Comments
 (0)