Skip to content

Commit 0210344

Browse files
Add context-based incremental solver interface
Allows to use incremental solvers using a push/pop interface.
1 parent c48a972 commit 0210344

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: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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(
17+
prop_convt &prop_conv)
18+
: prop_convt(), prop_conv(prop_conv)
19+
{
20+
}
21+
22+
decision_proceduret::resultt context_solvert::dec_solve()
23+
{
24+
return prop_conv.dec_solve();
25+
}
26+
27+
literalt context_solvert::convert(const exprt& expr)
28+
{
29+
return prop_conv.convert(expr);
30+
}
31+
32+
exprt context_solvert::get(const exprt& expr) const
33+
{
34+
return prop_conv.get(expr);
35+
}
36+
37+
tvt context_solvert::l_get(literalt l) const
38+
{
39+
return prop_conv.l_get(l);
40+
}
41+
42+
std::string context_solvert::decision_procedure_text() const
43+
{
44+
return prop_conv.decision_procedure_text();
45+
}
46+
47+
void context_solvert::print_assignment(std::ostream &out) const
48+
{
49+
prop_conv.print_assignment(out);
50+
}
51+
52+
void context_solvert::set_frozen(literalt)
53+
{
54+
// unsupported
55+
UNREACHABLE;
56+
}
57+
58+
void context_solvert::set_frozen(const bvt &)
59+
{
60+
// unsupported
61+
UNREACHABLE;
62+
}
63+
64+
void context_solvert::set_assumptions(const bvt &_assumptions)
65+
{
66+
// unsupported
67+
UNREACHABLE;
68+
}
69+
70+
bool context_solvert::has_set_assumptions() const
71+
{
72+
// unsupported
73+
UNREACHABLE;
74+
}
75+
76+
void context_solvert::set_all_frozen()
77+
{
78+
// unsupported
79+
UNREACHABLE;
80+
}
81+
82+
bool context_solvert::is_in_conflict(literalt l) const
83+
{
84+
// unsupported
85+
UNREACHABLE;
86+
}
87+
88+
bool context_solvert::has_is_in_conflict() const
89+
{
90+
// unsupported
91+
UNREACHABLE;
92+
}
93+
94+
void context_solvert::set_time_limit_seconds(uint32_t limit)
95+
{
96+
prop_conv.set_time_limit_seconds(limit);
97+
}
98+
99+
std::size_t context_solvert::get_number_of_solver_calls() const
100+
{
101+
return prop_conv.get_number_of_solver_calls();
102+
}
103+
104+
prop_convt &context_solvert::get_solver() const
105+
{
106+
return prop_conv;
107+
}

src/solvers/prop/context_solver.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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_CONTEXT_SOLVER_H
13+
#define CPROVER_SOLVERS_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+
protected:
82+
explicit context_solvert(prop_convt &prop_conv);
83+
84+
prop_convt &prop_conv;
85+
};
86+
87+
#endif // CPROVER_SOLVERS_PROP_CONTEXT_SOLVER_H

0 commit comments

Comments
 (0)