Skip to content

Commit

Permalink
dimacs: make sure printing a dimacs is fast
Browse files Browse the repository at this point in the history
Use stringstreams and print their content to the actual stream only once in a
while to make printing formulas faster.
  • Loading branch information
nmanthey authored and tautschnig committed Mar 22, 2018
1 parent 7e00a30 commit 0afcf90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/solvers/sat/dimacs_cnf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Author: Daniel Kroening, [email protected]

#include "dimacs_cnf.h"

#include <util/magic.h>

#include <iostream>
#include <sstream>

dimacs_cnft::dimacs_cnft():break_lines(false)
{
Expand Down Expand Up @@ -60,9 +63,23 @@ static void write_dimacs_clause(

void dimacs_cnft::write_clauses(std::ostream &out)
{
std::size_t count = 0;
std::stringstream output_block;
for(clausest::const_iterator it=clauses.begin();
it!=clauses.end(); it++)
write_dimacs_clause(*it, out, break_lines);
{
write_dimacs_clause(*it, output_block, break_lines);

// print the block once in a while
if(++count % CNF_DUMP_BLOCK_SIZE == 0)
{
out << output_block.str();
output_block.str("");
}
}

// make sure the final block is printed as well
out << output_block.str();
}

void dimacs_cnf_dumpt::lcnf(const bvt &bv)
Expand Down
1 change: 1 addition & 0 deletions src/util/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cstddef>

const std::size_t CNF_DUMP_BLOCK_SIZE = 4096;
const std::size_t MAX_FLATTENED_ARRAY_SIZE=1000;
const std::size_t STRING_REFINEMENT_MAX_CHAR_WIDTH = 16;

Expand Down

0 comments on commit 0afcf90

Please sign in to comment.