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/clpbn/bp/ElimGraph.h

85 lines
1.6 KiB
C
Raw Normal View History

2011-12-12 15:29:51 +00:00
#ifndef HORUS_ELIMGRAPH_H
#define HORUS_ELIMGRAPH_H
#include "unordered_map"
#include "FactorGraph.h"
2012-03-22 11:33:24 +00:00
#include "Horus.h"
2011-12-12 15:29:51 +00:00
using namespace std;
enum ElimHeuristic
{
MIN_NEIGHBORS,
MIN_WEIGHT,
MIN_FILL,
WEIGHTED_MIN_FILL
};
2012-04-05 23:00:48 +01:00
class EgNode : public Var
2012-03-31 23:27:37 +01:00
{
2011-12-12 15:29:51 +00:00
public:
2012-04-05 23:00:48 +01:00
EgNode (VarId vid, unsigned range) : Var (vid, range) { }
2012-03-31 23:27:37 +01:00
void addNeighbor (EgNode* n) { neighs_.push_back (n); }
2011-12-12 15:29:51 +00:00
const vector<EgNode*>& neighbors (void) const { return neighs_; }
2012-03-31 23:27:37 +01:00
2011-12-12 15:29:51 +00:00
private:
vector<EgNode*> neighs_;
};
class ElimGraph
{
public:
2012-04-05 18:38:56 +01:00
ElimGraph (const vector<Factor*>&); // TODO
2012-03-31 23:27:37 +01:00
2011-12-12 15:29:51 +00:00
~ElimGraph (void);
2012-03-31 23:27:37 +01:00
VarIds getEliminatingOrder (const VarIds&);
2012-04-05 18:38:56 +01:00
void print (void) const;
2012-03-31 23:27:37 +01:00
void exportToGraphViz (const char*, bool = true,
const VarIds& = VarIds()) const;
2012-04-05 18:38:56 +01:00
static VarIds getEliminationOrder (const vector<Factor*>, VarIds);
2011-12-12 15:29:51 +00:00
static ElimHeuristic elimHeuristic;
2012-04-18 03:03:29 +01:00
2011-12-12 15:29:51 +00:00
private:
2012-04-05 18:38:56 +01:00
void addEdge (EgNode* n1, EgNode* n2)
{
assert (n1 != n2);
n1->addNeighbor (n2);
n2->addNeighbor (n1);
}
void addNode (EgNode*);
EgNode* getEgNode (VarId) const;
2012-03-31 23:27:37 +01:00
EgNode* getLowestCostNode (void) const;
unsigned getNeighborsCost (const EgNode*) const;
unsigned getWeightCost (const EgNode*) const;
unsigned getFillCost (const EgNode*) const;
unsigned getWeightedFillCost (const EgNode*) const;
void connectAllNeighbors (const EgNode*);
2011-12-12 15:29:51 +00:00
2012-03-31 23:27:37 +01:00
bool neighbors (const EgNode*, const EgNode*) const;
2011-12-12 15:29:51 +00:00
vector<EgNode*> nodes_;
vector<bool> marked_;
2012-04-05 18:38:56 +01:00
unordered_map<VarId, EgNode*> varMap_;
2011-12-12 15:29:51 +00:00
};
#endif // HORUS_ELIMGRAPH_H