Skip to content

Commit eefa4bb

Browse files
committed
Now "solvefile" works with "allsol"
1 parent 25c116d commit eefa4bb

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/main.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ int main(int argc, char* argv[])
435435
void print_solution_cnf_style(const Solution& solution);
436436
void check_solution(const ANF* anf, const Solution& solution);
437437
void print_solution_anf_style(const Solution& solution);
438+
void clear_solution_file();
438439
void write_solution_to_file_cnf_style(const Solution& solution);
439440
void ban_solution(CMSat::SATSolver& solver, const Solution& solution);
440441

@@ -455,6 +456,7 @@ void solve(Bosph::Bosphorus* mylib, CNF* cnf, ANF* anf) {
455456
solver.add_clause(*cc2);
456457
}
457458

459+
clear_solution_file();
458460
uint32_t number_of_solutions = 0;
459461
while(true) {
460462
CMSat::lbool ret = solver.solve();
@@ -470,9 +472,7 @@ void solve(Bosph::Bosphorus* mylib, CNF* cnf, ANF* anf) {
470472
solution. ret = l_False;
471473
}
472474
print_solution_anf_style(solution);
473-
if (!solution_output_file.empty()) {
474-
write_solution_to_file_cnf_style(solution);
475-
}
475+
write_solution_to_file_cnf_style(solution);
476476
if (ret == CMSat::l_True) {
477477
check_solution(anf, solution);
478478
}
@@ -488,15 +488,35 @@ void solve(Bosph::Bosphorus* mylib, CNF* cnf, ANF* anf) {
488488
}
489489
}
490490

491-
void write_solution_to_file_cnf_style(const Solution& solution)
491+
void clear_solution_file()
492492
{
493+
if (solution_output_file.empty()) {
494+
return;
495+
}
496+
493497
std::ofstream ofs;
494498
ofs.open(solution_output_file);
495499
if (!ofs) {
496500
std::cerr << "c Error opening file \"" << solution_output_file
497501
<< "\" for writing\n";
498502
exit(-1);
499503
}
504+
ofs.close();
505+
}
506+
507+
void write_solution_to_file_cnf_style(const Solution& solution)
508+
{
509+
if (solution_output_file.empty()) {
510+
return;
511+
}
512+
513+
std::ofstream ofs;
514+
ofs.open(solution_output_file, std::ios_base::app);
515+
if (!ofs) {
516+
std::cerr << "c Error opening file \"" << solution_output_file
517+
<< "\" for writing\n";
518+
exit(-1);
519+
}
500520
assert(solution.ret != l_Undef);
501521
ofs << "Solution ";
502522
ofs << ((solution.ret == l_True) ? "SAT" : "UNSAT") << endl;

0 commit comments

Comments
 (0)