sort the parfactors by their parameters when printing

This commit is contained in:
Tiago Gomes 2012-04-27 19:10:22 +01:00
parent 20fc2c8dd1
commit 52f4aa0340
2 changed files with 18 additions and 3 deletions

View File

@ -113,9 +113,10 @@ ParfactorList::isAllShattered (void) const
void void
ParfactorList::print (void) const ParfactorList::print (void) const
{ {
list<Parfactor*>::const_iterator it; Parfactors pfVec (pfList_.begin(), pfList_.end());
for (it = pfList_.begin(); it != pfList_.end(); ++it) { std::sort (pfVec.begin(), pfVec.end(), sortByParams());
(*it)->print(); for (unsigned i = 0; i < pfVec.size(); i++) {
pfVec[i]->print();
} }
} }

View File

@ -90,6 +90,20 @@ class ParfactorList
const ProbFormula&, ConstraintTree, const ProbFormula&, ConstraintTree,
const ProbFormula&, ConstraintTree) const; const ProbFormula&, ConstraintTree) const;
struct sortByParams
{
inline bool operator() (const Parfactor* pf1, const Parfactor* pf2)
{
if (pf1->params().size() < pf2->params().size()) {
return true;
} else if (pf1->params().size() == pf2->params().size() &&
pf1->params() < pf2->params()) {
return true;
}
return false;
}
};
list<Parfactor*> pfList_; list<Parfactor*> pfList_;
}; };