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

161 lines
2.3 KiB
C++
Raw Normal View History

2013-02-07 20:09:10 +00:00
#include <cassert>
#include <iostream>
2012-05-23 14:56:01 +01:00
#include "ProbFormula.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
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);
2012-05-23 14:56:01 +01:00
}
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);
2012-05-23 14:56:01 +01:00
}
bool
ProbFormula::isAtom() const
2012-05-23 14:56:01 +01:00
{
2012-12-27 12:54:58 +00:00
return logVars_.empty();
2012-05-23 14:56:01 +01:00
}
bool
ProbFormula::isCounting() const
2012-05-23 14:56:01 +01:00
{
return countedLogVar_.valid();
}
LogVar
ProbFormula::countedLogVar() const
2012-05-23 14:56:01 +01:00
{
assert (isCounting());
return countedLogVar_;
}
2012-12-20 23:19:10 +00:00
2012-05-23 14:56:01 +01:00
void
ProbFormula::setCountedLogVar (LogVar lv)
{
countedLogVar_ = lv;
}
void
ProbFormula::clearCountedLogVar()
2012-05-23 14:56:01 +01:00
{
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;
}
}
2012-12-20 23:19:10 +00:00
std::ostream&
operator<< (std::ostream& os, const ProbFormula& f)
2012-05-23 14:56:01 +01:00
{
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
ProbFormula::getNewGroup()
2012-05-23 14:56:01 +01:00
{
freeGroup_ ++;
2012-12-27 12:54:58 +00:00
assert (freeGroup_ != std::numeric_limits<PrvGroup>::max());
2012-05-23 14:56:01 +01:00
return freeGroup_;
}
ObservedFormula::ObservedFormula (Symbol f, unsigned a, unsigned ev)
: functor_(f), arity_(a), evidence_(ev), constr_(a)
{
}
ObservedFormula::ObservedFormula (Symbol f, unsigned ev, const Tuple& tuple)
: functor_(f), arity_(tuple.size()), evidence_(ev), constr_(arity_)
{
constr_.addTuple (tuple);
}
std::ostream&
operator<< (std::ostream& os, const ObservedFormula& of)
2012-05-23 14:56:01 +01:00
{
os << of.functor_ << "/" << of.arity_;
os << "|" << of.constr_.tupleSet();
os << " [evidence=" << of.evidence_ << "]";
return os;
}
} // namespace Horus
2013-02-07 23:53:13 +00:00