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

76 lines
1.1 KiB
C++
Raw Normal View History

2012-05-23 14:56:01 +01:00
#include <sstream>
#include "Var.h"
unordered_map<VarId, VarInfo> Var::varsInfo_;
Var::Var (const Var* v)
{
varId_ = v->varId();
range_ = v->range();
evidence_ = v->getEvidence();
2012-12-27 12:54:58 +00:00
index_ = Util::maxUnsigned();
2012-05-23 14:56:01 +01:00
}
Var::Var (VarId varId, unsigned range, int evidence)
{
assert (range != 0);
assert (evidence < (int) range);
varId_ = varId;
range_ = range;
evidence_ = evidence;
2012-12-27 12:54:58 +00:00
index_ = Util::maxUnsigned();
2012-05-23 14:56:01 +01:00
}
bool
Var::isValidState (int stateIndex)
{
return stateIndex >= 0 && stateIndex < (int) range_;
}
void
2012-12-28 01:35:59 +00:00
Var::setEvidence (int evidence)
2012-12-20 23:19:10 +00:00
{
2012-12-28 01:35:59 +00:00
assert (evidence < (int) range_);
evidence_ = evidence;
2012-05-23 14:56:01 +01:00
}
string
Var::label (void) const
{
if (Var::varsHaveInfo()) {
return Var::getVarInfo (varId_).label;
}
stringstream ss;
ss << "x" << varId_;
return ss.str();
}
States
Var::states (void) const
{
if (Var::varsHaveInfo()) {
return Var::getVarInfo (varId_).states;
}
States states;
for (unsigned i = 0; i < range_; i++) {
stringstream ss;
ss << i ;
states.push_back (ss.str());
}
return states;
}