Documentation ¶
Overview ¶
Package dimacs implements reading and writing of DIMACS format files for satisfiability problem statement.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeFile ¶
EncodeFile encodes p in DIMACS format and writes the resulting bytes to a new file at path.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads a DIMACS format stream of bytes from an io.Decoder.
func (*Decoder) Clause ¶
Clause returns the last clause decoded from the input stream. The underlying storage of the returned slice is part of an internal buffer. Any attempt to presist the clause must store the literal values in a new slice.
func (*Decoder) Decode ¶
Decode decodes a clause from the input stream. If r can decode a clause true is returned and the clause can be inspected or copied using r.Clause(). If no clause can be decoded false is returned and r.Err() will return any encountered error. If the stream was fully consumed than false will be returned and r.Err() will return nil.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder encodes Lit clauses as a DIMACS format byte stream.
func NewEncoder ¶
NewEncoder initializes a new Encoder. The returned encoder must be closed before it is discarded to avoid a corrupt output stream.
enc := NewEncoder(f) defer enc.Close()
func (*Encoder) Close ¶
Close writes any buffered output to the underlying io.Writer. If the number of encoded clauses is less than the number specified in the header an error is returned.
func (*Encoder) WriteHeader ¶
WriteHeader encodes and writes h to the output stream. WriteHeader must be called only once, before any clauses have been written.
type Lit ¶
type Lit int
Lit is a simple representation of a clause literal. Positive literals are equal to the variable they contain. Negated literals are equal to the negative value (additive inverse) of the variable they contain. The value 0 is not a valid Lit.
type Problem ¶
Problem is the statement of a SAT problem in CNF.
func DecodeFile ¶
DecodeFile opens path and decodes its contents using DecodeProblem.