some clean ups

This commit is contained in:
Tiago Gomes 2012-12-09 22:13:58 +00:00
parent e46d2177b7
commit 90736156ae
2 changed files with 38 additions and 49 deletions

View File

@ -101,9 +101,7 @@ LeafNode::weight (void) const
lvs -= clause_->negCountedLogVars(); lvs -= clause_->negCountedLogVars();
unsigned nrGroundings = 1; unsigned nrGroundings = 1;
if (lvs.empty() == false) { if (lvs.empty() == false) {
ConstraintTree ct = clause_->constr(); nrGroundings = clause_->constr().projectedCopy (lvs).size();
ct.project (lvs);
nrGroundings = ct.size();
} }
if (clause_->posCountedLogVars().empty() == false) { if (clause_->posCountedLogVars().empty() == false) {
nrGroundings *= std::pow (SetOrNode::nrPositives(), nrGroundings *= std::pow (SetOrNode::nrPositives(),
@ -134,9 +132,7 @@ SmoothNode::weight (void) const
lvs -= cs[i]->negCountedLogVars(); lvs -= cs[i]->negCountedLogVars();
unsigned nrGroundings = 1; unsigned nrGroundings = 1;
if (lvs.empty() == false) { if (lvs.empty() == false) {
ConstraintTree ct = cs[i]->constr(); nrGroundings = cs[i]->constr().projectedCopy (lvs).size();
ct.project (lvs);
nrGroundings = ct.size();
} }
if (cs[i]->posCountedLogVars().empty() == false) { if (cs[i]->posCountedLogVars().empty() == false) {
nrGroundings *= std::pow (SetOrNode::nrPositives(), nrGroundings *= std::pow (SetOrNode::nrPositives(),
@ -169,7 +165,7 @@ double
CompilationFailedNode::weight (void) const CompilationFailedNode::weight (void) const
{ {
// weighted model counting in compilation // weighted model counting in compilation
// failed nodes should give nan // failed nodes should give NaN
return 0.0 / 0.0; return 0.0 / 0.0;
} }
@ -474,13 +470,11 @@ LiftedCircuit::tryInclusionExclusion (
for (size_t j = 0; j < indepLits.size(); j++) { for (size_t j = 0; j < indepLits.size(); j++) {
c2->addLiteral (indepLits[j]); c2->addLiteral (indepLits[j]);
} }
clauses.erase (clauses.begin() + i);
Clauses plus1Clauses = Clause::copyClauses (clauses); Clauses plus1Clauses = Clause::copyClauses (clauses);
Clauses plus2Clauses = Clause::copyClauses (clauses); Clauses plus2Clauses = Clause::copyClauses (clauses);
plus1Clauses.erase (plus1Clauses.begin() + i);
plus2Clauses.erase (plus2Clauses.begin() + i);
clauses.erase (clauses.begin() + i);
plus1Clauses.push_back (c1); plus1Clauses.push_back (c1);
plus2Clauses.push_back (c2); plus2Clauses.push_back (c2);
clauses.push_back (c1); clauses.push_back (c1);
@ -828,8 +822,13 @@ LiftedCircuit::createSmoothNode (
{ {
if (missingLits.empty() == false) { if (missingLits.empty() == false) {
if (Globals::verbosity > 1) { if (Globals::verbosity > 1) {
// assert (Util::contains (originClausesMap_, prev)); unordered_map<CircuitNode*, Clauses>::iterator it;
backupClauses_ = originClausesMap_[*prev]; // TODO Clause::copyClauses ? it = originClausesMap_.find (*prev);
if (it != originClausesMap_.end()) {
backupClauses_ = it->second;
} else {
backupClauses_ = { ((dynamic_cast<LeafNode*>(*prev))->clause()) };
}
} }
Clauses clauses; Clauses clauses;
for (size_t i = 0; i < missingLits.size(); i++) { for (size_t i = 0; i < missingLits.size(); i++) {
@ -1131,7 +1130,7 @@ LiftedCircuit::printClauses (
} else if (getCircuitNodeType (node) == CircuitNodeType::SMOOTH_NODE) { } else if (getCircuitNodeType (node) == CircuitNodeType::SMOOTH_NODE) {
clauses = (dynamic_cast<SmoothNode*>(node))->clauses(); clauses = (dynamic_cast<SmoothNode*>(node))->clauses();
} }
if (clauses.empty() == false) { assert (clauses.empty() == false);
os << escapeNode (node); os << escapeNode (node);
os << " [shape=box," << extraOptions << "label=\"" ; os << " [shape=box," << extraOptions << "label=\"" ;
for (size_t i = 0; i < clauses.size(); i++) { for (size_t i = 0; i < clauses.size(); i++) {
@ -1140,8 +1139,5 @@ LiftedCircuit::printClauses (
} }
os << "\"]" ; os << "\"]" ;
os << endl; os << endl;
} else {
os << " [shape=box]" << endl;
}
} }

View File

@ -33,11 +33,6 @@ Literal::toString (
{ {
stringstream ss; stringstream ss;
negated_ ? ss << "¬" : ss << "" ; negated_ ? ss << "¬" : ss << "" ;
// if (negated_ == false) {
// posWeight_ < 0.0 ? ss << "λ" : ss << "Θ" ;
// } else {
// negWeight_ < 0.0 ? ss << "λ" : ss << "Θ" ;
// }
ss << "λ" ; ss << "λ" ;
ss << lid_ ; ss << lid_ ;
if (logVars_.empty() == false) { if (logVars_.empty() == false) {
@ -480,16 +475,14 @@ LiftedWCNF::createClause (LiteralId lid) const
const Literals& literals = clauses_[i]->literals(); const Literals& literals = clauses_[i]->literals();
for (size_t j = 0; j < literals.size(); j++) { for (size_t j = 0; j < literals.size(); j++) {
if (literals[j].lid() == lid) { if (literals[j].lid() == lid) {
// TODO projectedCopy ? ConstraintTree ct = clauses_[i]->constr().projectedCopy (
ConstraintTree ct = clauses_[i]->constr(); literals[j].logVars());
ct.project (literals[j].logVars());
Clause* c = new Clause (ct); Clause* c = new Clause (ct);
c->addLiteral (literals[j]); c->addLiteral (literals[j]);
return c; return c;
} }
} }
} }
abort(); // we should not reach this point
return 0; return 0;
} }
@ -512,8 +505,8 @@ LiftedWCNF::addIndicatorClauses (const ParfactorList& pfList)
const ProbFormulas& formulas = (*it)->arguments(); const ProbFormulas& formulas = (*it)->arguments();
for (size_t i = 0; i < formulas.size(); i++) { for (size_t i = 0; i < formulas.size(); i++) {
if (Util::contains (map_, formulas[i].group()) == false) { if (Util::contains (map_, formulas[i].group()) == false) {
ConstraintTree tempConstr = *(*it)->constr(); ConstraintTree tempConstr = (*it)->constr()->projectedCopy(
tempConstr.project (formulas[i].logVars()); formulas[i].logVars());
Clause* clause = new Clause (tempConstr); Clause* clause = new Clause (tempConstr);
vector<LiteralId> lids; vector<LiteralId> lids;
for (size_t j = 0; j < formulas[i].range(); j++) { for (size_t j = 0; j < formulas[i].range(); j++) {
@ -524,8 +517,8 @@ LiftedWCNF::addIndicatorClauses (const ParfactorList& pfList)
clauses_.push_back (clause); clauses_.push_back (clause);
for (size_t j = 0; j < formulas[i].range() - 1; j++) { for (size_t j = 0; j < formulas[i].range() - 1; j++) {
for (size_t k = j + 1; k < formulas[i].range(); k++) { for (size_t k = j + 1; k < formulas[i].range(); k++) {
ConstraintTree tempConstr2 = *(*it)->constr(); ConstraintTree tempConstr2 = (*it)->constr()->projectedCopy (
tempConstr2.project (formulas[i].logVars()); formulas[i].logVars());
Clause* clause2 = new Clause (tempConstr2); Clause* clause2 = new Clause (tempConstr2);
clause2->addLiteralComplemented (Literal (clause->literals()[j])); clause2->addLiteralComplemented (Literal (clause->literals()[j]));
clause2->addLiteralComplemented (Literal (clause->literals()[k])); clause2->addLiteralComplemented (Literal (clause->literals()[k]));
@ -598,8 +591,8 @@ LiftedWCNF::printFormulaIndicators (void) const
if (Util::contains (allGroups, formulas[i].group()) == false) { if (Util::contains (allGroups, formulas[i].group()) == false) {
allGroups.insert (formulas[i].group()); allGroups.insert (formulas[i].group());
cout << formulas[i] << " | " ; cout << formulas[i] << " | " ;
ConstraintTree tempCt = *(*it)->constr(); ConstraintTree tempCt = (*it)->constr()->projectedCopy (
tempCt.project (formulas[i].logVars()); formulas[i].logVars());
cout << tempCt.tupleSet(); cout << tempCt.tupleSet();
cout << " indicators => " ; cout << " indicators => " ;
vector<LiteralId> indicators = vector<LiteralId> indicators =