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

113 lines
2.7 KiB
C
Raw Normal View History

2012-05-23 14:56:01 +01:00
#ifndef HORUS_PROBFORMULA_H
#define HORUS_PROBFORMULA_H
#include <limits>
#include "ConstraintTree.h"
#include "LiftedUtils.h"
#include "Horus.h"
2012-05-24 23:38:44 +01:00
typedef unsigned long PrvGroup;
2012-05-23 14:56:01 +01:00
class ProbFormula
{
public:
ProbFormula (Symbol f, const LogVars& lvs, unsigned range)
: functor_(f), logVars_(lvs), range_(range),
2012-05-24 23:38:44 +01:00
countedLogVar_(), group_(numeric_limits<PrvGroup>::max()) { }
2012-05-23 14:56:01 +01:00
ProbFormula (Symbol f, unsigned r)
2012-05-24 23:38:44 +01:00
: functor_(f), range_(r), group_(numeric_limits<PrvGroup>::max()) { }
2012-05-23 14:56:01 +01:00
Symbol functor (void) const { return functor_; }
unsigned arity (void) const { return logVars_.size(); }
unsigned range (void) const { return range_; }
LogVars& logVars (void) { return logVars_; }
const LogVars& logVars (void) const { return logVars_; }
LogVarSet logVarSet (void) const { return LogVarSet (logVars_); }
2012-05-24 23:38:44 +01:00
PrvGroup group (void) 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-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 (void) const;
bool isCounting (void) const;
LogVar countedLogVar (void) const;
void setCountedLogVar (LogVar);
void clearCountedLogVar (void);
void rename (LogVar, LogVar);
2012-05-24 23:38:44 +01:00
static PrvGroup getNewGroup (void);
2012-05-23 14:56:01 +01:00
friend std::ostream& operator<< (ostream &os, const ProbFormula& f);
friend bool operator== (const ProbFormula& f1, const ProbFormula& f2);
private:
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
};
typedef vector<ProbFormula> ProbFormulas;
class ObservedFormula
{
public:
ObservedFormula (Symbol f, unsigned a, unsigned ev)
: functor_(f), arity_(a), evidence_(ev), constr_(a) { }
ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple)
: functor_(f), arity_(tuple.size()), evidence_(ev), constr_(arity_)
{
constr_.addTuple (tuple);
}
Symbol functor (void) const { return functor_; }
unsigned arity (void) const { return arity_; }
unsigned evidence (void) const { return evidence_; }
ConstraintTree& constr (void) { return constr_; }
bool isAtom (void) const { return arity_ == 0; }
void addTuple (const Tuple& tuple) { constr_.addTuple (tuple); }
friend ostream& operator<< (ostream &os, const ObservedFormula& of);
private:
Symbol functor_;
unsigned arity_;
unsigned evidence_;
ConstraintTree constr_;
};
typedef vector<ObservedFormula> ObservedFormulas;
#endif // HORUS_PROBFORMULA_H