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/BayesBallGraph.h

83 lines
1.8 KiB
C
Raw Normal View History

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
namespace Horus {
2013-02-07 23:53:13 +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-07 13:37:15 +00:00
const std::vector<BBNode*>& childs (void) const { return childs_; }
2012-05-23 14:56:01 +01:00
2013-02-07 13:37:15 +00:00
std::vector<BBNode*>& childs (void) { return childs_; }
2012-05-23 14:56:01 +01:00
2013-02-07 13:37:15 +00:00
const std::vector<BBNode*>& parents (void) const { return parents_; }
2012-05-23 14:56:01 +01:00
2013-02-07 13:37:15 +00:00
std::vector<BBNode*>& parents (void) { 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
bool isVisited (void) const { return visited_; }
2012-12-20 23:19:10 +00:00
2012-05-23 14:56:01 +01:00
void setAsVisited (void) { visited_ = true; }
2013-02-16 16:17:14 +00:00
bool isMarkedAbove (void) const { return markedAbove_; }
2012-12-20 23:19:10 +00:00
2013-02-16 16:17:14 +00:00
void markAbove (void) { markedAbove_ = true; }
2012-05-23 14:56:01 +01:00
2013-02-16 16:17:14 +00:00
bool isMarkedBelow (void) const { return markedBelow_; }
2012-12-20 23:19:10 +00:00
2013-02-16 16:17:14 +00:00
void markBelow (void) { markedBelow_ = true; }
2012-05-23 14:56:01 +01:00
2013-02-16 16:17:14 +00:00
void clear (void) { 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
};
class BayesBallGraph {
2012-05-23 14:56:01 +01:00
public:
2012-06-19 14:32:12 +01:00
BayesBallGraph (void) { }
2012-05-23 14:56:01 +01:00
bool empty (void) const { return nodes_.empty(); }
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
void setIndexes (void);
void clear (void);
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
};
} // 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