Counting Bp: move internal classes to source file

This commit is contained in:
Tiago Gomes 2013-02-20 12:42:05 +00:00
parent 8c2468c28b
commit 8de22f4f0b
2 changed files with 73 additions and 70 deletions

View File

@ -9,6 +9,54 @@
namespace Horus { namespace Horus {
class VarCluster {
public:
VarCluster (const VarNodes& vs) : members_(vs) { }
const VarNode* first (void) const { return members_.front(); }
const VarNodes& members (void) const { return members_; }
VarNode* representative (void) const { return repr_; }
void setRepresentative (VarNode* vn) { repr_ = vn; }
private:
VarNodes members_;
VarNode* repr_;
DISALLOW_COPY_AND_ASSIGN (VarCluster);
};
class FacCluster {
private:
typedef std::vector<VarCluster*> VarClusters;
public:
FacCluster (const FacNodes& fcs, const VarClusters& vcs)
: members_(fcs), varClusters_(vcs) { }
const FacNode* first (void) const { return members_.front(); }
const FacNodes& members (void) const { return members_; }
FacNode* representative (void) const { return repr_; }
void setRepresentative (FacNode* fn) { repr_ = fn; }
VarClusters& varClusters (void) { return varClusters_; }
FacNodes members_;
FacNode* repr_;
VarClusters varClusters_;
DISALLOW_COPY_AND_ASSIGN (FacCluster);
};
bool CountingBp::fif_ = true; bool CountingBp::fif_ = true;
@ -267,7 +315,7 @@ CountingBp::createClusters (
VarSignature CountingBp::VarSignature
CountingBp::getSignature (const VarNode* varNode) CountingBp::getSignature (const VarNode* varNode)
{ {
VarSignature sign; VarSignature sign;
@ -285,7 +333,7 @@ CountingBp::getSignature (const VarNode* varNode)
FacSignature CountingBp::FacSignature
CountingBp::getSignature (const FacNode* facNode) CountingBp::getSignature (const FacNode* facNode)
{ {
FacSignature sign; FacSignature sign;

View File

@ -15,25 +15,9 @@ class VarCluster;
class FacCluster; class FacCluster;
class WeightedBp; class WeightedBp;
typedef long Color;
typedef std::vector<Color> Colors;
typedef std::vector<std::pair<Color,unsigned>> VarSignature;
typedef std::vector<Color> FacSignature;
typedef std::unordered_map<unsigned, Color> DistColorMap; template <class T> inline size_t
typedef std::unordered_map<unsigned, Colors> VarColorMap; hash_combine (size_t seed, const T& v)
typedef std::unordered_map<VarSignature, VarNodes> VarSignMap;
typedef std::unordered_map<FacSignature, FacNodes> FacSignMap;
typedef std::unordered_map<VarId, VarCluster*> VarClusterMap;
typedef std::vector<VarCluster*> VarClusters;
typedef std::vector<FacCluster*> FacClusters;
template <class T>
inline size_t hash_combine (size_t seed, const T& v)
{ {
return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
} }
@ -67,50 +51,6 @@ template <typename T> struct hash<std::vector<T>>
namespace Horus { namespace Horus {
class VarCluster {
public:
VarCluster (const VarNodes& vs) : members_(vs) { }
const VarNode* first (void) const { return members_.front(); }
const VarNodes& members (void) const { return members_; }
VarNode* representative (void) const { return repr_; }
void setRepresentative (VarNode* vn) { repr_ = vn; }
private:
VarNodes members_;
VarNode* repr_;
DISALLOW_COPY_AND_ASSIGN (VarCluster);
};
class FacCluster {
public:
FacCluster (const FacNodes& fcs, const VarClusters& vcs)
: members_(fcs), varClusters_(vcs) { }
const FacNode* first (void) const { return members_.front(); }
const FacNodes& members (void) const { return members_; }
FacNode* representative (void) const { return repr_; }
void setRepresentative (FacNode* fn) { repr_ = fn; }
VarClusters& varClusters (void) { return varClusters_; }
private:
FacNodes members_;
FacNode* repr_;
VarClusters varClusters_;
DISALLOW_COPY_AND_ASSIGN (FacCluster);
};
class CountingBp : public GroundSolver { class CountingBp : public GroundSolver {
public: public:
CountingBp (const FactorGraph& fg); CountingBp (const FactorGraph& fg);
@ -124,6 +64,21 @@ class CountingBp : public GroundSolver {
static void setFindIdenticalFactorsFlag (bool fif) { fif_ = fif; } static void setFindIdenticalFactorsFlag (bool fif) { fif_ = fif; }
private: private:
typedef long Color;
typedef std::vector<Color> Colors;
typedef std::vector<std::pair<Color,unsigned>> VarSignature;
typedef std::vector<Color> FacSignature;
typedef std::vector<VarCluster*> VarClusters;
typedef std::vector<FacCluster*> FacClusters;
typedef std::unordered_map<unsigned, Color> DistColorMap;
typedef std::unordered_map<unsigned, Colors> VarColorMap;
typedef std::unordered_map<VarSignature, VarNodes> VarSignMap;
typedef std::unordered_map<FacSignature, FacNodes> FacSignMap;
typedef std::unordered_map<VarId, VarCluster*> VarClusterMap;
Color getNewColor (void); Color getNewColor (void);
Color getColor (const VarNode* vn) const; Color getColor (const VarNode* vn) const;
@ -156,8 +111,8 @@ class CountingBp : public GroundSolver {
std::vector<std::vector<unsigned>> getWeights (void) const; std::vector<std::vector<unsigned>> getWeights (void) const;
unsigned getWeight (const FacCluster*, unsigned getWeight (const FacCluster*, const VarCluster*,
const VarCluster*, size_t index) const; size_t index) const;
Color freeColor_; Color freeColor_;
Colors varColors_; Colors varColors_;
@ -175,7 +130,7 @@ class CountingBp : public GroundSolver {
inline Color inline CountingBp::Color
CountingBp::getNewColor (void) CountingBp::getNewColor (void)
{ {
++ freeColor_; ++ freeColor_;
@ -184,7 +139,7 @@ CountingBp::getNewColor (void)
inline Color inline CountingBp::Color
CountingBp::getColor (const VarNode* vn) const CountingBp::getColor (const VarNode* vn) const
{ {
return varColors_[vn->getIndex()]; return varColors_[vn->getIndex()];
@ -192,7 +147,7 @@ CountingBp::getColor (const VarNode* vn) const
inline Color inline CountingBp::Color
CountingBp::getColor (const FacNode* fn) const CountingBp::getColor (const FacNode* fn) const
{ {
return facColors_[fn->getIndex()]; return facColors_[fn->getIndex()];
@ -201,7 +156,7 @@ CountingBp::getColor (const FacNode* fn) const
inline void inline void
CountingBp::setColor (const VarNode* vn, Color c) CountingBp::setColor (const VarNode* vn, CountingBp::Color c)
{ {
varColors_[vn->getIndex()] = c; varColors_[vn->getIndex()] = c;
} }