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/clpbn/bp/ProbFormula.cpp

124 lines
1.8 KiB
C++
Raw Normal View History

2012-03-22 11:33:24 +00:00
#include "ProbFormula.h"
int ProbFormula::freeGroup_ = 0;
bool
ProbFormula::sameSkeletonAs (const ProbFormula& f) const
{
return functor_ == f.functor() && logVars_.size() == f.arity();
}
bool
ProbFormula::contains (LogVar lv) const
{
2012-03-31 23:27:37 +01:00
return Util::contains (logVars_, lv);
2012-03-22 11:33:24 +00:00
}
bool
ProbFormula::contains (LogVarSet s) const
{
return LogVarSet (logVars_).contains (s);
}
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::rename (LogVar oldName, LogVar newName)
{
for (unsigned i = 0; i < logVars_.size(); i++) {
if (logVars_[i] == oldName) {
logVars_[i] = newName;
}
}
if (isCounting() && countedLogVar_ == oldName) {
countedLogVar_ = newName;
}
}
2012-03-31 23:27:37 +01:00
bool operator== (const ProbFormula& f1, const ProbFormula& f2)
2012-03-22 11:33:24 +00:00
{
2012-03-31 23:27:37 +01:00
return f1.group_ == f2.group_;
//return functor_ == f.functor_ && logVars_ == f.logVars_ ;
2012-03-22 11:33:24 +00:00
}
2012-03-31 23:27:37 +01:00
std::ostream& operator<< (ostream &os, const ProbFormula& f)
2012-03-22 11:33:24 +00:00
{
os << f.functor_;
if (f.isAtom() == false) {
os << "(" ;
for (unsigned i = 0; i < f.logVars_.size(); i++) {
if (i != 0) os << ",";
if (f.isCounting() && f.logVars_[i] == f.countedLogVar_) {
os << "#" ;
}
os << f.logVars_[i];
}
os << ")" ;
}
os << "::" << f.range_;
return os;
}
unsigned
ProbFormula::getNewGroup (void)
{
freeGroup_ ++;
return freeGroup_;
}
2012-03-31 23:27:37 +01:00
ostream& operator<< (ostream &os, const ObservedFormula& of)
{
os << of.functor_ << "/" << of.arity_;
os << "|" << of.constr_.tupleSet();
os << " [evidence=" << of.evidence_ << "]";
return os;
}