Skip to content

Commit 83fac5f

Browse files
Add context-based incremental solver interface
Allows to use incremental solvers using a push/pop interface.
1 parent 804efea commit 83fac5f

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed

src/solvers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ SRC = $(BOOLEFORCE_SRC) \
145145
lowering/popcount.cpp \
146146
bdd/miniBDD/miniBDD.cpp \
147147
prop/bdd_expr.cpp \
148+
prop/context_solver.cpp \
148149
prop/cover_goals.cpp \
149150
prop/literal.cpp \
150151
prop/minimize.cpp \

src/solvers/prop/context_solver.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*******************************************************************\
2+
3+
Module: Context-based Incremental Solver Interface
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Context-based interface for incremental solvers
11+
12+
#include "context_solver.h"
13+
14+
#include <util/invariant.h>
15+
16+
context_solvert::context_solvert(prop_convt &prop_conv)
17+
: prop_convt(), prop_conv(prop_conv)
18+
{
19+
}
20+
21+
decision_proceduret::resultt context_solvert::dec_solve()
22+
{
23+
return prop_conv.dec_solve();
24+
}
25+
26+
literalt context_solvert::convert(const exprt &expr)
27+
{
28+
return prop_conv.convert(expr);
29+
}
30+
31+
exprt context_solvert::get(const exprt &expr) const
32+
{
33+
return prop_conv.get(expr);
34+
}
35+
36+
tvt context_solvert::l_get(literalt l) const
37+
{
38+
return prop_conv.l_get(l);
39+
}
40+
41+
std::string context_solvert::decision_procedure_text() const
42+
{
43+
return prop_conv.decision_procedure_text();
44+
}
45+
46+
void context_solvert::print_assignment(std::ostream &out) const
47+
{
48+
prop_conv.print_assignment(out);
49+
}
50+
51+
void context_solvert::set_frozen(literalt)
52+
{
53+
// unsupported
54+
UNREACHABLE;
55+
}
56+
57+
void context_solvert::set_frozen(const bvt &)
58+
{
59+
// unsupported
60+
UNREACHABLE;
61+
}
62+
63+
void context_solvert::set_assumptions(const bvt &_assumptions)
64+
{
65+
// unsupported
66+
UNREACHABLE;
67+
}
68+
69+
bool context_solvert::has_set_assumptions() const
70+
{
71+
// unsupported
72+
return false;
73+
}
74+
75+
void context_solvert::set_all_frozen()
76+
{
77+
// unsupported
78+
UNREACHABLE;
79+
}
80+
81+
bool context_solvert::is_in_conflict(literalt l) const
82+
{
83+
// unsupported
84+
UNREACHABLE;
85+
}
86+
87+
bool context_solvert::has_is_in_conflict() const
88+
{
89+
// unsupported
90+
return false;
91+
}
92+
93+
void context_solvert::set_time_limit_seconds(uint32_t limit)
94+
{
95+
prop_conv.set_time_limit_seconds(limit);
96+
}
97+
98+
std::size_t context_solvert::get_number_of_solver_calls() const
99+
{
100+
return prop_conv.get_number_of_solver_calls();
101+
}
102+
103+
prop_convt &context_solvert::get_solver() const
104+
{
105+
return prop_conv;
106+
}

src/solvers/prop/context_solver.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*******************************************************************\
2+
3+
Module: Context-based Incremental Solver Interface
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Context-based interface for incremental solvers
11+
12+
#ifndef CPROVER_SOLVERS_PROP_CONTEXT_SOLVER_H
13+
#define CPROVER_SOLVERS_PROP_CONTEXT_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 context_solvert : public prop_convt
20+
{
21+
public:
22+
/// Push a new context on the stack
23+
/// This context becomes a child context nested in the current context.
24+
virtual void push_context() = 0;
25+
26+
/// Pop the current context
27+
virtual void pop_context() = 0;
28+
29+
/// Add \p expr to the formula within the current context
30+
void set_to(const exprt &expr, bool value) override = 0;
31+
32+
/// Solve the current formula
33+
decision_proceduret::resultt dec_solve() override;
34+
35+
/// Convert a Boolean expression \p expr
36+
literalt convert(const exprt &expr) override;
37+
38+
/// Replace the variables in \p expr by values from the model
39+
exprt get(const exprt &expr) const override;
40+
41+
/// Return the value of the given literal in the model
42+
tvt l_get(literalt) const override;
43+
44+
/// Return a textual description of the decision procedure
45+
std::string decision_procedure_text() const override;
46+
47+
/// Print satisfying assignment
48+
void print_assignment(std::ostream &out) const override;
49+
50+
/// Not supported
51+
void set_frozen(literalt) override;
52+
53+
/// Not supported
54+
void set_frozen(const bvt &) override;
55+
56+
/// Not supported
57+
void set_assumptions(const bvt &) override;
58+
59+
/// Not supported
60+
bool has_set_assumptions() const override;
61+
62+
/// Not supported
63+
void set_all_frozen() override;
64+
65+
/// Not supported
66+
bool is_in_conflict(literalt) const override;
67+
68+
/// Not supported
69+
bool has_is_in_conflict() const override;
70+
71+
// Set resource limits
72+
void set_time_limit_seconds(uint32_t) override;
73+
74+
/// Returns the number of incremental solver calls
75+
std::size_t get_number_of_solver_calls() const override;
76+
77+
/// Returns the underlying solver
78+
prop_convt &get_solver() const;
79+
80+
virtual ~context_solvert() = default;
81+
82+
protected:
83+
explicit context_solvert(prop_convt &prop_conv);
84+
85+
prop_convt &prop_conv;
86+
};
87+
88+
#endif // CPROVER_SOLVERS_PROP_CONTEXT_SOLVER_H

0 commit comments

Comments
 (0)