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
|
|
|
|
2013-02-08 21:12:46 +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
|
|
|
|
{
|
2013-02-08 21:01:53 +00:00
|
|
|
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
|
|
|
|
{
|
2013-02-08 21:01:53 +00:00
|
|
|
return Util::indexOf (logVars_, X);
|
2012-05-23 14:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProbFormula::isAtom (void) const
|
|
|
|
{
|
2012-12-27 12:54:58 +00:00
|
|
|
return logVars_.empty();
|
2012-05-23 14:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProbFormula::isCounting (void) const
|
|
|
|
{
|
|
|
|
return countedLogVar_.valid();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LogVar
|
|
|
|
ProbFormula::countedLogVar (void) const
|
|
|
|
{
|
|
|
|
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 (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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-20 23:19:10 +00:00
|
|
|
|
2013-02-07 22:37:45 +00:00
|
|
|
bool
|
|
|
|
operator== (const ProbFormula& f1, const ProbFormula& f2)
|
2012-12-20 23:19:10 +00:00
|
|
|
{
|
|
|
|
return f1.group_ == f2.group_ &&
|
2012-05-23 14:56:01 +01:00
|
|
|
f1.logVars_ == f2.logVars_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-07 22:37:45 +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
|
2012-05-23 14:56:01 +01:00
|
|
|
ProbFormula::getNewGroup (void)
|
|
|
|
{
|
|
|
|
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_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-07 22:37:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:12:46 +00:00
|
|
|
} // namespace Horus
|
2013-02-07 23:53:13 +00:00
|
|
|
|