2013-02-07 17:50:02 +00:00
|
|
|
#ifndef YAP_PACKAGES_CLPBN_HORUS_VAR_H_
|
|
|
|
#define YAP_PACKAGES_CLPBN_HORUS_VAR_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
2013-02-07 20:09:10 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <string>
|
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
#include "Util.h"
|
|
|
|
#include "Horus.h"
|
|
|
|
|
|
|
|
|
2013-02-08 21:12:46 +00:00
|
|
|
namespace Horus {
|
2013-02-07 23:53:13 +00:00
|
|
|
|
2013-02-13 14:26:47 +00:00
|
|
|
class Var {
|
2012-05-23 14:56:01 +01:00
|
|
|
public:
|
|
|
|
Var (const Var*);
|
|
|
|
|
2013-03-09 16:18:13 +00:00
|
|
|
Var (VarId, unsigned range, int evidence = Constants::unobserved);
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
virtual ~Var() { };
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
VarId varId() const { return varId_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
unsigned range() const { return range_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
int getEvidence() const { return evidence_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
size_t getIndex() const { return index_; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2012-05-24 22:55:20 +01:00
|
|
|
void setIndex (size_t idx) { index_ = idx; }
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
bool hasEvidence() const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
operator size_t() const;
|
2012-05-28 16:59:41 +01:00
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
bool operator== (const Var& var) const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
bool operator!= (const Var& var) const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
bool isValidState (int);
|
|
|
|
|
|
|
|
void setEvidence (int);
|
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
std::string label() const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
States states() const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
static void addVarInfo (
|
2013-02-07 13:37:15 +00:00
|
|
|
VarId vid, std::string label, const States& states);
|
2013-02-06 00:24:02 +00:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
static bool varsHaveInfo();
|
2013-02-06 00:24:02 +00:00
|
|
|
|
2013-02-28 19:45:37 +00:00
|
|
|
static void clearVarsInfo();
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
private:
|
2013-03-09 16:18:13 +00:00
|
|
|
typedef std::pair<std::string, States> VarInfo;
|
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
VarId varId_;
|
|
|
|
unsigned range_;
|
|
|
|
int evidence_;
|
2012-05-24 22:55:20 +01:00
|
|
|
size_t index_;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-07 13:37:15 +00:00
|
|
|
static std::unordered_map<VarId, VarInfo> varsInfo_;
|
2013-02-13 14:42:24 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Var);
|
2012-05-23 14:56:01 +01:00
|
|
|
};
|
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
inline bool
|
2013-02-28 19:45:37 +00:00
|
|
|
Var::hasEvidence() const
|
2013-02-06 00:24:02 +00:00
|
|
|
{
|
2013-02-13 18:54:15 +00:00
|
|
|
return evidence_ != Constants::unobserved;
|
2013-02-06 00:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
2013-02-28 19:45:37 +00:00
|
|
|
Var::operator size_t() const
|
2013-02-06 00:24:02 +00:00
|
|
|
{
|
|
|
|
return index_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
Var::operator== (const Var& var) const
|
|
|
|
{
|
|
|
|
assert (!(varId_ == var.varId() && range_ != var.range()));
|
|
|
|
return varId_ == var.varId();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
Var::operator!= (const Var& var) const
|
|
|
|
{
|
|
|
|
return !(*this == var);
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:12:46 +00:00
|
|
|
} // namespace Horus
|
2013-02-07 23:53:13 +00:00
|
|
|
|
2013-02-08 00:20:01 +00:00
|
|
|
#endif // YAP_PACKAGES_CLPBN_HORUS_VAR_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|