This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/CLPBN/horus/BayesBall.h
2013-02-16 16:17:14 +00:00

75 lines
1.6 KiB
C++

#ifndef YAP_PACKAGES_CLPBN_HORUS_BAYESBALL_H_
#define YAP_PACKAGES_CLPBN_HORUS_BAYESBALL_H_
#include <vector>
#include <queue>
#include <list>
#include "FactorGraph.h"
#include "BayesBallGraph.h"
#include "Horus.h"
namespace Horus {
struct ScheduleInfo {
ScheduleInfo (BBNode* n, bool vfp, bool vfc)
: node(n), visitedFromParent(vfp), visitedFromChild(vfc) { }
BBNode* node;
bool visitedFromParent;
bool visitedFromChild;
};
typedef std::queue<ScheduleInfo, std::list<ScheduleInfo>> Scheduling;
class BayesBall {
public:
BayesBall (FactorGraph& fg);
FactorGraph* getMinimalFactorGraph (const VarIds&);
static FactorGraph* getMinimalFactorGraph (FactorGraph& fg, VarIds vids);
private:
void constructGraph (FactorGraph* fg) const;
void scheduleParents (const BBNode* n, Scheduling& sch) const;
void scheduleChilds (const BBNode* n, Scheduling& sch) const;
FactorGraph& fg_;
BayesBallGraph& dag_;
};
inline void
BayesBall::scheduleParents (const BBNode* n, Scheduling& sch) const
{
const std::vector<BBNode*>& ps = n->parents();
for (std::vector<BBNode*>::const_iterator it = ps.begin();
it != ps.end(); ++it) {
sch.push (ScheduleInfo (*it, false, true));
}
}
inline void
BayesBall::scheduleChilds (const BBNode* n, Scheduling& sch) const
{
const std::vector<BBNode*>& cs = n->childs();
for (std::vector<BBNode*>::const_iterator it = cs.begin();
it != cs.end(); ++it) {
sch.push (ScheduleInfo (*it, true, false));
}
}
} // namespace Horus
#endif // YAP_PACKAGES_CLPBN_HORUS_BAYESBALL_H_