CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dimacs_cnf.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9
10#include "dimacs_cnf.h"
11
12#include <util/invariant.h>
13#include <util/magic.h>
14
16 : cnf_clause_listt(message_handler), break_lines(false)
17{
18}
19
24
26{
28 return false;
29}
30
32 std::ostream &_out,
33 message_handlert &message_handler)
34 : cnft(message_handler), out(_out)
35{
36}
37
38void dimacs_cnft::write_dimacs_cnf(std::ostream &out) const
39{
41 write_clauses(out);
42}
43
44void dimacs_cnft::write_problem_line(std::ostream &out) const
45{
46 // We start counting at 1, thus there is one variable fewer.
47 out << "p cnf " << (no_variables()-1) << " "
48 << clauses.size() << "\n";
49}
50
52 const bvt &clause,
53 std::ostream &out,
54 bool break_lines)
55{
56 // The DIMACS CNF format allows line breaks in clauses:
57 // "Each clauses is terminated by the value 0. Unlike many formats
58 // that represent the end of a clause by a new-line character,
59 // this format allows clauses to be on multiple lines."
60 // Some historic solvers (zchaff e.g.) have silently swallowed
61 // literals in clauses that exceed some fixed buffer size.
62
63 // However, the SAT competition format does not allow line
64 // breaks in clauses, so we offer both options.
65
66 for(size_t j=0; j<clause.size(); j++)
67 {
68 out << clause[j].dimacs() << " ";
69 // newline to avoid overflow in sat checkers
70 if((j&15)==0 && j!=0 && break_lines)
71 out << "\n";
72 }
73
74 out << "0" << "\n";
75}
76
77void dimacs_cnft::write_clauses(std::ostream &out) const
78{
79 std::size_t count = 0;
80 std::stringstream output_block;
81 for(clausest::const_iterator it=clauses.begin();
82 it!=clauses.end(); it++)
83 {
85
86 // print the block once in a while
87 if(++count % CNF_DUMP_BLOCK_SIZE == 0)
88 {
89 out << output_block.str();
90 output_block.str("");
91 }
92 }
93
94 // make sure the final block is printed as well
95 out << output_block.str();
96}
97
99{
101}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Definition cnf.h:18
virtual size_t no_variables() const override
Definition cnf.h:42
std::ostream & out
Definition dimacs_cnf.h:74
dimacs_cnf_dumpt(std::ostream &_out, message_handlert &message_handler)
void lcnf(const bvt &bv) override
bool is_in_conflict(literalt l) const override
Returns true if an assumption is in the final conflict.
dimacs_cnft(message_handlert &)
void write_clauses(std::ostream &out) const
static void write_dimacs_clause(const bvt &, std::ostream &, bool break_lines)
bool break_lines
Definition dimacs_cnf.h:42
void set_assignment(literalt a, bool value) override
virtual void write_dimacs_cnf(std::ostream &out) const
void write_problem_line(std::ostream &out) const
std::vector< literalt > bvt
Definition literal.h:201
Magic numbers used throughout the codebase.
const std::size_t CNF_DUMP_BLOCK_SIZE
Definition magic.h:10
#define UNREACHABLE
This should be used to mark dead code.
Definition invariant.h:525
#define UNIMPLEMENTED
Definition invariant.h:558