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-07 23:53:13 +00:00
|
|
|
namespace horus {
|
|
|
|
|
2012-05-23 14:56:01 +01: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
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Var (const Var*);
|
|
|
|
|
2013-02-08 00:15:41 +00:00
|
|
|
Var (VarId, unsigned, int = constants::NO_EVIDENCE);
|
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
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
bool hasEvidence (void) const;
|
2012-05-23 14:56:01 +01:00
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
operator size_t (void) 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-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);
|
2013-02-06 00:24:02 +00:00
|
|
|
|
|
|
|
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_;
|
2012-05-23 14:56:01 +01:00
|
|
|
};
|
|
|
|
|
2013-02-06 00:24:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
Var::hasEvidence (void) const
|
|
|
|
{
|
2013-02-08 00:15:41 +00:00
|
|
|
return evidence_ != constants::NO_EVIDENCE;
|
2013-02-06 00:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-02-07 23:53:13 +00:00
|
|
|
} // namespace horus
|
|
|
|
|
2013-02-08 00:20:01 +00:00
|
|
|
#endif // YAP_PACKAGES_CLPBN_HORUS_VAR_H_
|
2012-05-23 14:56:01 +01:00
|
|
|
|