Implemented [equals] using binary predicate and STL's equal
parent
b9ceca7dc6
commit
e1f14b34c3
|
@ -33,7 +33,9 @@ namespace gtsam {
|
|||
template<class Conditional>
|
||||
bool BayesTree<Conditional>::equals(const BayesTree<Conditional>& other,
|
||||
double tol) const {
|
||||
return false;
|
||||
return size()==other.size() &&
|
||||
equal(nodeMap_.begin(),nodeMap_.end(),other.nodeMap_.begin()) &&
|
||||
equal(nodes_.begin(),nodes_.end(),other.nodes_.begin(),equals_star<Node>);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace gtsam {
|
|||
private:
|
||||
typedef boost::shared_ptr<Conditional> cond_ptr;
|
||||
std::list<std::string> keys_; /** frontal keys */
|
||||
std::list<cond_ptr> nodes_; /** conditionals */
|
||||
std::list<cond_ptr> conditionals_; /** conditionals */
|
||||
std::list<std::string> separator_; /** separator keys */
|
||||
public:
|
||||
|
||||
|
@ -50,13 +50,14 @@ namespace gtsam {
|
|||
|
||||
/** check equality. TODO: only keys */
|
||||
bool equals(const Front<Conditional>& other, double tol = 1e-9) const {
|
||||
return (keys_ == other.keys_);
|
||||
return (keys_ == other.keys_) &&
|
||||
equal(conditionals_.begin(),conditionals_.end(),other.conditionals_.begin(),equals_star<Conditional>);
|
||||
}
|
||||
|
||||
/** add a frontal node */
|
||||
void add(std::string key, cond_ptr conditional) {
|
||||
keys_.push_front(key);
|
||||
nodes_.push_front(conditional);
|
||||
conditionals_.push_front(conditional);
|
||||
}
|
||||
|
||||
/** return size of the clique */
|
||||
|
@ -122,6 +123,9 @@ namespace gtsam {
|
|||
/** insert a new conditional */
|
||||
void insert(std::string key, conditional_ptr conditional);
|
||||
|
||||
/** number of cliques */
|
||||
inline size_t size() const { return nodes_.size();}
|
||||
|
||||
/** return root clique */
|
||||
const Front<Conditional>& root() const {return *(nodes_[0]);}
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ TEST( BayesTree, Front )
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( BayesTree, insert )
|
||||
TEST( BayesTree, constructor )
|
||||
{
|
||||
// Insert
|
||||
// Create using insert
|
||||
BayesTree<SymbolicConditional> bayesTree;
|
||||
bayesTree.insert("B",B);
|
||||
bayesTree.insert("L",L);
|
||||
|
@ -44,33 +44,25 @@ TEST( BayesTree, insert )
|
|||
bayesTree.insert("S",S);
|
||||
bayesTree.insert("T",T);
|
||||
bayesTree.insert("X",X);
|
||||
//bayesTree.print("bayesTree");
|
||||
|
||||
//LONGS_EQUAL(1,bayesTree.size());
|
||||
// Check Size
|
||||
LONGS_EQUAL(4,bayesTree.size());
|
||||
|
||||
// Check root
|
||||
Front<SymbolicConditional> expected_root("B",B);
|
||||
//CHECK(assert_equal(expected_root,bayesTree.root()));
|
||||
}
|
||||
expected_root.add("L",L);
|
||||
expected_root.add("E",E);
|
||||
Front<SymbolicConditional> actual_root = bayesTree.root();
|
||||
CHECK(assert_equal(expected_root,actual_root));
|
||||
|
||||
/* ************************************************************************* */
|
||||
TEST( BayesTree, constructor )
|
||||
{
|
||||
// Create Symbolic Bayes Chain in which we want to discover cliques
|
||||
// Create from symbolic Bayes chain in which we want to discover cliques
|
||||
map<string, SymbolicConditional::shared_ptr> nodes;
|
||||
insert(nodes)("B",B)("L",L)("E",E)("S",S)("T",T)("X",X);
|
||||
SymbolicBayesChain ASIA(nodes);
|
||||
BayesTree<SymbolicConditional> bayesTree2(ASIA);
|
||||
|
||||
// Create Bayes Tree from Symbolic Bayes Chain
|
||||
BayesTree<SymbolicConditional> bayesTree(ASIA);
|
||||
bayesTree.insert("B",B);
|
||||
//bayesTree.print("bayesTree");
|
||||
|
||||
//LONGS_EQUAL(1,bayesTree.size());
|
||||
|
||||
// Check root
|
||||
Front<SymbolicConditional> expected_root("B",B);
|
||||
//CHECK(assert_equal(expected_root,bayesTree.root()));
|
||||
// Check whether the same
|
||||
//CHECK(assert_equal(bayesTree,bayesTree2));
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
|
|
Loading…
Reference in New Issue