2012-05-28 16:59:41 +01:00
|
|
|
#ifndef HORUS_VAR_H
|
|
|
|
#define HORUS_VAR_H
|
2012-05-23 14:56:01 +01:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "Util.h"
|
|
|
|
#include "Horus.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
struct VarInfo
|
|
|
|
{
|
|
|
|
VarInfo (string l, const States& sts) : label(l), states(sts) { }
|
|
|
|
string label;
|
|
|
|
States states;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Var
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Var (const Var*);
|
|
|
|
|
|
|
|
Var (VarId, unsigned, int = Constants::NO_EVIDENCE);
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return evidence_ != Constants::NO_EVIDENCE;
|
|
|
|
}
|
|
|
|
|
2012-05-28 16:59:41 +01:00
|
|
|
operator size_t (void) const { return index_; }
|
|
|
|
|
2012-05-23 14:56:01 +01:00
|
|
|
bool operator== (const Var& var) const
|
|
|
|
{
|
|
|
|
assert (!(varId_ == var.varId() && range_ != var.range()));
|
|
|
|
return varId_ == var.varId();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!= (const Var& var) const
|
|
|
|
{
|
|
|
|
assert (!(varId_ == var.varId() && range_ != var.range()));
|
|
|
|
return varId_ != var.varId();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isValidState (int);
|
|
|
|
|
|
|
|
bool isValidState (const string&);
|
|
|
|
|
|
|
|
void setEvidence (int);
|
|
|
|
|
|
|
|
void setEvidence (const string&);
|
|
|
|
|
|
|
|
string label (void) const;
|
|
|
|
|
|
|
|
States states (void) const;
|
|
|
|
|
|
|
|
static void addVarInfo (
|
|
|
|
VarId vid, string label, const States& states)
|
|
|
|
{
|
|
|
|
assert (Util::contains (varsInfo_, vid) == false);
|
|
|
|
varsInfo_.insert (make_pair (vid, VarInfo (label, states)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static VarInfo getVarInfo (VarId vid)
|
|
|
|
{
|
|
|
|
assert (Util::contains (varsInfo_, vid));
|
|
|
|
return varsInfo_.find (vid)->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool varsHaveInfo (void)
|
|
|
|
{
|
|
|
|
return varsInfo_.size() != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clearVarsInfo (void)
|
|
|
|
{
|
|
|
|
varsInfo_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
static unordered_map<VarId, VarInfo> varsInfo_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-05-28 16:59:41 +01:00
|
|
|
#endif // HORUS_VAR_H
|
2012-05-23 14:56:01 +01:00
|
|
|
|