improvements on shattering
This commit is contained in:
parent
90e139f8f3
commit
346b70145f
@ -646,24 +646,29 @@ ConstraintTree::isCarteesianProduct (const LogVarSet& Xs)
|
|||||||
|
|
||||||
|
|
||||||
std::pair<ConstraintTree*,ConstraintTree*>
|
std::pair<ConstraintTree*,ConstraintTree*>
|
||||||
ConstraintTree::split (
|
ConstraintTree::split (const Tuple& tuple)
|
||||||
const Tuple& tuple,
|
|
||||||
unsigned stopLevel)
|
|
||||||
{
|
{
|
||||||
|
// assumes that my log vars are already on top
|
||||||
|
LogVars lvs (logVars_.begin(), logVars_.begin() + tuple.size());
|
||||||
ConstraintTree tempCt (logVars_, {tuple});
|
ConstraintTree tempCt (logVars_, {tuple});
|
||||||
return split (&tempCt, stopLevel);
|
return split (lvs, &tempCt, lvs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::pair<ConstraintTree*, ConstraintTree*>
|
std::pair<ConstraintTree*, ConstraintTree*>
|
||||||
ConstraintTree::split (
|
ConstraintTree::split (
|
||||||
const ConstraintTree* ct,
|
const LogVars& lvs1,
|
||||||
unsigned stopLevel) const
|
ConstraintTree* ct,
|
||||||
|
const LogVars& lvs2)
|
||||||
{
|
{
|
||||||
assert (stopLevel <= logVars_.size());
|
assert (lvs1.size() == lvs2.size());
|
||||||
assert (stopLevel <= ct->logVars_.size());
|
assert (lvs1.size() == LogVarSet (lvs1).size());
|
||||||
|
assert (lvs2.size() == LogVarSet (lvs2).size());
|
||||||
|
assert (logVarSet_.contains (lvs1));
|
||||||
|
assert (ct->logVarSet().contains (lvs2));
|
||||||
CTChilds commChilds, exclChilds;
|
CTChilds commChilds, exclChilds;
|
||||||
|
unsigned stopLevel = lvs1.size();
|
||||||
split (root_, ct->root(), commChilds, exclChilds, stopLevel);
|
split (root_, ct->root(), commChilds, exclChilds, stopLevel);
|
||||||
ConstraintTree* commCt = new ConstraintTree (commChilds, logVars_);
|
ConstraintTree* commCt = new ConstraintTree (commChilds, logVars_);
|
||||||
ConstraintTree* exclCt = new ConstraintTree (exclChilds, logVars_);
|
ConstraintTree* exclCt = new ConstraintTree (exclChilds, logVars_);
|
||||||
@ -802,32 +807,6 @@ ConstraintTree::jointCountNormalize (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
ConstraintTree::identical (
|
|
||||||
const ConstraintTree* ct1,
|
|
||||||
const ConstraintTree* ct2,
|
|
||||||
unsigned stopLevel)
|
|
||||||
{
|
|
||||||
TupleSet ts1 = ct1->tupleSet (stopLevel);
|
|
||||||
TupleSet ts2 = ct2->tupleSet (stopLevel);
|
|
||||||
return ts1 == ts2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
ConstraintTree::disjoint (
|
|
||||||
const ConstraintTree* ct1,
|
|
||||||
const ConstraintTree* ct2,
|
|
||||||
unsigned stopLevel)
|
|
||||||
{
|
|
||||||
TupleSet ts1 = ct1->tupleSet (stopLevel);
|
|
||||||
TupleSet ts2 = ct2->tupleSet (stopLevel);
|
|
||||||
return (ts1 & ts2).empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LogVars
|
LogVars
|
||||||
ConstraintTree::expand (LogVar X)
|
ConstraintTree::expand (LogVar X)
|
||||||
{
|
{
|
||||||
|
@ -185,25 +185,18 @@ class ConstraintTree
|
|||||||
|
|
||||||
TinySet<unsigned> getConditionalCounts (const LogVarSet&);
|
TinySet<unsigned> getConditionalCounts (const LogVarSet&);
|
||||||
|
|
||||||
bool isCarteesianProduct (const LogVarSet&) const;
|
bool isCarteesianProduct (const LogVarSet&);
|
||||||
|
|
||||||
|
std::pair<ConstraintTree*, ConstraintTree*> split (const Tuple&);
|
||||||
|
|
||||||
std::pair<ConstraintTree*, ConstraintTree*> split (
|
std::pair<ConstraintTree*, ConstraintTree*> split (
|
||||||
const Tuple&, unsigned);
|
const LogVars&, ConstraintTree*, const LogVars&);
|
||||||
|
|
||||||
std::pair<ConstraintTree*, ConstraintTree*> split (
|
|
||||||
const ConstraintTree*, unsigned) const;
|
|
||||||
|
|
||||||
ConstraintTrees countNormalize (const LogVarSet&);
|
ConstraintTrees countNormalize (const LogVarSet&);
|
||||||
|
|
||||||
ConstraintTrees jointCountNormalize (
|
ConstraintTrees jointCountNormalize (
|
||||||
ConstraintTree*, ConstraintTree*, LogVar, LogVar, LogVar);
|
ConstraintTree*, ConstraintTree*, LogVar, LogVar, LogVar);
|
||||||
|
|
||||||
static bool identical (
|
|
||||||
const ConstraintTree*, const ConstraintTree*, unsigned);
|
|
||||||
|
|
||||||
static bool disjoint (
|
|
||||||
const ConstraintTree*, const ConstraintTree*, unsigned);
|
|
||||||
|
|
||||||
LogVars expand (LogVar);
|
LogVars expand (LogVar);
|
||||||
|
|
||||||
ConstraintTrees ground (LogVar);
|
ConstraintTrees ground (LogVar);
|
||||||
|
@ -98,6 +98,9 @@ ParfactorList::isAllShattered (void) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
vector<Parfactor*> pfs (pfList_.begin(), pfList_.end());
|
vector<Parfactor*> pfs (pfList_.begin(), pfList_.end());
|
||||||
|
for (unsigned i = 0; i < pfs.size(); i++) {
|
||||||
|
assert (isShattered (pfs[i]));
|
||||||
|
}
|
||||||
for (unsigned i = 0; i < pfs.size() - 1; i++) {
|
for (unsigned i = 0; i < pfs.size() - 1; i++) {
|
||||||
for (unsigned j = i + 1; j < pfs.size(); j++) {
|
for (unsigned j = i + 1; j < pfs.size(); j++) {
|
||||||
if (isShattered (pfs[i], pfs[j]) == false) {
|
if (isShattered (pfs[i], pfs[j]) == false) {
|
||||||
@ -117,11 +120,48 @@ ParfactorList::print (void) const
|
|||||||
std::sort (pfVec.begin(), pfVec.end(), sortByParams());
|
std::sort (pfVec.begin(), pfVec.end(), sortByParams());
|
||||||
for (unsigned i = 0; i < pfVec.size(); i++) {
|
for (unsigned i = 0; i < pfVec.size(); i++) {
|
||||||
pfVec[i]->print();
|
pfVec[i]->print();
|
||||||
|
cout << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ParfactorList::isShattered (const Parfactor* g) const
|
||||||
|
{
|
||||||
|
const ProbFormulas& formulas = g->arguments();
|
||||||
|
if (formulas.size() < 2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ConstraintTree ct (*g->constr());
|
||||||
|
for (unsigned i = 0; i < formulas.size() - 1; i++) {
|
||||||
|
for (unsigned j = i + 1; j < formulas.size(); j++) {
|
||||||
|
if (formulas[i].group() == formulas[j].group()) {
|
||||||
|
if (identical (
|
||||||
|
formulas[i], *(g->constr()),
|
||||||
|
formulas[j], *(g->constr())) == false) {
|
||||||
|
g->print();
|
||||||
|
cout << "-> not identical on positions " ;
|
||||||
|
cout << i << " and " << j << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (disjoint (
|
||||||
|
formulas[i], *(g->constr()),
|
||||||
|
formulas[j], *(g->constr())) == false) {
|
||||||
|
g->print();
|
||||||
|
cout << "-> not disjoint on positions " ;
|
||||||
|
cout << i << " and " << j << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ParfactorList::isShattered (
|
ParfactorList::isShattered (
|
||||||
const Parfactor* g1,
|
const Parfactor* g1,
|
||||||
@ -130,18 +170,28 @@ ParfactorList::isShattered (
|
|||||||
assert (g1 != g2);
|
assert (g1 != g2);
|
||||||
const ProbFormulas& fms1 = g1->arguments();
|
const ProbFormulas& fms1 = g1->arguments();
|
||||||
const ProbFormulas& fms2 = g2->arguments();
|
const ProbFormulas& fms2 = g2->arguments();
|
||||||
|
|
||||||
for (unsigned i = 0; i < fms1.size(); i++) {
|
for (unsigned i = 0; i < fms1.size(); i++) {
|
||||||
for (unsigned j = 0; j < fms2.size(); j++) {
|
for (unsigned j = 0; j < fms2.size(); j++) {
|
||||||
if (fms1[i].group() == fms2[j].group()) {
|
if (fms1[i].group() == fms2[j].group()) {
|
||||||
if (identical (
|
if (identical (
|
||||||
fms1[i], *(g1->constr()),
|
fms1[i], *(g1->constr()),
|
||||||
fms2[j], *(g2->constr())) == false) {
|
fms2[j], *(g2->constr())) == false) {
|
||||||
|
g1->print();
|
||||||
|
cout << "^" << endl;
|
||||||
|
g2->print();
|
||||||
|
cout << "-> not identical on group " << fms1[i].group() << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (disjoint (
|
if (disjoint (
|
||||||
fms1[i], *(g1->constr()),
|
fms1[i], *(g1->constr()),
|
||||||
fms2[j], *(g2->constr())) == false) {
|
fms2[j], *(g2->constr())) == false) {
|
||||||
|
g1->print();
|
||||||
|
cout << "^" << endl;
|
||||||
|
g2->print();
|
||||||
|
cout << "-> not disjoint on groups " << fms1[i].group();
|
||||||
|
cout << " and " << fms2[j].group() << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,17 +206,7 @@ void
|
|||||||
ParfactorList::addToShatteredList (Parfactor* g)
|
ParfactorList::addToShatteredList (Parfactor* g)
|
||||||
{
|
{
|
||||||
queue<Parfactor*> residuals;
|
queue<Parfactor*> residuals;
|
||||||
|
residuals.push (g);
|
||||||
Parfactors res = shatterAgainstMySelf (g);
|
|
||||||
if (res.empty()) {
|
|
||||||
residuals.push (g);
|
|
||||||
} else {
|
|
||||||
for (unsigned i = 0; i < res.size(); i++) {
|
|
||||||
residuals.push (res[i]);
|
|
||||||
}
|
|
||||||
delete g;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (residuals.empty() == false) {
|
while (residuals.empty() == false) {
|
||||||
Parfactor* pf = residuals.front();
|
Parfactor* pf = residuals.front();
|
||||||
bool pfSplitted = false;
|
bool pfSplitted = false;
|
||||||
@ -190,7 +230,12 @@ ParfactorList::addToShatteredList (Parfactor* g)
|
|||||||
}
|
}
|
||||||
residuals.pop();
|
residuals.pop();
|
||||||
if (pfSplitted == false) {
|
if (pfSplitted == false) {
|
||||||
addShattered (pf);
|
Parfactors res = shatterAgainstMySelf (pf);
|
||||||
|
if (res.empty()) {
|
||||||
|
addShattered (pf);
|
||||||
|
} else {
|
||||||
|
Util::addToQueue (residuals, res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert (isAllShattered());
|
assert (isAllShattered());
|
||||||
@ -200,6 +245,37 @@ ParfactorList::addToShatteredList (Parfactor* g)
|
|||||||
|
|
||||||
Parfactors
|
Parfactors
|
||||||
ParfactorList::shatterAgainstMySelf (Parfactor* g)
|
ParfactorList::shatterAgainstMySelf (Parfactor* g)
|
||||||
|
{
|
||||||
|
Parfactors pfs;
|
||||||
|
queue<Parfactor*> residuals;
|
||||||
|
residuals.push (g);
|
||||||
|
bool shattered = true;
|
||||||
|
while (residuals.empty() == false) {
|
||||||
|
Parfactor* pf = residuals.front();
|
||||||
|
Parfactors res = shatterAgainstMySelf2 (pf);
|
||||||
|
if (res.empty()) {
|
||||||
|
assert (isShattered (pf));
|
||||||
|
if (shattered) {
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
pfs.push_back (pf);
|
||||||
|
} else {
|
||||||
|
shattered = false;
|
||||||
|
for (unsigned i = 0; i < res.size(); i++) {
|
||||||
|
assert (res[i]->constr()->empty() == false);
|
||||||
|
residuals.push (res[i]);
|
||||||
|
}
|
||||||
|
delete pf;
|
||||||
|
}
|
||||||
|
residuals.pop();
|
||||||
|
}
|
||||||
|
return pfs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Parfactors
|
||||||
|
ParfactorList::shatterAgainstMySelf2 (Parfactor* g)
|
||||||
{
|
{
|
||||||
// slip a parfactor with overlapping formulas:
|
// slip a parfactor with overlapping formulas:
|
||||||
// e.g. {s(X),s(Y)}, with (X,Y) in {(p1,p2),(p1,p3),(p4,p1)}
|
// e.g. {s(X),s(Y)}, with (X,Y) in {(p1,p2),(p1,p3),(p4,p1)}
|
||||||
@ -225,6 +301,16 @@ ParfactorList::shatterAgainstMySelf (
|
|||||||
unsigned fIdx1,
|
unsigned fIdx1,
|
||||||
unsigned fIdx2)
|
unsigned fIdx2)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
Util::printDashedLine();
|
||||||
|
cout << "-> SHATTERING" << endl;
|
||||||
|
g->print();
|
||||||
|
cout << "-> ON: " << g->argument (fIdx1) << "|" ;
|
||||||
|
cout << g->constr()->tupleSet (g->argument (fIdx1).logVars()) << endl;
|
||||||
|
cout << "-> ON: " << g->argument (fIdx2) << "|" ;
|
||||||
|
cout << g->constr()->tupleSet (g->argument (fIdx2).logVars()) << endl;
|
||||||
|
Util::printDashedLine();
|
||||||
|
*/
|
||||||
ProbFormula& f1 = g->argument (fIdx1);
|
ProbFormula& f1 = g->argument (fIdx1);
|
||||||
ProbFormula& f2 = g->argument (fIdx2);
|
ProbFormula& f2 = g->argument (fIdx2);
|
||||||
if (f1.isAtom()) {
|
if (f1.isAtom()) {
|
||||||
@ -243,7 +329,7 @@ ParfactorList::shatterAgainstMySelf (
|
|||||||
ctCopy.moveToTop (f2.logVars());
|
ctCopy.moveToTop (f2.logVars());
|
||||||
|
|
||||||
std::pair<ConstraintTree*,ConstraintTree*> split1 =
|
std::pair<ConstraintTree*,ConstraintTree*> split1 =
|
||||||
g->constr()->split (&ctCopy, f1.arity());
|
g->constr()->split (f1.logVars(), &ctCopy, f2.logVars());
|
||||||
ConstraintTree* commCt1 = split1.first;
|
ConstraintTree* commCt1 = split1.first;
|
||||||
ConstraintTree* exclCt1 = split1.second;
|
ConstraintTree* exclCt1 = split1.second;
|
||||||
|
|
||||||
@ -253,19 +339,29 @@ ParfactorList::shatterAgainstMySelf (
|
|||||||
delete exclCt1;
|
delete exclCt1;
|
||||||
return { };
|
return { };
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned newGroup = ProbFormula::getNewGroup();
|
unsigned newGroup = ProbFormula::getNewGroup();
|
||||||
Parfactors res1 = shatter (g, fIdx1, commCt1, exclCt1, newGroup);
|
Parfactors res1 = shatter (g, fIdx1, commCt1, exclCt1, newGroup);
|
||||||
if (res1.empty()) {
|
if (res1.empty()) {
|
||||||
res1.push_back (g);
|
res1.push_back (g);
|
||||||
}
|
}
|
||||||
|
|
||||||
Parfactors res;
|
Parfactors res;
|
||||||
ctCopy.moveToTop (f1.logVars());
|
ctCopy.moveToTop (f1.logVars());
|
||||||
for (unsigned i = 0; i < res1.size(); i++) {
|
for (unsigned i = 0; i < res1.size(); i++) {
|
||||||
res1[i]->constr()->moveToTop (f2.logVars());
|
res1[i]->constr()->moveToTop (f2.logVars());
|
||||||
std::pair<ConstraintTree*, ConstraintTree*> split2;
|
std::pair<ConstraintTree*, ConstraintTree*> split2;
|
||||||
split2 = res1[i]->constr()->split (&ctCopy, f2.arity());
|
split2 = res1[i]->constr()->split (f2.logVars(), &ctCopy, f1.logVars());
|
||||||
ConstraintTree* commCt2 = split2.first;
|
ConstraintTree* commCt2 = split2.first;
|
||||||
ConstraintTree* exclCt2 = split2.second;
|
ConstraintTree* exclCt2 = split2.second;
|
||||||
|
if (commCt2->empty()) {
|
||||||
|
if (res1[i] != g) {
|
||||||
|
res.push_back (res1[i]);
|
||||||
|
}
|
||||||
|
delete commCt2;
|
||||||
|
delete exclCt2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
newGroup = ProbFormula::getNewGroup();
|
newGroup = ProbFormula::getNewGroup();
|
||||||
Parfactors res2 = shatter (res1[i], fIdx2, commCt2, exclCt2, newGroup);
|
Parfactors res2 = shatter (res1[i], fIdx2, commCt2, exclCt2, newGroup);
|
||||||
if (res2.empty()) {
|
if (res2.empty()) {
|
||||||
@ -274,6 +370,8 @@ ParfactorList::shatterAgainstMySelf (
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Util::addToVector (res, res2);
|
Util::addToVector (res, res2);
|
||||||
|
for (unsigned j = 0; j < res2.size(); j++) {
|
||||||
|
}
|
||||||
if (res1[i] != g) {
|
if (res1[i] != g) {
|
||||||
delete res1[i];
|
delete res1[i];
|
||||||
}
|
}
|
||||||
@ -319,17 +417,18 @@ ParfactorList::shatter (
|
|||||||
{
|
{
|
||||||
ProbFormula& f1 = g1->argument (fIdx1);
|
ProbFormula& f1 = g1->argument (fIdx1);
|
||||||
ProbFormula& f2 = g2->argument (fIdx2);
|
ProbFormula& f2 = g2->argument (fIdx2);
|
||||||
// cout << endl;
|
/*
|
||||||
// Util::printDashedLine();
|
Util::printDashedLine();
|
||||||
// cout << "-> SHATTERING (#" << g1 << ", #" << g2 << ")" << endl;
|
cout << "-> SHATTERING" << endl;
|
||||||
// g1->print();
|
g1->print();
|
||||||
// cout << "-> WITH" << endl;
|
cout << "-> WITH" << endl;
|
||||||
// g2->print();
|
g2->print();
|
||||||
// cout << "-> ON: " << f1 << "|" ;
|
cout << "-> ON: " << f1 << "|" ;
|
||||||
// cout << g1->constr()->tupleSet (f1.logVars()) << endl;
|
cout << g1->constr()->tupleSet (f1.logVars()) << endl;
|
||||||
// cout << "-> ON: " << f2 << "|" ;
|
cout << "-> ON: " << f2 << "|" ;
|
||||||
// cout << g2->constr()->tupleSet (f2.logVars()) << endl;
|
cout << g2->constr()->tupleSet (f2.logVars()) << endl;
|
||||||
// Util::printDashedLine();
|
Util::printDashedLine();
|
||||||
|
*/
|
||||||
if (f1.isAtom()) {
|
if (f1.isAtom()) {
|
||||||
f2.setGroup (f1.group());
|
f2.setGroup (f1.group());
|
||||||
updateGroups (f2.group(), f1.group());
|
updateGroups (f2.group(), f1.group());
|
||||||
@ -346,7 +445,7 @@ ParfactorList::shatter (
|
|||||||
g2->constr()->moveToTop (f2.logVars());
|
g2->constr()->moveToTop (f2.logVars());
|
||||||
|
|
||||||
std::pair<ConstraintTree*,ConstraintTree*> split1 =
|
std::pair<ConstraintTree*,ConstraintTree*> split1 =
|
||||||
g1->constr()->split (g2->constr(), f1.arity());
|
g1->constr()->split (f1.logVars(), g2->constr(), f2.logVars());
|
||||||
ConstraintTree* commCt1 = split1.first;
|
ConstraintTree* commCt1 = split1.first;
|
||||||
ConstraintTree* exclCt1 = split1.second;
|
ConstraintTree* exclCt1 = split1.second;
|
||||||
|
|
||||||
@ -358,12 +457,12 @@ ParfactorList::shatter (
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ConstraintTree*,ConstraintTree*> split2 =
|
std::pair<ConstraintTree*,ConstraintTree*> split2 =
|
||||||
g2->constr()->split (g1->constr(), f2.arity());
|
g2->constr()->split (f2.logVars(), g1->constr(), f1.logVars());
|
||||||
ConstraintTree* commCt2 = split2.first;
|
ConstraintTree* commCt2 = split2.first;
|
||||||
ConstraintTree* exclCt2 = split2.second;
|
ConstraintTree* exclCt2 = split2.second;
|
||||||
|
|
||||||
assert (commCt1->tupleSet (f1.arity()) ==
|
assert (commCt1->tupleSet (f1.logVars()) ==
|
||||||
commCt2->tupleSet (f2.arity()));
|
commCt2->tupleSet (f2.logVars()));
|
||||||
|
|
||||||
// unsigned static count = 0; count ++;
|
// unsigned static count = 0; count ++;
|
||||||
// stringstream ss1; ss1 << "" << count << "_A.dot" ;
|
// stringstream ss1; ss1 << "" << count << "_A.dot" ;
|
||||||
@ -475,19 +574,19 @@ ParfactorList::updateGroups (unsigned oldGroup, unsigned newGroup)
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
ParfactorList::proper (
|
ParfactorList::proper (
|
||||||
const ProbFormula& f1, ConstraintTree c1,
|
const ProbFormula& f1, ConstraintTree ct1,
|
||||||
const ProbFormula& f2, ConstraintTree c2) const
|
const ProbFormula& f2, ConstraintTree ct2) const
|
||||||
{
|
{
|
||||||
return disjoint (f1, c1, f2, c2)
|
return disjoint (f1, ct1, f2, ct2)
|
||||||
|| identical (f1, c1, f2, c2);
|
|| identical (f1, ct1, f2, ct2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ParfactorList::identical (
|
ParfactorList::identical (
|
||||||
const ProbFormula& f1, ConstraintTree c1,
|
const ProbFormula& f1, ConstraintTree ct1,
|
||||||
const ProbFormula& f2, ConstraintTree c2) const
|
const ProbFormula& f2, ConstraintTree ct2) const
|
||||||
{
|
{
|
||||||
if (f1.sameSkeletonAs (f2) == false) {
|
if (f1.sameSkeletonAs (f2) == false) {
|
||||||
return false;
|
return false;
|
||||||
@ -495,28 +594,26 @@ ParfactorList::identical (
|
|||||||
if (f1.isAtom()) {
|
if (f1.isAtom()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
c1.moveToTop (f1.logVars());
|
TupleSet ts1 = ct1.tupleSet (f1.logVars());
|
||||||
c2.moveToTop (f2.logVars());
|
TupleSet ts2 = ct2.tupleSet (f2.logVars());
|
||||||
return ConstraintTree::identical (
|
return ts1 == ts2;
|
||||||
&c1, &c2, f1.arity());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ParfactorList::disjoint (
|
ParfactorList::disjoint (
|
||||||
const ProbFormula& f1, ConstraintTree c1,
|
const ProbFormula& f1, ConstraintTree ct1,
|
||||||
const ProbFormula& f2, ConstraintTree c2) const
|
const ProbFormula& f2, ConstraintTree ct2) const
|
||||||
{
|
{
|
||||||
if (f1.sameSkeletonAs (f2) == false) {
|
if (f1.sameSkeletonAs (f2) == false) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (f1.isAtom()) {
|
if (f1.isAtom()) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
c1.moveToTop (f1.logVars());
|
TupleSet ts1 = ct1.tupleSet (f1.logVars());
|
||||||
c2.moveToTop (f2.logVars());
|
TupleSet ts2 = ct2.tupleSet (f2.logVars());
|
||||||
return ConstraintTree::disjoint (
|
return (ts1 & ts2).empty();
|
||||||
&c1, &c2, f1.arity());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +59,16 @@ class ParfactorList
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool isShattered (const Parfactor*) const;
|
||||||
|
|
||||||
bool isShattered (const Parfactor*, const Parfactor*) const;
|
bool isShattered (const Parfactor*, const Parfactor*) const;
|
||||||
|
|
||||||
void addToShatteredList (Parfactor*);
|
void addToShatteredList (Parfactor*);
|
||||||
|
|
||||||
Parfactors shatterAgainstMySelf (Parfactor* g);
|
Parfactors shatterAgainstMySelf (Parfactor* g);
|
||||||
|
|
||||||
|
Parfactors shatterAgainstMySelf2 (Parfactor* g);
|
||||||
|
|
||||||
Parfactors shatterAgainstMySelf (
|
Parfactors shatterAgainstMySelf (
|
||||||
Parfactor* g, unsigned fIdx1, unsigned fIdx2);
|
Parfactor* g, unsigned fIdx1, unsigned fIdx2);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user