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

106 lines
1.7 KiB
C
Raw Permalink 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
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
virtual ~Var() { };
2012-05-23 14:56:01 +01:00
VarId varId() const { return varId_; }
2012-05-23 14:56:01 +01:00
unsigned range() const { return range_; }
2012-05-23 14:56:01 +01:00
int getEvidence() const { return evidence_; }
2012-05-23 14:56:01 +01: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
bool hasEvidence() const;
2012-05-23 14:56:01 +01:00
operator size_t() 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);
std::string label() const;
2012-05-23 14:56:01 +01: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);
static bool varsHaveInfo();
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
};
inline bool
Var::hasEvidence() const
{
return evidence_ != Constants::unobserved;
}
inline
Var::operator size_t() 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