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.cpp

141 lines
2.0 KiB
C++
Raw Normal View History

2012-05-23 14:56:01 +01:00
#include "ProbFormula.h"
2012-05-24 23:38:44 +01:00
PrvGroup ProbFormula::freeGroup_ = 0;
2012-05-23 14:56:01 +01:00
bool
ProbFormula::sameSkeletonAs (const ProbFormula& f) const
{
return functor_ == f.functor() && logVars_.size() == f.arity();
}
bool
ProbFormula::contains (LogVar lv) const
{
return Util::contains (logVars_, lv);
}
bool
ProbFormula::contains (LogVarSet s) const
{
return LogVarSet (logVars_).contains (s);
}
2012-05-24 22:55:20 +01:00
size_t
2012-05-23 14:56:01 +01:00
ProbFormula::indexOf (LogVar X) const
{
return Util::indexOf (logVars_, X);
}
bool
ProbFormula::isAtom (void) const
{
return logVars_.size() == 0;
}
bool
ProbFormula::isCounting (void) const
{
return countedLogVar_.valid();
}
LogVar
ProbFormula::countedLogVar (void) const
{
assert (isCounting());
return countedLogVar_;
}
void
ProbFormula::setCountedLogVar (LogVar lv)
{
countedLogVar_ = lv;
}
void
ProbFormula::clearCountedLogVar (void)
{
countedLogVar_ = LogVar();
}
void
ProbFormula::rename (LogVar oldName, LogVar newName)
{
2012-05-24 22:55:20 +01:00
for (size_t i = 0; i < logVars_.size(); i++) {
2012-05-23 14:56:01 +01:00
if (logVars_[i] == oldName) {
logVars_[i] = newName;
}
}
if (isCounting() && countedLogVar_ == oldName) {
countedLogVar_ = newName;
}
}
bool operator== (const ProbFormula& f1, const ProbFormula& f2)
{
return f1.group_ == f2.group_ &&
f1.logVars_ == f2.logVars_;
}
std::ostream& operator<< (ostream &os, const ProbFormula& f)
{
os << f.functor_;
if (f.isAtom() == false) {
os << "(" ;
2012-05-24 22:55:20 +01:00
for (size_t i = 0; i < f.logVars_.size(); i++) {
2012-05-23 14:56:01 +01:00
if (i != 0) os << ",";
if (f.isCounting() && f.logVars_[i] == f.countedLogVar_) {
os << "#" ;
}
os << f.logVars_[i];
}
os << ")" ;
}
os << "::" << f.range_;
return os;
}
2012-05-24 23:38:44 +01:00
PrvGroup
2012-05-23 14:56:01 +01:00
ProbFormula::getNewGroup (void)
{
freeGroup_ ++;
2012-05-24 23:38:44 +01:00
assert (freeGroup_ != numeric_limits<PrvGroup>::max());
2012-05-23 14:56:01 +01:00
return freeGroup_;
}
ostream& operator<< (ostream &os, const ObservedFormula& of)
{
os << of.functor_ << "/" << of.arity_;
os << "|" << of.constr_.tupleSet();
os << " [evidence=" << of.evidence_ << "]";
return os;
}