bool testInput1() { bool ok = true; Backend::SP backend(new Backend(20,20)); RawProblem problem; parseProblem("../../data/testInput1.cnf", problem); UpBdd up; vector<bool> has_results; vector<BddReturn> results; Clause clause; has_results.push_back(false); results.push_back(BddReturn()); has_results.push_back(true); clause.push_back(2); results.push_back(BddReturn(SAT,UpBdd(backend->makeImplication(clause),bddOne))); has_results.push_back(true); results.push_back(BddReturn(SAT,UpBdd(backend->makeImplication(problem[0]),bddOne))); has_results.push_back(true); results.push_back(BddReturn(UNSAT,UpBdd())); int i = 0; foreach(Clause clause, problem) { UpBdd tmp = backend->makeClause(clause); BddReturn result = backend->bddAnd(up,tmp); //cout << "bddAnd(" << up.toString() << ", " << tmp.toString(); if (result.first == SAT) { // cout << ") = (SAT, " << result.second.toString() << ")\n"; up = result.second; } else { // cout << ") = UNSAT" << endl; } if (has_results[i]) { ok = ok && ((results[i].first == UNSAT && result.first == UNSAT) || results[i] == result); } i++; };
void minimizeCnf(const vector<Clause>& input, vector<Clause>& output, const vector<Var>& variablesToProjectOut) { vector<Var> variables; for (size_t i = 0; i < input.size(); ++i) { const Clause& cl = input[i]; for (size_t j = 0; j < cl.size(); ++j) { variables.push_back(abs(cl[j])); } } sort(variables.begin(), variables.end()); variables.erase(unique(variables.begin(), variables.end()), variables.end()); #if 0 if (doPrint) { fprintf(stderr, "variables ="); for (size_t i = 0; i < variables.size(); ++i) { fprintf(stderr, " %d", variables[i]); } fprintf(stderr, "\n"); } #endif assert (variables.size() <= maxVariableCountToSimplify); vector<SimplificationClauseSet> temp(input.size()); for (size_t i = 0; i < input.size(); ++i) { const Clause& cl = input[i]; SimplificationClauseSet& sc = temp[i]; sc.positive.reset(); sc.negative.reset(); for (size_t j = 0; j < cl.size(); ++j) { Lit l = cl[j]; pair<vector<Var>::const_iterator, vector<Var>::const_iterator> range = equal_range(variables.begin(), variables.end(), abs(l)); assert (range.first != range.second); size_t idx = range.first - variables.begin(); if (l < 0) { sc.negative.set(idx); } else { sc.positive.set(idx); } } } #if 1 vector<SimplificationClauseSet> oldTemp = temp; #endif vector<unsigned int> variablesToProjectOutInGroup(variablesToProjectOut.size()); for (size_t i = 0; i < variablesToProjectOut.size(); ++i) { variablesToProjectOutInGroup[i] = find(variables.begin(), variables.end(), variablesToProjectOut[i]) - variables.begin(); } doAllMinimizations(temp, variablesToProjectOutInGroup); #if 1 if (doPrint && temp != oldTemp) { fprintf(stderr, "In:\n"); printSignMatrix(oldTemp); fprintf(stderr, "Out:\n"); printSignMatrix(temp); } #endif for (size_t i = 0; i < temp.size(); ++i) { Clause cl; for (size_t j = 0; j < variables.size(); ++j) { if (temp[i].positive.test(j)) { cl.push_back(variables[j]); } else if (temp[i].negative.test(j)) { cl.push_back(-variables[j]); } } output.push_back(cl); } }