Skip to content

Commit 71e16e8

Browse files
authored
Merge pull request #5607 from diffblue/external-sat-incremental
make the 'external SAT' solver incremental
2 parents 299307b + 6363b4c commit 71e16e8

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/solvers/sat/external_sat.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
#include <util/string_utils.h>
1313
#include <util/tempfile.h>
1414

15-
#include <chrono>
15+
#include <algorithm>
1616
#include <cstdlib>
1717
#include <fstream>
18-
#include <random>
1918
#include <sstream>
2019
#include <string>
21-
#include <thread>
2220

2321
external_satt::external_satt(message_handlert &message_handler, std::string cmd)
2422
: cnf_clause_list_assignmentt(message_handler), solver_cmd(std::move(cmd))
@@ -46,11 +44,18 @@ void external_satt::write_cnf_file(std::string cnf_file)
4644
std::ofstream out(cnf_file);
4745

4846
// We start counting at 1, thus there is one variable fewer.
49-
out << "p cnf " << (no_variables() - 1) << ' ' << no_clauses() << '\n';
47+
out << "p cnf " << (no_variables() - 1) << ' '
48+
<< no_clauses() + assumptions.size() << '\n';
5049

50+
// output the problem clauses
5151
for(auto &c : clauses)
5252
dimacs_cnft::write_dimacs_clause(c, out, false);
5353

54+
// output the assumption clauses
55+
forall_literals(it, assumptions)
56+
if(!it->is_constant())
57+
out << it->dimacs() << " 0\n";
58+
5459
out.close();
5560
}
5661

@@ -161,6 +166,14 @@ external_satt::resultt external_satt::parse_result(std::string solver_output)
161166

162167
external_satt::resultt external_satt::do_prop_solve()
163168
{
169+
// are we assuming 'false'?
170+
if(
171+
std::find(assumptions.begin(), assumptions.end(), const_literal(false)) !=
172+
assumptions.end())
173+
{
174+
return resultt::P_UNSATISFIABLE;
175+
}
176+
164177
// create a temporary file
165178
temporary_filet cnf_file("external-sat", ".cnf");
166179
write_cnf_file(cnf_file());

src/solvers/sat/external_sat.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class external_satt : public cnf_clause_list_assignmentt
1414

1515
bool has_set_assumptions() const override final
1616
{
17-
return false;
17+
return true;
1818
}
1919

2020
bool has_is_in_conflict() const override final
@@ -27,9 +27,16 @@ class external_satt : public cnf_clause_list_assignmentt
2727
bool is_in_conflict(literalt) const override;
2828
void set_assignment(literalt, bool) override;
2929

30+
void set_assumptions(const bvt &_assumptions) override
31+
{
32+
assumptions = _assumptions;
33+
}
34+
3035
protected:
31-
resultt do_prop_solve() override;
3236
std::string solver_cmd;
37+
bvt assumptions;
38+
39+
resultt do_prop_solve() override;
3340
void write_cnf_file(std::string);
3441
std::string execute_solver(std::string);
3542
resultt parse_result(std::string);

0 commit comments

Comments
 (0)