when expanding a counting formula, check if the expanded log vars are still counting log vars

This commit is contained in:
Tiago Gomes 2012-04-28 01:01:23 +01:00
parent 52f4aa0340
commit 1173b4c25b
4 changed files with 18 additions and 2 deletions

View File

@ -37,7 +37,7 @@ class Symbol
class LogVar
{
public:
LogVar (void) : id_(numeric_limits<unsigned>::max()) { }
LogVar (void) : id_(Util::maxUnsigned()) { }
LogVar (unsigned id) : id_(id) { }
@ -52,7 +52,7 @@ class LogVar
bool valid (void) const
{
return id_ != numeric_limits<unsigned>::max();
return id_ != Util::maxUnsigned();
}
friend ostream& operator<< (ostream &os, const LogVar& X);

View File

@ -285,6 +285,12 @@ Parfactor::expand (LogVar X, LogVar X_new1, LogVar X_new2)
args_.insert (args_.begin() + fIdx + 1, args_[fIdx]);
args_[fIdx].rename (X, X_new1);
args_[fIdx + 1].rename (X, X_new2);
if (H1 == 2) {
args_[fIdx].clearCountedLogVar();
}
if (H2 == 2) {
args_[fIdx + 1].clearCountedLogVar();
}
ranges_.insert (ranges_.begin() + fIdx + 1, H2);
ranges_[fIdx] = H1;
}

View File

@ -76,6 +76,14 @@ ProbFormula::setCountedLogVar (LogVar lv)
void
ProbFormula::clearCountedLogVar (void)
{
countedLogVar_ = LogVar();
}
void
ProbFormula::rename (LogVar oldName, LogVar newName)
{

View File

@ -50,6 +50,8 @@ class ProbFormula
LogVar countedLogVar (void) const;
void setCountedLogVar (LogVar);
void clearCountedLogVar (void);
void rename (LogVar, LogVar);