2013-02-07 17:50:02 +00:00
|
|
|
#ifndef YAP_PACKAGES_CLPBN_HORUS_PROBFORMULA_H_
|
|
|
|
#define YAP_PACKAGES_CLPBN_HORUS_PROBFORMULA_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-07 20:09:10 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <ostream>
|
2012-05-23 14:56:01 +01:00
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#include "ConstraintTree.h"
|
|
|
|
#include "LiftedUtils.h"
|
|
|
|
#include "Horus.h"
|
|
|
|
|
2013-02-07 23:53:13 +00:00
|
|
|
|
2013-02-08 21:12:46 +00:00
|
|
|
namespace Horus {
|
2013-02-07 23:53:13 +00:00
|
|
|
|
2012-05-24 23:38:44 +01:00
|
|
|
typedef unsigned long PrvGroup;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-13 14:26:47 +00:00
|
|
|
class ProbFormula {
|
2012-05-23 14:56:01 +01:00
|
|
|
public:
|
2012-12-20 23:19:10 +00:00
|
|
|
ProbFormula (Symbol f, const LogVars& lvs, unsigned range)
|
2012-05-23 14:56:01 +01:00
|
|
|
: functor_(f), logVars_(lvs), range_(range),
|
2012-12-27 12:54:58 +00:00
|
|
|
countedLogVar_(), group_(std::numeric_limits<PrvGroup>::max()) { }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-12-20 23:19:10 +00:00
|
|
|
ProbFormula (Symbol f, unsigned r)
|
2012-12-27 12:54:58 +00:00
|
|
|
: functor_(f), range_(r),
|
|
|
|
group_(std::numeric_limits<PrvGroup>::max()) { }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
Symbol functor() const { return functor_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
unsigned arity() const { return logVars_.size(); }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
unsigned range() const { return range_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
LogVars& logVars() { return logVars_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
const LogVars& logVars() const { return logVars_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
LogVarSet logVarSet() const { return LogVarSet (logVars_); }
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
PrvGroup group() const { return group_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-05-24 23:38:44 +01:00
|
|
|
void setGroup (PrvGroup g) { group_ = g; }
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
bool sameSkeletonAs (const ProbFormula&) const;
|
|
|
|
|
|
|
|
bool contains (LogVar) const;
|
|
|
|
|
|
|
|
bool contains (LogVarSet) const;
|
|
|
|
|
2012-05-24 22:55:20 +01:00
|
|
|
size_t indexOf (LogVar) const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
bool isAtom() const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
bool isCounting() const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
LogVar countedLogVar() const;
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
void setCountedLogVar (LogVar);
|
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
void clearCountedLogVar();
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
void rename (LogVar, LogVar);
|
2012-12-17 18:39:42 +00:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
static PrvGroup getNewGroup();
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-07 22:37:45 +00:00
|
|
|
private:
|
2013-03-04 17:58:32 +00:00
|
|
|
|
2013-02-07 13:37:15 +00:00
|
|
|
friend bool operator== (
|
|
|
|
const ProbFormula& f1, const ProbFormula& f2);
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-07 13:37:15 +00:00
|
|
|
friend std::ostream& operator<< (
|
2013-02-07 22:37:45 +00:00
|
|
|
std::ostream&, const ProbFormula&);
|
2013-02-06 00:24:02 +00:00
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
Symbol functor_;
|
|
|
|
LogVars logVars_;
|
|
|
|
unsigned range_;
|
|
|
|
LogVar countedLogVar_;
|
2012-05-24 23:38:44 +01:00
|
|
|
PrvGroup group_;
|
|
|
|
static PrvGroup freeGroup_;
|
2012-05-23 14:56:01 +01:00
|
|
|
};
|
|
|
|
|
2013-02-07 13:37:15 +00:00
|
|
|
typedef std::vector<ProbFormula> ProbFormulas;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
|
2013-03-04 17:58:32 +00:00
|
|
|
inline bool
|
|
|
|
operator== (const ProbFormula& f1, const ProbFormula& f2)
|
|
|
|
{
|
|
|
|
return f1.group_ == f2.group_ && f1.logVars_ == f2.logVars_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-13 14:26:47 +00:00
|
|
|
class ObservedFormula {
|
2012-05-23 14:56:01 +01:00
|
|
|
public:
|
2013-02-06 00:24:02 +00:00
|
|
|
ObservedFormula (Symbol f, unsigned a, unsigned ev);
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple);
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
Symbol functor() const { return functor_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
unsigned arity() const { return arity_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
unsigned evidence() const { return evidence_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-06-14 11:57:00 +01:00
|
|
|
void setEvidence (unsigned ev) { evidence_ = ev; }
|
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
ConstraintTree& constr() { return constr_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
bool isAtom() const { return arity_ == 0; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
void addTuple (const Tuple& tuple) { constr_.addTuple (tuple); }
|
|
|
|
|
|
|
|
private:
|
2013-02-07 22:37:45 +00:00
|
|
|
friend std::ostream& operator<< (
|
|
|
|
std::ostream&, const ObservedFormula&);
|
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
Symbol functor_;
|
|
|
|
unsigned arity_;
|
|
|
|
unsigned evidence_;
|
|
|
|
ConstraintTree constr_;
|
|
|
|
};
|
|
|
|
|
2013-02-07 13:37:15 +00:00
|
|
|
typedef std::vector<ObservedFormula> ObservedFormulas;
|
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_PROBFORMULA_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|