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

128 lines
2.8 KiB
C
Raw Normal View History

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
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
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
Symbol functor() const { return functor_; }
2012-05-23 14:56:01 +01:00
unsigned arity() const { return logVars_.size(); }
2012-05-23 14:56:01 +01:00
unsigned range() const { return range_; }
2012-05-23 14:56:01 +01:00
LogVars& logVars() { return logVars_; }
2012-05-23 14:56:01 +01:00
const LogVars& logVars() const { return logVars_; }
2012-05-23 14:56:01 +01:00
LogVarSet logVarSet() const { return LogVarSet (logVars_); }
2012-12-17 18:39:42 +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
bool isAtom() const;
2012-05-23 14:56:01 +01:00
bool isCounting() const;
2012-05-23 14:56:01 +01:00
LogVar countedLogVar() const;
2012-12-17 18:39:42 +00:00
2012-05-23 14:56:01 +01:00
void setCountedLogVar (LogVar);
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
static PrvGroup getNewGroup();
2012-05-23 14:56:01 +01:00
private:
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<< (
std::ostream&, const ProbFormula&);
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
inline bool
operator== (const ProbFormula& f1, const ProbFormula& f2)
{
return f1.group_ == f2.group_ && f1.logVars_ == f2.logVars_;
}
class ObservedFormula {
2012-05-23 14:56:01 +01:00
public:
ObservedFormula (Symbol f, unsigned a, unsigned ev);
2012-05-23 14:56:01 +01:00
ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple);
2012-05-23 14:56:01 +01:00
Symbol functor() const { return functor_; }
2012-05-23 14:56:01 +01:00
unsigned arity() const { return arity_; }
2012-05-23 14:56:01 +01: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; }
ConstraintTree& constr() { return constr_; }
2012-05-23 14:56:01 +01:00
bool isAtom() const { return arity_ == 0; }
2012-05-23 14:56:01 +01:00
void addTuple (const Tuple& tuple) { constr_.addTuple (tuple); }
private:
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
} // 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