Skip to content

Commit 3accf8d

Browse files
Natasha Yogananda Jeppudanielsn
Natasha Yogananda Jeppu
authored andcommitted
Store clause counter value from satcheck_minisat instead of storing the clause itself
Add comment to explain solver_clause_num + 1 in solver hardness, change <int> to <size_t> Remove sorting of clause set keeping performance in mind Add additional utility to map program lines to clauses in --dimacs output clang format
1 parent e7a3e5e commit 3accf8d

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

src/solvers/sat/satcheck_minisat2.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,22 @@ void satcheck_minisat2_baset<T>::lcnf(const bvt &bv)
140140

141141
solver->addClause_(c);
142142

143-
size_t solver_clause_num = clause_counter;
144-
with_solver_hardness([&bv, &solver_clause_num](solver_hardnesst &hardness) {
145-
hardness.register_clause(bv, solver_clause_num);
146-
});
143+
// To map clauses to lines of program code, track clause indices in the
144+
// dimacs cnf output. Dimacs output is generated after processing clauses
145+
// to remove duplicates and clauses that are trivially true. Here, a clause
146+
// is checked to see if it can be thus eliminated. If not, add the clause
147+
// index to list of clauses in solver_hardnesst::register_clause().
148+
static size_t cnf_clause_index = 0;
149+
bvt cnf;
150+
bool clause_removed = process_clause(bv, cnf);
151+
152+
if(!clause_removed)
153+
cnf_clause_index++;
154+
155+
with_solver_hardness(
156+
[&bv, &cnf, &clause_removed](solver_hardnesst &hardness) {
157+
hardness.register_clause(bv, cnf, cnf_clause_index, !clause_removed);
158+
});
147159
clause_counter++;
148160
}
149161
catch(const Minisat::OutOfMemoryException &)

src/solvers/solver_hardness.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ void solver_hardnesst::register_assertion_ssas(
9191

9292
void solver_hardnesst::register_clause(
9393
const bvt &bv,
94-
const size_t solver_clause_num)
94+
const bvt &cnf,
95+
const size_t cnf_clause_index,
96+
bool register_cnf)
9597
{
9698
current_hardness.clauses++;
9799
current_hardness.literals += bv.size();
@@ -101,16 +103,16 @@ void solver_hardnesst::register_clause(
101103
current_hardness.variables.insert(literal.var_no());
102104
}
103105

106+
if(register_cnf)
107+
{
104108
#ifdef DEBUG
105-
std::cout << solver_clause_num << ": ";
106-
for(const auto &literal : bv)
107-
std::cout << literal.dimacs() << " ";
108-
std::cout << "0\n";
109+
std::cout << cnf_clause_index << ": ";
110+
for(const auto &literal : cnf)
111+
std::cout << literal.dimacs() << " ";
112+
std::cout << "0\n";
109113
#endif
110-
111-
// The clause_counter is incremented after the call to register_clause.
112-
// Here we add 1 to solver_clause_num to incorporate this increment.
113-
current_hardness.clause_set.push_back(solver_clause_num + 1);
114+
current_hardness.clause_set.push_back(cnf_clause_index);
115+
}
114116
}
115117

116118
void solver_hardnesst::set_outfile(const std::string &file_name)

src/solvers/solver_hardness.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ struct solver_hardnesst
108108
/// \param bv: the clause (vector of literals)
109109
/// \param solver_clause_num: clause counter value passed from
110110
/// `satcheck_minisat2::lcnf`
111-
void register_clause(const bvt &bv, const size_t solver_clause_num);
111+
void register_clause(
112+
const bvt &bv,
113+
const bvt &cnf,
114+
const size_t cnf_clause_index,
115+
bool register_cnf);
112116

113117
void set_outfile(const std::string &file_name);
114118

0 commit comments

Comments
 (0)