2013-02-07 17:50:02 +00:00
|
|
|
#ifndef YAP_PACKAGES_CLPBN_HORUS_BAYESBALLGRAPH_H_
|
|
|
|
#define YAP_PACKAGES_CLPBN_HORUS_BAYESBALLGRAPH_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
#include <vector>
|
2012-12-27 12:54:58 +00:00
|
|
|
#include <unordered_map>
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
#include "Var.h"
|
|
|
|
#include "Horus.h"
|
|
|
|
|
2013-02-16 16:17:14 +00:00
|
|
|
|
2013-02-08 21:12:46 +00:00
|
|
|
namespace Horus {
|
2013-02-07 23:53:13 +00:00
|
|
|
|
2013-02-13 14:26:47 +00:00
|
|
|
class BBNode : public Var {
|
2012-05-23 14:56:01 +01:00
|
|
|
public:
|
2012-12-27 12:54:58 +00:00
|
|
|
BBNode (Var* v) : Var (v), visited_(false),
|
2013-02-16 16:17:14 +00:00
|
|
|
markedAbove_(false), markedBelow_(false) { }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
const std::vector<BBNode*>& childs() const { return childs_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
std::vector<BBNode*>& childs() { return childs_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
const std::vector<BBNode*>& parents() const { return parents_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
std::vector<BBNode*>& parents() { return parents_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-06-19 14:32:12 +01:00
|
|
|
void addParent (BBNode* p) { parents_.push_back (p); }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-06-19 14:32:12 +01:00
|
|
|
void addChild (BBNode* c) { childs_.push_back (c); }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
bool isVisited() const { return visited_; }
|
2012-12-20 23:19:10 +00:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
void setAsVisited() { visited_ = true; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
bool isMarkedAbove() const { return markedAbove_; }
|
2012-12-20 23:19:10 +00:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
void markAbove() { markedAbove_ = true; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
bool isMarkedBelow() const { return markedBelow_; }
|
2012-12-20 23:19:10 +00:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
void markBelow() { markedBelow_ = true; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
void clear() { visited_ = markedAbove_ = markedBelow_ = false; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool visited_;
|
2013-02-16 16:17:14 +00:00
|
|
|
bool markedAbove_;
|
|
|
|
bool markedBelow_;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-07 13:37:15 +00:00
|
|
|
std::vector<BBNode*> childs_;
|
|
|
|
std::vector<BBNode*> parents_;
|
2012-05-23 14:56:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-13 14:26:47 +00:00
|
|
|
class BayesBallGraph {
|
2012-05-23 14:56:01 +01:00
|
|
|
public:
|
2013-02-28 19:45:37 +00:00
|
|
|
BayesBallGraph() { }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
bool empty() const { return nodes_.empty(); }
|
2013-02-06 00:24:02 +00:00
|
|
|
|
2012-06-19 14:32:12 +01:00
|
|
|
void addNode (BBNode* n);
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
void addEdge (VarId vid1, VarId vid2);
|
|
|
|
|
2012-06-19 14:32:12 +01:00
|
|
|
const BBNode* getNode (VarId vid) const;
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2012-06-19 14:32:12 +01:00
|
|
|
BBNode* getNode (VarId vid);
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
void setIndexes();
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
void clear();
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
void exportToGraphViz (const char*);
|
|
|
|
|
|
|
|
private:
|
2013-02-16 16:17:14 +00:00
|
|
|
std::vector<BBNode*> nodes_;
|
|
|
|
std::unordered_map<VarId, BBNode*> varMap_;
|
2012-05-23 14:56:01 +01:00
|
|
|
};
|
|
|
|
|
2013-02-08 21:12:46 +00:00
|
|
|
} // namespace Horus
|
2013-02-07 23:53:13 +00:00
|
|
|
|
2013-02-08 00:20:01 +00:00
|
|
|
#endif // YAP_PACKAGES_CLPBN_HORUS_BAYESBALLGRAPH_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|