// Copyright 2008, 2009 Brady J. Garvin
// This file is part of Covering Arrays by Simulated Annealing (CASA).
// CASA is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// CASA is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with CASA. If not, see .
// Other SAT solvers can be substituted by altering SAT.H and SAT.C.
#include "sat/SAT.H"
InputClause::InputClause() :
maxVariable(-1) {}
InputClause::InputClause(Arrayterms) :
maxVariable(-1) {
unsigned size = terms.getSize();
for (unsigned i = 0; i < size; ++i) {
append(terms[i]);
}
}
InputClause::InputClause(Arraysymbols) :
maxVariable(-1) {
unsigned size = symbols.getSize();
for (unsigned i = 0; i < size; ++i) {
append(InputTerm(false, symbols[i]));
}
}
InputClause::~InputClause() {}
InputClause::operator vec&() {
return literals;
}
InputClause::operator const vec&() const {
return literals;
}
void InputClause::clear(){
literals.clear();
}
void InputClause::append(InputTerm term) {
int variable = term.getVariable();
if (variable > maxVariable) {
maxVariable = variable;
}
literals.push(term.isNegated() ? ~Lit(variable) : Lit(variable));
}
void InputClause::undoAppend() {
literals.pop();
}
void SATSolver::reserve(int variables) {
while (variables >= solver.nVars()) {
solver.newVar();
}
}
void SATSolver::addClause(InputClause&clause) {
reserve(clause.getMaxVariable());
solver.addClause(clause);
}
bool SATSolver::operator()(const InputKnown&known) {
reserve(known.getMaxVariable());
return solver.simplify() && solver.solve(known);
}