An instance implements a complete CNF formula using several Clause instances. More...
#include <formula.h>
Public Member Functions | |
Formula (VariableSet *, std::ostream *, std::string) | |
Creates an instance of Formula which will use the VariableSet of the input. Creates also the DIMACS formated file corresponding to this formula. | |
~Formula () | |
When this instance is destroyed, prints the clauses still in the cnfs attribute. | |
void | newClause () |
Reinitialise the bufferClause attribute to an emtpy one. | |
void | addLit (unsigned int, bool, unsigned int, unsigned int) |
Adds a new variable to the bufferClause attribute, negated if sign==false. | |
void | addLit (unsigned int, bool, unsigned int, unsigned int, unsigned int) |
Adds a new variable to the bufferClause attribute, negated if sign==false. | |
void | addLitCode (int) |
Adds a new variable to the bufferClause attribute from its code. | |
void | pushClause () |
Use this method to put the current clause in the formula modeled by this instance. | |
void | flush () |
Prints the content of the cnfs attribute to the output and reinitialises it. | |
Private Attributes | |
VariableSet * | varSet |
The set of the variables. | |
std::vector< Clause * > | cnfs |
Stores the CNF clauses of this Formula as Clause instances. | |
Clause * | bufferClause |
The clause currently being modified. It is modified by the newClause(), addLit() and pushClause(). | |
std::ostream * | output |
The stream to which the instance must be printed. |
An instance implements a complete CNF formula using several Clause instances.
A CNF formula is the conjunction of an arbitrary number of disjunctive clauses. These are represented by Clause instances stored in a std::vector. Note that the codes of the literals of the clauses are given by a VariableSet instance connected to this one.
The CNF is printed in the ostream specified at the construction as it is build. For efficiency however, it is printed by bursts of at most CLAUSE_BUFFER_SIZE clauses.
Formula::Formula | ( | VariableSet * | S, |
std::ostream * | out, | ||
std::string | comment | ||
) |
Creates an instance of Formula which will use the VariableSet of the input. Creates also the DIMACS formated file corresponding to this formula.
For more info on the DIMACS encoding, see this. A commentary will be added in the beginning of the file.
out | A pointer to the stream where the file must be written. |
comment | The commentary to add on the first line. |
S | A pointer to the VariableSet to link to this Formula. |
Definition at line 17 of file formula.cpp.
Formula::~Formula | ( | ) |
When this instance is destroyed, prints the clauses still in the cnfs attribute.
Definition at line 29 of file formula.cpp.
void Formula::addLit | ( | unsigned int | s, |
bool | sign, | ||
unsigned int | i, | ||
unsigned int | j | ||
) |
Adds a new variable to the bufferClause attribute, negated if sign==false.
s | The subset in which to take the variable |
sign | False if the literal is negated, true otherwise. |
i | First coordinate. |
j | Second coordinate. |
Definition at line 41 of file formula.cpp.
void Formula::addLit | ( | unsigned int | s, |
bool | sign, | ||
unsigned int | i, | ||
unsigned int | j, | ||
unsigned int | k | ||
) |
Adds a new variable to the bufferClause attribute, negated if sign==false.
s | The subset in which to take the variable |
sign | False if the literal is negated, true otherwise. |
i | First coordinate. |
j | Second coordinate. |
k | Third coordinate. |
Definition at line 50 of file formula.cpp.
void Formula::addLitCode | ( | int | c | ) |
Adds a new variable to the bufferClause attribute from its code.
c | The code of the variable to add to the clause. |
Definition at line 59 of file formula.cpp.
void Formula::flush | ( | ) |
Prints the content of the cnfs attribute to the output and reinitialises it.
Definition at line 84 of file formula.cpp.
void Formula::newClause | ( | ) |
Reinitialise the bufferClause attribute to an emtpy one.
Definition at line 35 of file formula.cpp.
void Formula::pushClause | ( | ) |
Use this method to put the current clause in the formula modeled by this instance.
Definition at line 76 of file formula.cpp.
Clause* cnf::Formula::bufferClause [private] |
The clause currently being modified. It is modified by the newClause(), addLit() and pushClause().
std::vector<Clause*> cnf::Formula::cnfs [private] |
std::ostream* cnf::Formula::output [private] |
VariableSet* cnf::Formula::varSet [private] |