Skip to content

Commit 243b2ed

Browse files
committed
New CNF dumping setup, fixing empty etc
1 parent 4dd5e72 commit 243b2ed

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

src/arjun.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,18 @@ DLL_PUBLIC const vector<Lit> Arjun::get_internal_cnf(uint32_t& num_cls) const
312312
return cnf;
313313
}
314314

315-
static std::pair<vector<vector<Lit>>, uint32_t> get_simplified_cnf(
316-
SATSolver* solver, vector<uint32_t>& sampl_vars, const bool renumber)
315+
static void get_simplified_cnf(
316+
SATSolver* solver, vector<uint32_t>& sampl_vars, const bool renumber,
317+
vector<vector<Lit>>& cnf, uint32_t& nvars)
317318
{
318-
vector<vector<Lit>> cnf;
319+
assert(cnf.empty());
319320
solver->start_getting_small_clauses(
320321
std::numeric_limits<uint32_t>::max(),
321322
std::numeric_limits<uint32_t>::max(),
322323
false, //red
323324
false, //bva vars
324325
renumber); //simplified
325-
326326
if (renumber) sampl_vars = solver->translate_sampl_set(sampl_vars);
327-
std::sort(sampl_vars.begin(), sampl_vars.end());
328327

329328
bool ret = true;
330329
vector<Lit> clause;
@@ -335,8 +334,7 @@ static std::pair<vector<vector<Lit>>, uint32_t> get_simplified_cnf(
335334
}
336335
}
337336
solver->end_getting_small_clauses();
338-
return std::make_pair(cnf,
339-
renumber ? solver->simplified_nvars() : solver->nVars());
337+
nvars = renumber ? solver->simplified_nvars() : solver->nVars();
340338
}
341339

342340
static void fill_solver(
@@ -387,8 +385,7 @@ static void fill_solver(
387385
}
388386
}
389387

390-
DLL_PUBLIC std::tuple<std::pair<std::vector<std::vector<CMSat::Lit>>, uint32_t>, std::vector<uint32_t>>
391-
Arjun::get_fully_simplified_renumbered_cnf(
388+
DLL_PUBLIC SimplifiedCNF Arjun::get_fully_simplified_renumbered_cnf(
392389
const vector<uint32_t>& sampl_vars, //contains empty_vars!
393390
const uint32_t orig_num_vars,
394391
const bool sparsify,
@@ -438,10 +435,17 @@ Arjun::get_fully_simplified_renumbered_cnf(
438435
str += string(", must-scc-vrepl, must-renumber");
439436
solver.simplify(&dont_elim, &str);
440437

441-
vector<uint32_t> new_sampl_set;
442-
for(const auto& l: dont_elim) new_sampl_set.push_back(l.var());
443-
auto cnf = get_simplified_cnf(&solver, new_sampl_set, renumber);
444-
return std::make_tuple(cnf, new_sampl_set);
438+
vector<uint32_t> new_sampl_vars (sampl_vars);
439+
SimplifiedCNF cnf;
440+
get_simplified_cnf(&solver, new_sampl_vars, renumber, cnf.cnf, cnf.nvars);
441+
442+
vector<uint32_t> empty_occs;
443+
if (arjdata->common.conf.empty_occs_based)
444+
solver.find_equiv_subformula(new_sampl_vars, empty_occs);
445+
std::sort(new_sampl_vars.begin(), new_sampl_vars.end());
446+
cnf.sampling_vars = new_sampl_vars;
447+
cnf.empty_occs = empty_occs.size();
448+
return cnf;
445449
}
446450

447451
DLL_PUBLIC void Arjun::set_pred_forever_cutoff(int pred_forever_cutoff)

src/arjun.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ THE SOFTWARE.
3535
#endif
3636

3737
namespace ArjunNS {
38+
struct SimplifiedCNF {
39+
std::vector<std::vector<CMSat::Lit>> cnf;
40+
std::vector<uint32_t> sampling_vars;
41+
uint32_t nvars;
42+
uint32_t empty_occs;
43+
};
44+
3845
struct ArjPrivateData;
3946
#ifdef _WIN32
4047
class __declspec(dllexport) Arjun
@@ -73,8 +80,7 @@ namespace ArjunNS {
7380
bool get_next_small_clause(std::vector<CMSat::Lit>& ret); //returns FALSE if no more
7481
void end_getting_small_clauses();
7582
const std::vector<CMSat::Lit> get_internal_cnf(uint32_t& num_cls) const;
76-
std::tuple<std::pair<std::vector<std::vector<CMSat::Lit>>, uint32_t>, std::vector<uint32_t>>
77-
get_fully_simplified_renumbered_cnf(
83+
SimplifiedCNF get_fully_simplified_renumbered_cnf(
7884
const std::vector<uint32_t>& sampl_vars,
7985
const uint32_t orig_num_vars,
8086
const bool sparsify = true,

src/main.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -313,28 +313,23 @@ void readInAFile(const string& filename)
313313
#endif
314314
}
315315

316-
void dump_cnf(const std::pair<vector<vector<Lit>>,
317-
uint32_t>& cnf, const vector<uint32_t>& sampl_set,
318-
const uint32_t multiply = 0)
316+
void dump_cnf(const ArjunNS::SimplifiedCNF& simpcnf)
319317
{
320-
uint32_t num_cls = cnf.first.size();
321-
uint32_t max_var = cnf.second;
318+
uint32_t num_cls = simpcnf.cnf.size();
322319
std::ofstream outf;
323320
outf.open(elimtofile.c_str(), std::ios::out);
324-
outf << "p cnf " << max_var << " " << num_cls << endl;
321+
outf << "p cnf " << simpcnf.nvars << " " << num_cls << endl;
325322

326323
//Add projection
327324
outf << "c ind ";
328-
for(const auto& v: sampl_set) {
329-
assert(v < max_var);
325+
for(const auto& v: simpcnf.sampling_vars) {
326+
assert(v < simpcnf.nvars);
330327
outf << v+1 << " ";
331328
}
332329
outf << "0\n";
333330

334-
for(const auto& cl: cnf.first) {
335-
outf << cl << " 0\n";
336-
}
337-
outf << "c MUST MUTIPLY BY 2**" << multiply << endl;
331+
for(const auto& cl: simpcnf.cnf) outf << cl << " 0\n";
332+
outf << "c MUST MUTIPLY BY 2**" << simpcnf.empty_occs << endl;
338333
}
339334

340335
void elim_to_file(
@@ -346,7 +341,7 @@ void elim_to_file(
346341
auto ret = arjun->get_fully_simplified_renumbered_cnf(
347342
sampl_vars, orig_num_vars, sparsify, renumber);
348343

349-
dump_cnf(std::get<0>(ret), std::get<1>(ret), 0);
344+
dump_cnf(ret);
350345
cout << "c [arjun] Done dumping. T: "
351346
<< std::setprecision(2) << (cpuTime() - dump_start_time) << endl;
352347
}

0 commit comments

Comments
 (0)