From 52f4aa03402d93eb74fd11ac073706a8c9474c82 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Fri, 27 Apr 2012 19:10:22 +0100 Subject: [PATCH] sort the parfactors by their parameters when printing --- packages/CLPBN/clpbn/bp/ParfactorList.cpp | 7 ++++--- packages/CLPBN/clpbn/bp/ParfactorList.h | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/CLPBN/clpbn/bp/ParfactorList.cpp b/packages/CLPBN/clpbn/bp/ParfactorList.cpp index e7899b17b..bca6de33d 100644 --- a/packages/CLPBN/clpbn/bp/ParfactorList.cpp +++ b/packages/CLPBN/clpbn/bp/ParfactorList.cpp @@ -113,9 +113,10 @@ ParfactorList::isAllShattered (void) const void ParfactorList::print (void) const { - list::const_iterator it; - for (it = pfList_.begin(); it != pfList_.end(); ++it) { - (*it)->print(); + Parfactors pfVec (pfList_.begin(), pfList_.end()); + std::sort (pfVec.begin(), pfVec.end(), sortByParams()); + for (unsigned i = 0; i < pfVec.size(); i++) { + pfVec[i]->print(); } } diff --git a/packages/CLPBN/clpbn/bp/ParfactorList.h b/packages/CLPBN/clpbn/bp/ParfactorList.h index a102c0672..a574184d7 100644 --- a/packages/CLPBN/clpbn/bp/ParfactorList.h +++ b/packages/CLPBN/clpbn/bp/ParfactorList.h @@ -90,6 +90,20 @@ class ParfactorList const ProbFormula&, ConstraintTree, 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 pfList_; };