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.h

114 lines
1.9 KiB
C
Raw Normal View History

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"
namespace Horus {
2013-02-07 23:53:13 +00:00
struct VarInfo {
2013-02-07 13:37:15 +00:00
VarInfo (std::string l, const States& sts)
2012-12-27 12:54:58 +00:00
: label(l), states(sts) { }
2013-02-07 13:37:15 +00:00
std::string label;
2012-05-23 14:56:01 +01:00
States states;
};
class Var {
2012-05-23 14:56:01 +01:00
public:
Var (const Var*);
Var (VarId, unsigned, int = Constants::unobserved);
2012-05-23 14:56:01 +01:00
virtual ~Var (void) { };
2012-05-24 22:55:20 +01:00
VarId varId (void) const { return varId_; }
2012-05-23 14:56:01 +01:00
unsigned range (void) const { return range_; }
int getEvidence (void) const { return evidence_; }
2012-05-24 22:55:20 +01:00
size_t getIndex (void) 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
bool hasEvidence (void) const;
2012-05-23 14:56:01 +01:00
operator size_t (void) const;
2012-05-28 16:59:41 +01:00
bool operator== (const Var& var) const;
2012-05-23 14:56:01 +01:00
bool operator!= (const Var& var) const;
2012-05-23 14:56:01 +01:00
bool isValidState (int);
void setEvidence (int);
2013-02-07 13:37:15 +00:00
std::string label (void) const;
2012-05-23 14:56:01 +01:00
States states (void) const;
static void addVarInfo (
2013-02-07 13:37:15 +00:00
VarId vid, std::string label, const States& states);
static VarInfo getVarInfo (VarId vid);
static bool varsHaveInfo (void);
static void clearVarsInfo (void);
2012-05-23 14:56:01 +01:00
private:
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
};
inline bool
Var::hasEvidence (void) const
{
return evidence_ != Constants::unobserved;
}
inline
Var::operator size_t (void) const
{
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);
}
} // 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