Improve independence

This commit is contained in:
Tiago Gomes 2012-11-07 18:42:11 +00:00
parent 07c6509a79
commit 278f8f77f5
2 changed files with 45 additions and 27 deletions

View File

@ -335,30 +335,27 @@ LiftedCircuit::tryIndependence (
if (clauses.size() == 1) { if (clauses.size() == 1) {
return false; return false;
} }
// TODO compare all subsets with all subsets Clauses depClauses = { clauses[0] };
for (size_t i = 0; i < clauses.size(); i++) { Clauses indepClauses (clauses.begin() + 1, clauses.end());
bool indep = true; bool finish = false;
TinySet<LiteralId> lids1 = clauses[i].lidSet(); while (finish == false) {
for (size_t j = 0; j < clauses.size(); j++) { finish = true;
TinySet<LiteralId> lids2 = clauses[j].lidSet(); for (size_t i = 0; i < indepClauses.size(); i++) {
if (i != j && ((lids1 & lids2).empty() == false)) { if (isIndependentClause (indepClauses[i], depClauses) == false) {
indep = false; depClauses.push_back (indepClauses[i]);
indepClauses.erase (indepClauses.begin() + i);
finish = false;
break; break;
} }
} }
if (indep == true) { }
Clauses newClauses = clauses; if (indepClauses.empty() == false) {
newClauses.erase (newClauses.begin() + i); AndNode* andNode = new AndNode (clauses, " Independence");
stringstream explanation; compile (andNode->leftBranch(), depClauses);
explanation << " Independence on clause Nº " << i ; compile (andNode->rightBranch(), indepClauses);
AndNode* andNode = new AndNode (clauses, explanation.str());
Clauses indepClause = {clauses[i]};
compile (andNode->leftBranch(), indepClause);
compile (andNode->rightBranch(), newClauses);
(*follow) = andNode; (*follow) = andNode;
return true; return true;
} }
}
return false; return false;
} }
@ -653,6 +650,24 @@ LiftedCircuit::shatterCountedLogVarsAux (
bool
LiftedCircuit::isIndependentClause (
Clause& clause,
Clauses& otherClauses) const
{
// TODO consider counted log vars
TinySet<LiteralId> lidSet = clause.lidSet();
for (size_t i = 0; i < otherClauses.size(); i++) {
if ((lidSet & otherClauses[i].lidSet()).empty() == false) {
return false;
}
}
return true;
}
LitLvTypesSet LitLvTypesSet
LiftedCircuit::smoothCircuit (CircuitNode* node) LiftedCircuit::smoothCircuit (CircuitNode* node)
{ {

View File

@ -52,6 +52,7 @@ class OrNode : public CircuitNode
CircuitNode** rightBranch (void) { return &rightBranch_; } CircuitNode** rightBranch (void) { return &rightBranch_; }
double weight (void) const; double weight (void) const;
private: private:
CircuitNode* leftBranch_; CircuitNode* leftBranch_;
CircuitNode* rightBranch_; CircuitNode* rightBranch_;
@ -242,6 +243,8 @@ class LiftedCircuit
bool shatterCountedLogVarsAux (Clauses& clauses, size_t idx1, size_t idx2); bool shatterCountedLogVarsAux (Clauses& clauses, size_t idx1, size_t idx2);
bool isIndependentClause (Clause& clause, Clauses& otherClauses) const;
LitLvTypesSet smoothCircuit (CircuitNode* node); LitLvTypesSet smoothCircuit (CircuitNode* node);
void createSmoothNode (const LitLvTypesSet& lids, void createSmoothNode (const LitLvTypesSet& lids,