support model counting on atom couting nodes - still untested
This commit is contained in:
parent
d4912ea219
commit
a1d0deb638
@ -26,13 +26,21 @@ AndNode::weight (void) const
|
|||||||
double
|
double
|
||||||
SetOrNode::weight (void) const
|
SetOrNode::weight (void) const
|
||||||
{
|
{
|
||||||
// TODO
|
double weightSum = LogAware::addIdenty();
|
||||||
return 0.0;
|
for (unsigned i = 0; i < nrGroundings_ + 1; i++) {
|
||||||
|
nrGrsStack.push (make_pair (i, nrGroundings_ - i));
|
||||||
|
if (Globals::logDomain) {
|
||||||
|
double w = std::log (Util::nrCombinations (nrGroundings_, i));
|
||||||
|
weightSum = Util::logSum (weightSum, w + follow_->weight());
|
||||||
|
} else {
|
||||||
|
weightSum += Util::nrCombinations (nrGroundings_, i) * follow_->weight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return weightSum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
SetAndNode::weight (void) const
|
SetAndNode::weight (void) const
|
||||||
{
|
{
|
||||||
@ -67,14 +75,22 @@ LeafNode::weight (void) const
|
|||||||
assert (clauses()[0].isUnit());
|
assert (clauses()[0].isUnit());
|
||||||
Clause c = clauses()[0];
|
Clause c = clauses()[0];
|
||||||
double weight = c.literals()[0].weight();
|
double weight = c.literals()[0].weight();
|
||||||
LogVarSet lvs = c.constr().logVarSet() - c.ipgLogVars();
|
LogVarSet lvs = c.constr().logVarSet();
|
||||||
|
lvs -= c.ipgLogVars();
|
||||||
|
lvs -= c.positiveCountedLogVars();
|
||||||
|
lvs -= c.negativeCountedLogVars();
|
||||||
unsigned nrGroundings = 1;
|
unsigned nrGroundings = 1;
|
||||||
if (lvs.empty() == false) {
|
if (lvs.empty() == false) {
|
||||||
ConstraintTree ct = c.constr();
|
ConstraintTree ct = c.constr();
|
||||||
ct.project (lvs);
|
ct.project (lvs);
|
||||||
nrGroundings = ct.size();
|
nrGroundings = ct.size();
|
||||||
}
|
}
|
||||||
assert (nrGroundings != 0);
|
// TODO this only works for one counted log var
|
||||||
|
if (c.positiveCountedLogVars().empty() == false) {
|
||||||
|
nrGroundings *= SetOrNode::nrPositives();
|
||||||
|
} else if (c.negativeCountedLogVars().empty() == false) {
|
||||||
|
nrGroundings *= SetOrNode::nrNegatives();
|
||||||
|
}
|
||||||
return Globals::logDomain
|
return Globals::logDomain
|
||||||
? weight * nrGroundings
|
? weight * nrGroundings
|
||||||
: std::pow (weight, nrGroundings);
|
: std::pow (weight, nrGroundings);
|
||||||
@ -85,6 +101,7 @@ LeafNode::weight (void) const
|
|||||||
double
|
double
|
||||||
SmoothNode::weight (void) const
|
SmoothNode::weight (void) const
|
||||||
{
|
{
|
||||||
|
// TODO and what happens if smoothing contains ipg or counted lvs ?
|
||||||
Clauses cs = clauses();
|
Clauses cs = clauses();
|
||||||
double totalWeight = LogAware::multIdenty();
|
double totalWeight = LogAware::multIdenty();
|
||||||
for (size_t i = 0; i < cs.size(); i++) {
|
for (size_t i = 0; i < cs.size(); i++) {
|
||||||
@ -223,12 +240,11 @@ LiftedCircuit::tryUnitPropagation (
|
|||||||
CircuitNode** follow,
|
CircuitNode** follow,
|
||||||
Clauses& clauses)
|
Clauses& clauses)
|
||||||
{
|
{
|
||||||
cout << "ALL CLAUSES:" << endl;
|
// cout << "ALL CLAUSES:" << endl;
|
||||||
Clause::printClauses (clauses);
|
// Clause::printClauses (clauses);
|
||||||
|
|
||||||
for (size_t i = 0; i < clauses.size(); i++) {
|
for (size_t i = 0; i < clauses.size(); i++) {
|
||||||
if (clauses[i].isUnit()) {
|
if (clauses[i].isUnit()) {
|
||||||
cout << clauses[i] << " is unit!" << endl;
|
// cout << clauses[i] << " is unit!" << endl;
|
||||||
Clauses newClauses;
|
Clauses newClauses;
|
||||||
for (size_t j = 0; j < clauses.size(); j++) {
|
for (size_t j = 0; j < clauses.size(); j++) {
|
||||||
if (i != j) {
|
if (i != j) {
|
||||||
@ -453,7 +469,9 @@ LiftedCircuit::tryAtomCounting (
|
|||||||
for (size_t j = 0; j < literals.size(); j++) {
|
for (size_t j = 0; j < literals.size(); j++) {
|
||||||
if (literals[j].logVars().size() == 1) {
|
if (literals[j].logVars().size() == 1) {
|
||||||
// TODO check if not already in ipg and countedlvs
|
// TODO check if not already in ipg and countedlvs
|
||||||
SetOrNode* setOrNode = new SetOrNode (clauses);
|
unsigned nrGroundings = clauses[i].constr().projectedCopy (
|
||||||
|
literals[j].logVars()).size();
|
||||||
|
SetOrNode* setOrNode = new SetOrNode (nrGroundings, clauses);
|
||||||
Clause c1 (clauses[i].constr().projectedCopy (literals[j].logVars()));
|
Clause c1 (clauses[i].constr().projectedCopy (literals[j].logVars()));
|
||||||
Clause c2 (clauses[i].constr().projectedCopy (literals[j].logVars()));
|
Clause c2 (clauses[i].constr().projectedCopy (literals[j].logVars()));
|
||||||
c1.addLiteral (literals[j]);
|
c1.addLiteral (literals[j]);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef HORUS_LIFTEDCIRCUIT_H
|
#ifndef HORUS_LIFTEDCIRCUIT_H
|
||||||
#define HORUS_LIFTEDCIRCUIT_H
|
#define HORUS_LIFTEDCIRCUIT_H
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
#include "LiftedWCNF.h"
|
#include "LiftedWCNF.h"
|
||||||
|
|
||||||
|
|
||||||
@ -46,10 +48,10 @@ class OrNode : public CircuitNode
|
|||||||
: CircuitNode (clauses, explanation),
|
: CircuitNode (clauses, explanation),
|
||||||
leftBranch_(0), rightBranch_(0) { }
|
leftBranch_(0), rightBranch_(0) { }
|
||||||
|
|
||||||
double weight (void) const;
|
|
||||||
|
|
||||||
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
||||||
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
||||||
|
|
||||||
|
double weight (void) const;
|
||||||
private:
|
private:
|
||||||
CircuitNode* leftBranch_;
|
CircuitNode* leftBranch_;
|
||||||
CircuitNode* rightBranch_;
|
CircuitNode* rightBranch_;
|
||||||
@ -79,10 +81,11 @@ class AndNode : public CircuitNode
|
|||||||
: CircuitNode ({}, explanation),
|
: CircuitNode ({}, explanation),
|
||||||
leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
leftBranch_(leftBranch), rightBranch_(rightBranch) { }
|
||||||
|
|
||||||
double weight (void) const;
|
|
||||||
|
|
||||||
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
CircuitNode** leftBranch (void) { return &leftBranch_; }
|
||||||
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
CircuitNode** rightBranch (void) { return &rightBranch_; }
|
||||||
|
|
||||||
|
double weight (void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CircuitNode* leftBranch_;
|
CircuitNode* leftBranch_;
|
||||||
CircuitNode* rightBranch_;
|
CircuitNode* rightBranch_;
|
||||||
@ -93,14 +96,23 @@ class AndNode : public CircuitNode
|
|||||||
class SetOrNode : public CircuitNode
|
class SetOrNode : public CircuitNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SetOrNode (const Clauses& clauses, string explanation = "")
|
SetOrNode (unsigned nrGroundings, const Clauses& clauses)
|
||||||
: CircuitNode (clauses, explanation), follow_(0) { }
|
: CircuitNode (clauses, " AC"), follow_(0),
|
||||||
|
nrGroundings_(nrGroundings) { }
|
||||||
|
|
||||||
|
CircuitNode** follow (void) { return &follow_; }
|
||||||
|
|
||||||
|
static unsigned nrPositives (void) { return nrGrsStack.top().first; }
|
||||||
|
|
||||||
|
static unsigned nrNegatives (void) { return nrGrsStack.top().second; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight (void) const;
|
||||||
|
|
||||||
CircuitNode** follow (void) { return &follow_; }
|
|
||||||
private:
|
private:
|
||||||
CircuitNode* follow_;
|
CircuitNode* follow_;
|
||||||
|
unsigned nrGroundings_;
|
||||||
|
|
||||||
|
static stack<pair<unsigned, unsigned>> nrGrsStack;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -109,15 +121,16 @@ class SetAndNode : public CircuitNode
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SetAndNode (unsigned nrGroundings, const Clauses& clauses)
|
SetAndNode (unsigned nrGroundings, const Clauses& clauses)
|
||||||
: CircuitNode (clauses, " IPG"), nrGroundings_(nrGroundings),
|
: CircuitNode (clauses, " IPG"), follow_(0),
|
||||||
follow_(0) { }
|
nrGroundings_(nrGroundings) { }
|
||||||
|
|
||||||
|
CircuitNode** follow (void) { return &follow_; }
|
||||||
|
|
||||||
double weight (void) const;
|
double weight (void) const;
|
||||||
|
|
||||||
CircuitNode** follow (void) { return &follow_; }
|
|
||||||
private:
|
private:
|
||||||
unsigned nrGroundings_;
|
|
||||||
CircuitNode* follow_;
|
CircuitNode* follow_;
|
||||||
|
unsigned nrGroundings_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -129,12 +142,12 @@ class IncExcNode : public CircuitNode
|
|||||||
: CircuitNode (clauses), plus1Branch_(0),
|
: CircuitNode (clauses), plus1Branch_(0),
|
||||||
plus2Branch_(0), minusBranch_(0) { }
|
plus2Branch_(0), minusBranch_(0) { }
|
||||||
|
|
||||||
double weight (void) const;
|
|
||||||
|
|
||||||
CircuitNode** plus1Branch (void) { return &plus1Branch_; }
|
CircuitNode** plus1Branch (void) { return &plus1Branch_; }
|
||||||
CircuitNode** plus2Branch (void) { return &plus2Branch_; }
|
CircuitNode** plus2Branch (void) { return &plus2Branch_; }
|
||||||
CircuitNode** minusBranch (void) { return &minusBranch_; }
|
CircuitNode** minusBranch (void) { return &minusBranch_; }
|
||||||
|
|
||||||
|
double weight (void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CircuitNode* plus1Branch_;
|
CircuitNode* plus1Branch_;
|
||||||
CircuitNode* plus2Branch_;
|
CircuitNode* plus2Branch_;
|
||||||
|
@ -98,6 +98,10 @@ class Clause
|
|||||||
|
|
||||||
void addNegativeCountedLogVar (LogVar X) { negCountedLvs_.insert (X); }
|
void addNegativeCountedLogVar (LogVar X) { negCountedLvs_.insert (X); }
|
||||||
|
|
||||||
|
LogVarSet positiveCountedLogVars (void) const { return posCountedLvs_; }
|
||||||
|
|
||||||
|
LogVarSet negativeCountedLogVars (void) const { return negCountedLvs_; }
|
||||||
|
|
||||||
bool containsLiteral (LiteralId lid) const;
|
bool containsLiteral (LiteralId lid) const;
|
||||||
|
|
||||||
bool containsPositiveLiteral (LiteralId lid, const LogVarTypes&) const;
|
bool containsPositiveLiteral (LiteralId lid, const LogVarTypes&) const;
|
||||||
|
Reference in New Issue
Block a user