Skip to content

Commit c5b4e19

Browse files
authored
Merge pull request #1963 from tautschnig/dimacs-output
dimacs: make sure printing a dimacs is fast
2 parents 4f3fb8b + 0afcf90 commit c5b4e19

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/solvers/sat/dimacs_cnf.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Author: Daniel Kroening, [email protected]
99

1010
#include "dimacs_cnf.h"
1111

12+
#include <util/magic.h>
13+
1214
#include <iostream>
15+
#include <sstream>
1316

1417
dimacs_cnft::dimacs_cnft():break_lines(false)
1518
{
@@ -60,9 +63,23 @@ static void write_dimacs_clause(
6063

6164
void dimacs_cnft::write_clauses(std::ostream &out)
6265
{
66+
std::size_t count = 0;
67+
std::stringstream output_block;
6368
for(clausest::const_iterator it=clauses.begin();
6469
it!=clauses.end(); it++)
65-
write_dimacs_clause(*it, out, break_lines);
70+
{
71+
write_dimacs_clause(*it, output_block, break_lines);
72+
73+
// print the block once in a while
74+
if(++count % CNF_DUMP_BLOCK_SIZE == 0)
75+
{
76+
out << output_block.str();
77+
output_block.str("");
78+
}
79+
}
80+
81+
// make sure the final block is printed as well
82+
out << output_block.str();
6683
}
6784

6885
void dimacs_cnf_dumpt::lcnf(const bvt &bv)

src/util/magic.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <cstddef>
99

10+
const std::size_t CNF_DUMP_BLOCK_SIZE = 4096;
1011
const std::size_t MAX_FLATTENED_ARRAY_SIZE=1000;
1112
const std::size_t STRING_REFINEMENT_MAX_CHAR_WIDTH = 16;
1213

0 commit comments

Comments
 (0)