Skip to content

dimacs: make sure printing a dimacs is fast #1963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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