Move some things around. No functional changes

This commit is contained in:
Tiago Gomes 2013-02-07 22:37:45 +00:00
parent 2992f9e3cf
commit 3738d0b2c6
14 changed files with 118 additions and 119 deletions

View File

@ -100,6 +100,14 @@ class BeliefProp : public GroundSolver
static void setMsgSchedule (MsgSchedule sch) { schedule_ = sch; }
protected:
struct CmpResidual {
bool operator() (const BpLink* l1, const BpLink* l2) {
return l1->residual() > l2->residual();
}};
typedef std::multiset<BpLink*, CmpResidual> SortedOrder;
typedef std::unordered_map<BpLink*, SortedOrder::iterator> BpLinkMap;
SPNodeInfo* ninf (const VarNode* var) const;
SPNodeInfo* ninf (const FacNode* fac) const;
@ -110,14 +118,6 @@ class BeliefProp : public GroundSolver
void updateMessage (BpLink* link);
struct CompareResidual
{
inline bool operator() (const BpLink* link1, const BpLink* link2)
{
return link1->residual() > link2->residual();
}
};
void runSolver (void);
virtual void createLinks (void);
@ -135,16 +135,12 @@ class BeliefProp : public GroundSolver
std::vector<SPNodeInfo*> varsI_;
std::vector<SPNodeInfo*> facsI_;
bool runned_;
SortedOrder sortedOrder_;
BpLinkMap linkMap_;
typedef std::multiset<BpLink*, CompareResidual> SortedOrder;
SortedOrder sortedOrder_;
typedef std::unordered_map<BpLink*, SortedOrder::iterator> BpLinkMap;
BpLinkMap linkMap_;
static double accuracy_;
static unsigned maxIter_;
static MsgSchedule schedule_;
static double accuracy_;
static unsigned maxIter_;
static MsgSchedule schedule_;
private:
void initializeSolver (void);

View File

@ -145,7 +145,8 @@ CTNode::deleteSubtree (CTNode* n)
std::ostream& operator<< (std::ostream &out, const CTNode& n)
std::ostream&
operator<< (std::ostream& out, const CTNode& n)
{
out << "(" << n.level() << ") " ;
out << n.symbol();

View File

@ -13,31 +13,28 @@
class CTNode;
typedef std::vector<CTNode*> CTNodes;
class ConstraintTree;
typedef std::vector<CTNode*> CTNodes;
typedef std::vector<ConstraintTree*> ConstraintTrees;
class CTNode
{
public:
struct CompareSymbol
{
bool operator() (const CTNode* n1, const CTNode* n2) const
{
return n1->symbol() < n2->symbol();
}
};
private:
typedef TinySet<CTNode*, CompareSymbol> CTChilds_;
struct CmpSymbol {
bool operator() (const CTNode* n1, const CTNode* n2) const {
return n1->symbol() < n2->symbol();
}};
public:
CTNode (const CTNode& n, const CTChilds_& chs = CTChilds_())
typedef TinySet<CTNode*, CmpSymbol> CTChilds;
CTNode (const CTNode& n, const CTChilds& chs = CTChilds())
: symbol_(n.symbol()), childs_(chs), level_(n.level()) { }
CTNode (Symbol s, unsigned l, const CTChilds_& chs = CTChilds_())
CTNode (Symbol s, unsigned l, const CTChilds& chs = CTChilds())
: symbol_(s), childs_(chs), level_(l) { }
unsigned level (void) const { return level_; }
@ -48,9 +45,9 @@ class CTNode
void setSymbol (const Symbol s) { symbol_ = s; }
CTChilds_& childs (void) { return childs_; }
CTChilds& childs (void) { return childs_; }
const CTChilds_& childs (void) const { return childs_; }
const CTChilds& childs (void) const { return childs_; }
size_t nrChilds (void) const { return childs_.size(); }
@ -58,7 +55,7 @@ class CTNode
bool isLeaf (void) const { return childs_.empty(); }
CTChilds_::iterator findSymbol (Symbol symb);
CTChilds::iterator findSymbol (Symbol symb);
void mergeSubtree (CTNode*, bool = true);
@ -80,14 +77,14 @@ class CTNode
void updateChildLevels (CTNode*, unsigned);
Symbol symbol_;
CTChilds_ childs_;
CTChilds childs_;
unsigned level_;
DISALLOW_ASSIGN (CTNode);
};
typedef TinySet<CTNode*, CTNode::CompareSymbol> CTChilds;
typedef CTNode::CTChilds CTChilds;
inline CTChilds::iterator
@ -98,7 +95,7 @@ CTNode::findSymbol (Symbol symb)
}
std::ostream& operator<< (std::ostream &out, const CTNode&);
std::ostream& operator<< (std::ostream&, const CTNode&);
class ConstraintTree

View File

@ -135,6 +135,8 @@ class FactorGraph
static void disablePrintFactorGraph (void) { printFg_ = false; }
private:
typedef std::unordered_map<unsigned, VarNode*> VarMap;
void ignoreLines (std::ifstream&) const;
bool containsCycle (void) const;
@ -145,19 +147,16 @@ class FactorGraph
bool containsCycle (const FacNode*, const VarNode*,
std::vector<bool>&, std::vector<bool>&) const;
VarNodes varNodes_;
FacNodes facNodes_;
VarNodes varNodes_;
FacNodes facNodes_;
VarMap varMap_;
BayesBallGraph structure_;
bool bayesFactors_;
typedef std::unordered_map<unsigned, VarNode*> VarMap;
VarMap varMap_;
static bool exportLd_;
static bool exportUai_;
static bool exportGv_;
static bool printFg_;
static bool exportLd_;
static bool exportUai_;
static bool exportGv_;
static bool printFg_;
DISALLOW_ASSIGN (FactorGraph);
};

View File

@ -138,7 +138,8 @@ HistogramSet::clearAfter (size_t idx)
std::ostream& operator<< (std::ostream &os, const HistogramSet& hs)
std::ostream&
operator<< (std::ostream& os, const HistogramSet& hs)
{
os << "#" << hs.hist_;
return os;

View File

@ -36,11 +36,11 @@ class HistogramSet
void clearAfter (size_t);
friend std::ostream& operator<< (std::ostream&, const HistogramSet&);
unsigned size_;
Histogram hist_;
friend std::ostream& operator<< (std::ostream &os, const HistogramSet& hs);
DISALLOW_COPY_AND_ASSIGN (HistogramSet);
};

View File

@ -38,14 +38,14 @@ class Indexer
private:
void calculateOffsets (void);
friend std::ostream& operator<< (std::ostream&, const Indexer&);
size_t index_;
Ranges indices_;
const Ranges& ranges_;
size_t size_;
std::vector<size_t> offsets_;
friend std::ostream& operator<< (std::ostream&, const Indexer&);
DISALLOW_COPY_AND_ASSIGN (Indexer);
};
@ -223,14 +223,14 @@ class MapIndexer
void reset (void);
private:
friend std::ostream& operator<< (std::ostream&, const MapIndexer&);
size_t index_;
Ranges indices_;
const Ranges& ranges_;
bool valid_;
std::vector<size_t> offsets_;
friend std::ostream& operator<< (std::ostream&, const MapIndexer&);
DISALLOW_COPY_AND_ASSIGN (MapIndexer);
};

View File

@ -40,7 +40,8 @@ printSymbolDictionary (void)
std::ostream& operator<< (std::ostream &os, const Symbol& s)
std::ostream&
operator<< (std::ostream& os, const Symbol& s)
{
std::unordered_map<std::string, unsigned>::const_iterator it
= LiftedUtils::symbolDict.begin();
@ -54,7 +55,8 @@ std::ostream& operator<< (std::ostream &os, const Symbol& s)
std::ostream& operator<< (std::ostream &os, const LogVar& X)
std::ostream&
operator<< (std::ostream& os, const LogVar& X)
{
const std::string labels[] = {
"A", "B", "C", "D", "E", "F",
@ -65,7 +67,8 @@ std::ostream& operator<< (std::ostream &os, const LogVar& X)
std::ostream& operator<< (std::ostream &os, const Tuple& t)
std::ostream&
operator<< (std::ostream& os, const Tuple& t)
{
os << "(" ;
for (size_t i = 0; i < t.size(); i++) {
@ -77,7 +80,8 @@ std::ostream& operator<< (std::ostream &os, const Tuple& t)
std::ostream& operator<< (std::ostream &os, const Ground& gr)
std::ostream&
operator<< (std::ostream& os, const Ground& gr)
{
os << gr.functor();
os << "(" ;
@ -111,7 +115,8 @@ Substitution::getDiscardedLogVars (void) const
std::ostream& operator<< (std::ostream &os, const Substitution& theta)
std::ostream&
operator<< (std::ostream& os, const Substitution& theta)
{
std::unordered_map<LogVar, LogVar>::const_iterator it;
os << "[" ;

View File

@ -24,9 +24,9 @@ class Symbol
static Symbol invalid (void) { return Symbol(); }
private:
unsigned id_;
friend std::ostream& operator<< (std::ostream&, const Symbol&);
friend std::ostream& operator<< (std::ostream &os, const Symbol& s);
unsigned id_;
};
@ -44,9 +44,9 @@ class LogVar
bool valid (void) const;
private:
unsigned id_;
friend std::ostream& operator<< (std::ostream&, const LogVar&);
friend std::ostream& operator<< (std::ostream &os, const LogVar& X);
unsigned id_;
};
@ -86,16 +86,16 @@ template <> struct hash<LogVar> {
};
typedef std::vector<Symbol> Symbols;
typedef std::vector<Symbol> Tuple;
typedef std::vector<Tuple> Tuples;
typedef std::vector<LogVar> LogVars;
typedef TinySet<Symbol> SymbolSet;
typedef TinySet<LogVar> LogVarSet;
typedef TinySet<Tuple> TupleSet;
typedef std::vector<Symbol> Symbols;
typedef std::vector<Symbol> Tuple;
typedef std::vector<Tuple> Tuples;
typedef std::vector<LogVar> LogVars;
typedef TinySet<Symbol> SymbolSet;
typedef TinySet<LogVar> LogVarSet;
typedef TinySet<Tuple> TupleSet;
std::ostream& operator<< (std::ostream &os, const Tuple& t);
std::ostream& operator<< (std::ostream&, const Tuple&);
namespace LiftedUtils {
@ -113,7 +113,8 @@ class Ground
public:
Ground (Symbol f) : functor_(f) { }
Ground (Symbol f, const Symbols& args) : functor_(f), args_(args) { }
Ground (Symbol f, const Symbols& args)
: functor_(f), args_(args) { }
Symbol functor (void) const { return functor_; }
@ -124,10 +125,10 @@ class Ground
bool isAtom (void) const { return args_.empty(); }
private:
friend std::ostream& operator<< (std::ostream&, const Ground&);
Symbol functor_;
Symbols args_;
friend std::ostream& operator<< (std::ostream &os, const Ground& gr);
};
typedef std::vector<Ground> Grounds;
@ -150,11 +151,10 @@ class Substitution
LogVars getDiscardedLogVars (void) const;
private:
std::unordered_map<LogVar, LogVar> subs_;
friend std::ostream& operator<< (
std::ostream &os, const Substitution& theta);
std::ostream&, const Substitution&);
std::unordered_map<LogVar, LogVar> subs_;
};
@ -205,6 +205,5 @@ Substitution::nrReplacements (void) const
return subs_.size();
}
#endif // YAP_PACKAGES_CLPBN_HORUS_LIFTEDUTILS_H_

View File

@ -65,7 +65,7 @@ Literal::toString (
std::ostream&
operator<< (std::ostream &os, const Literal& lit)
operator<< (std::ostream& os, const Literal& lit)
{
os << lit.toString();
return os;
@ -342,7 +342,7 @@ Clause::deleteClauses (Clauses& clauses)
std::ostream&
operator<< (std::ostream &os, const Clause& clause)
operator<< (std::ostream& os, const Clause& clause)
{
for (unsigned i = 0; i < clause.literals_.size(); i++) {
if (i != 0) os << " v " ;
@ -374,7 +374,7 @@ Clause::getLogVarSetExcluding (size_t idx) const
std::ostream&
operator<< (std::ostream &os, const LitLvTypes& lit)
operator<< (std::ostream& os, const LitLvTypes& lit)
{
os << lit.lid_ << "<" ;
for (size_t i = 0; i < lit.lvTypes_.size(); i++) {

View File

@ -54,11 +54,11 @@ class Literal
LogVarSet negCountedLvs = LogVarSet()) const;
private:
friend std::ostream& operator<< (std::ostream&, const Literal&);
LiteralId lid_;
LogVars logVars_;
bool negated_;
friend std::ostream& operator<< (std::ostream &os, const Literal& lit);
};
typedef std::vector<Literal> Literals;
@ -145,14 +145,14 @@ class Clause
private:
LogVarSet getLogVarSetExcluding (size_t idx) const;
friend std::ostream& operator<< (std::ostream&, const Clause&);
Literals literals_;
LogVarSet ipgLvs_;
LogVarSet posCountedLvs_;
LogVarSet negCountedLvs_;
ConstraintTree constr_;
friend std::ostream& operator<< (std::ostream &os, const Clause& clause);
DISALLOW_ASSIGN (Clause);
};
@ -163,22 +163,6 @@ typedef std::vector<Clause*> Clauses;
class LitLvTypes
{
public:
struct CompareLitLvTypes
{
bool operator() (
const LitLvTypes& types1,
const LitLvTypes& types2) const
{
if (types1.lid_ < types2.lid_) {
return true;
}
if (types1.lid_ == types2.lid_) {
return types1.lvTypes_ < types2.lvTypes_;
}
return false;
}
};
LitLvTypes (LiteralId lid, const LogVarTypes& lvTypes) :
lid_(lid), lvTypes_(lvTypes) { }
@ -190,13 +174,29 @@ class LitLvTypes
std::fill (lvTypes_.begin(), lvTypes_.end(), LogVarType::FULL_LV); }
private:
friend std::ostream& operator<< (std::ostream&, const LitLvTypes&);
LiteralId lid_;
LogVarTypes lvTypes_;
friend std::ostream& operator<< (std::ostream &os, const LitLvTypes& lit);
};
typedef TinySet<LitLvTypes,LitLvTypes::CompareLitLvTypes> LitLvTypesSet;
struct CmpLitLvTypes
{
bool operator() (const LitLvTypes& types1, const LitLvTypes& types2) const
{
if (types1.lid() < types2.lid()) {
return true;
}
if (types1.lid() == types2.lid()){
return types1.logVarTypes() < types2.logVarTypes();
}
return false;
}
};
typedef TinySet<LitLvTypes, CmpLitLvTypes> LitLvTypesSet;

View File

@ -97,7 +97,8 @@ ProbFormula::rename (LogVar oldName, LogVar newName)
bool operator== (const ProbFormula& f1, const ProbFormula& f2)
bool
operator== (const ProbFormula& f1, const ProbFormula& f2)
{
return f1.group_ == f2.group_ &&
f1.logVars_ == f2.logVars_;
@ -105,7 +106,8 @@ bool operator== (const ProbFormula& f1, const ProbFormula& f2)
std::ostream& operator<< (std::ostream &os, const ProbFormula& f)
std::ostream&
operator<< (std::ostream& os, const ProbFormula& f)
{
os << f.functor_;
if (f.isAtom() == false) {
@ -151,7 +153,8 @@ ObservedFormula::ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple)
std::ostream& operator<< (std::ostream &os, const ObservedFormula& of)
std::ostream&
operator<< (std::ostream& os, const ObservedFormula& of)
{
os << of.functor_ << "/" << of.arity_;
os << "|" << of.constr_.tupleSet();

View File

@ -60,13 +60,13 @@ class ProbFormula
static PrvGroup getNewGroup (void);
private:
friend bool operator== (
const ProbFormula& f1, const ProbFormula& f2);
friend std::ostream& operator<< (
std::ostream &os, const ProbFormula& f);
std::ostream&, const ProbFormula&);
private:
Symbol functor_;
LogVars logVars_;
unsigned range_;
@ -100,13 +100,13 @@ class ObservedFormula
void addTuple (const Tuple& tuple) { constr_.addTuple (tuple); }
private:
friend std::ostream& operator<< (
std::ostream&, const ObservedFormula&);
Symbol functor_;
unsigned arity_;
unsigned evidence_;
ConstraintTree constr_;
friend std::ostream& operator<< (
std::ostream &os, const ObservedFormula& of);
};
typedef std::vector<ObservedFormula> ObservedFormulas;

View File

@ -10,9 +10,8 @@ template <typename T, typename Compare = std::less<T>>
class TinySet
{
public:
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
typedef typename std::vector<T>::iterator iterator;
typedef typename std::vector<T>::const_iterator const_iterator;
TinySet (const TinySet& s)
: vec_(s.vec_), cmp_(s.cmp_) { }
@ -90,9 +89,6 @@ class TinySet
bool consistent (void) const;
std::vector<T> vec_;
Compare cmp_;
friend bool operator== (const TinySet& s1, const TinySet& s2)
{
return s1.vec_ == s2.vec_;
@ -114,6 +110,8 @@ class TinySet
return out;
}
std::vector<T> vec_;
Compare cmp_;
};