diff --git a/gtsam/symbolic/tests/testConditional.cpp0 b/gtsam/symbolic/tests/testConditional.cpp similarity index 100% rename from gtsam/symbolic/tests/testConditional.cpp0 rename to gtsam/symbolic/tests/testConditional.cpp diff --git a/gtsam/symbolic/tests/testFactorGraph.cpp0 b/gtsam/symbolic/tests/testFactorGraph.cpp0 deleted file mode 100644 index 43402d2cb..000000000 --- a/gtsam/symbolic/tests/testFactorGraph.cpp0 +++ /dev/null @@ -1,65 +0,0 @@ -/* ---------------------------------------------------------------------------- - - * GTSAM Copyright 2010, Georgia Tech Research Corporation, - * Atlanta, Georgia 30332-0415 - * All Rights Reserved - * Authors: Frank Dellaert, et al. (see THANKS for the full author list) - - * See LICENSE for the license information - - * -------------------------------------------------------------------------- */ - -/** - * @file testFactorgraph.cpp - * @brief Unit tests for IndexFactor Graphs - * @author Christian Potthast - **/ - -/*STL/C++*/ -#include -#include -#include -#include -#include // for operator += -#include -using namespace boost::assign; - -#include - -#include -#include - -using namespace std; -using namespace gtsam; - -/* ************************************************************************* */ -TEST(FactorGraph, eliminateFrontals) { - - SymbolicFactorGraph sfgOrig; - sfgOrig.push_factor(0,1); - sfgOrig.push_factor(0,2); - sfgOrig.push_factor(1,3); - sfgOrig.push_factor(1,4); - sfgOrig.push_factor(2,3); - sfgOrig.push_factor(4,5); - - IndexConditional::shared_ptr actualCond; - SymbolicFactorGraph actualSfg; - boost::tie(actualCond, actualSfg) = sfgOrig.eliminateFrontals(2); - - vector condIndices; - condIndices += 0,1,2,3,4; - IndexConditional expectedCond(condIndices, 2); - - SymbolicFactorGraph expectedSfg; - expectedSfg.push_factor(2,3); - expectedSfg.push_factor(4,5); - expectedSfg.push_factor(2,3,4); - - EXPECT(assert_equal(expectedSfg, actualSfg)); - EXPECT(assert_equal(expectedCond, *actualCond)); -} - -/* ************************************************************************* */ -int main() { TestResult tr; return TestRegistry::runAllTests(tr); } -/* ************************************************************************* */ diff --git a/gtsam/symbolic/tests/testSymbolicEliminationTree.cpp b/gtsam/symbolic/tests/testSymbolicEliminationTree.cpp index bc3c9a902..a34ea09d2 100644 --- a/gtsam/symbolic/tests/testSymbolicEliminationTree.cpp +++ b/gtsam/symbolic/tests/testSymbolicEliminationTree.cpp @@ -71,24 +71,21 @@ public: namespace { /* ************************************************************************* */ - // Conditionals for ASIA example from the tutorial with A and D evidence + // Keys for ASIA example from the tutorial with A and D evidence const Key _X_=X(0), _T_=T(0), _S_=S(0), _E_=E(0), _L_=L(0), _B_=B(0); - // Bayes Tree for Asia example - SymbolicFactorGraphUnordered createAsiaGraph() { - SymbolicFactorGraphUnordered asiaGraph; - asiaGraph.push_factor(_T_); - asiaGraph.push_factor(_S_); - asiaGraph.push_factor(_T_, _E_, _L_); - asiaGraph.push_factor(_L_, _S_); - asiaGraph.push_factor(_S_, _B_); - asiaGraph.push_factor(_E_, _B_); - asiaGraph.push_factor(_E_, _X_); - return asiaGraph; - } + // Factor graph for Asia example + const SymbolicFactorGraphUnordered asiaGraph = list_of + (boost::make_shared(_T_)) + (boost::make_shared(_S_)) + (boost::make_shared(_T_, _E_, _L_)) + (boost::make_shared(_L_, _S_)) + (boost::make_shared(_S_, _B_)) + (boost::make_shared(_E_, _B_)) + (boost::make_shared(_E_, _X_)); /* ************************************************************************* */ - OrderingUnordered asiaOrdering = list_of(_X_)(_T_)(_S_)(_E_)(_L_)(_B_); + const OrderingUnordered asiaOrdering = list_of(_X_)(_T_)(_S_)(_E_)(_L_)(_B_); } diff --git a/gtsam/symbolic/tests/testSymbolicFactor.cpp b/gtsam/symbolic/tests/testSymbolicFactor.cpp new file mode 100644 index 000000000..707faa57c --- /dev/null +++ b/gtsam/symbolic/tests/testSymbolicFactor.cpp @@ -0,0 +1,78 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file testSymbolicFactor.cpp + * @brief Unit tests for a symbolic IndexFactor + * @author Frank Dellaert + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace std; +using namespace gtsam; +using namespace boost::assign; + +/* ************************************************************************* */ +#ifdef TRACK_ELIMINATE +TEST(SymbolicFactor, eliminate) { + vector keys; keys += 2, 3, 4, 6, 7, 9, 10, 11; + IndexFactor actual(keys.begin(), keys.end()); + BayesNet fragment = *actual.eliminate(3); + + IndexFactor expected(keys.begin()+3, keys.end()); + IndexConditional::shared_ptr expected0 = IndexConditional::FromRange(keys.begin(), keys.end(), 1); + IndexConditional::shared_ptr expected1 = IndexConditional::FromRange(keys.begin()+1, keys.end(), 1); + IndexConditional::shared_ptr expected2 = IndexConditional::FromRange(keys.begin()+2, keys.end(), 1); + + CHECK(assert_equal(fragment.size(), size_t(3))); + CHECK(assert_equal(expected, actual)); + BayesNet::const_iterator fragmentCond = fragment.begin(); + CHECK(assert_equal(**fragmentCond++, *expected0)); + CHECK(assert_equal(**fragmentCond++, *expected1)); + CHECK(assert_equal(**fragmentCond++, *expected2)); +} +#endif +/* ************************************************************************* */ +TEST(SymbolicFactor, EliminateSymbolic) +{ + const vector factors = list_of + (boost::make_shared(2,4,6)) + (boost::make_shared(1,2,5)) + (boost::make_shared(0,3)); + + const SymbolicFactorUnordered expectedFactor(4,5,6); + const SymbolicConditionalUnordered expectedConditional = + SymbolicConditionalUnordered::FromKeys(list_of(0)(1)(2)(3)(4)(5)(6), 4); + + SymbolicFactorUnordered::shared_ptr actualFactor; + SymbolicConditionalUnordered::shared_ptr actualConditional; + boost::tie(actualConditional, actualFactor) = + EliminateSymbolicUnordered(factors, list_of(0)(1)(2)(3)); + + CHECK(assert_equal(expectedConditional, *actualConditional)); + CHECK(assert_equal(expectedFactor, *actualFactor)); +} + +/* ************************************************************************* */ +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} +/* ************************************************************************* */ diff --git a/gtsam/symbolic/tests/testSymbolicFactor.cpp0 b/gtsam/symbolic/tests/testSymbolicFactor.cpp0 deleted file mode 100644 index a474c09a1..000000000 --- a/gtsam/symbolic/tests/testSymbolicFactor.cpp0 +++ /dev/null @@ -1,113 +0,0 @@ -/* ---------------------------------------------------------------------------- - - * GTSAM Copyright 2010, Georgia Tech Research Corporation, - * Atlanta, Georgia 30332-0415 - * All Rights Reserved - * Authors: Frank Dellaert, et al. (see THANKS for the full author list) - - * See LICENSE for the license information - - * -------------------------------------------------------------------------- */ - -/** - * @file testSymbolicFactor.cpp - * @brief Unit tests for a symbolic IndexFactor - * @author Frank Dellaert - */ - -#include -#include -#include -#include -#include - -#include -#include - -using namespace std; -using namespace gtsam; -using namespace boost::assign; - -/* ************************************************************************* */ -TEST(SymbolicFactor, constructor) { - - // Frontals sorted, parents not sorted - vector keys1; keys1 += 3, 4, 5, 9, 7, 8; - (void)IndexConditional(keys1, 3); - -// // Frontals not sorted -// vector keys2; keys2 += 3, 5, 4, 9, 7, 8; -// (void)IndexConditional::FromRange(keys2.begin(), keys2.end(), 3); - -// // Frontals not before parents -// vector keys3; keys3 += 3, 4, 5, 1, 7, 8; -// (void)IndexConditional::FromRange(keys3.begin(), keys3.end(), 3); -} - -/* ************************************************************************* */ -#ifdef TRACK_ELIMINATE -TEST(SymbolicFactor, eliminate) { - vector keys; keys += 2, 3, 4, 6, 7, 9, 10, 11; - IndexFactor actual(keys.begin(), keys.end()); - BayesNet fragment = *actual.eliminate(3); - - IndexFactor expected(keys.begin()+3, keys.end()); - IndexConditional::shared_ptr expected0 = IndexConditional::FromRange(keys.begin(), keys.end(), 1); - IndexConditional::shared_ptr expected1 = IndexConditional::FromRange(keys.begin()+1, keys.end(), 1); - IndexConditional::shared_ptr expected2 = IndexConditional::FromRange(keys.begin()+2, keys.end(), 1); - - CHECK(assert_equal(fragment.size(), size_t(3))); - CHECK(assert_equal(expected, actual)); - BayesNet::const_iterator fragmentCond = fragment.begin(); - CHECK(assert_equal(**fragmentCond++, *expected0)); - CHECK(assert_equal(**fragmentCond++, *expected1)); - CHECK(assert_equal(**fragmentCond++, *expected2)); -} -#endif -/* ************************************************************************* */ -TEST(SymbolicFactor, EliminateSymbolic) { - SymbolicFactorGraph factors; - factors.push_factor(2,4,6); - factors.push_factor(1,2,5); - factors.push_factor(0,3); - - IndexFactor expectedFactor(4,5,6); - std::vector keys; keys += 0,1,2,3,4,5,6; - IndexConditional::shared_ptr expectedConditional(new IndexConditional(keys, 4)); - - IndexFactor::shared_ptr actualFactor; - IndexConditional::shared_ptr actualConditional; - boost::tie(actualConditional, actualFactor) = EliminateSymbolic(factors, 4); - - CHECK(assert_equal(*expectedConditional, *actualConditional)); - CHECK(assert_equal(expectedFactor, *actualFactor)); - -// BayesNet expected_bn; -// vector parents; -// -// parents.clear(); parents += 1,2,3,4,5,6; -// expected_bn.push_back(IndexConditional::shared_ptr(new IndexConditional(0, parents))); -// -// parents.clear(); parents += 2,3,4,5,6; -// expected_bn.push_back(IndexConditional::shared_ptr(new IndexConditional(1, parents))); -// -// parents.clear(); parents += 3,4,5,6; -// expected_bn.push_back(IndexConditional::shared_ptr(new IndexConditional(2, parents))); -// -// parents.clear(); parents += 4,5,6; -// expected_bn.push_back(IndexConditional::shared_ptr(new IndexConditional(3, parents))); -// -// BayesNet::shared_ptr actual_bn; -// IndexFactor::shared_ptr actual_factor; -// boost::tie(actual_bn, actual_factor) = EliminateSymbolic(factors, 4); -// -// CHECK(assert_equal(expected_bn, *actual_bn)); -// CHECK(assert_equal(expected_factor, *actual_factor)); -} - -/* ************************************************************************* */ -int main() { - TestResult tr; - return TestRegistry::runAllTests(tr); -} -/* ************************************************************************* */ diff --git a/gtsam/symbolic/tests/testSymbolicFactorGraph.cpp b/gtsam/symbolic/tests/testSymbolicFactorGraph.cpp index 97f627726..9349850f6 100644 --- a/gtsam/symbolic/tests/testSymbolicFactorGraph.cpp +++ b/gtsam/symbolic/tests/testSymbolicFactorGraph.cpp @@ -23,6 +23,34 @@ using namespace std; using namespace gtsam; +/* ************************************************************************* */ +TEST(FactorGraph, eliminateFrontals) { + + SymbolicFactorGraph sfgOrig; + sfgOrig.push_factor(0,1); + sfgOrig.push_factor(0,2); + sfgOrig.push_factor(1,3); + sfgOrig.push_factor(1,4); + sfgOrig.push_factor(2,3); + sfgOrig.push_factor(4,5); + + IndexConditional::shared_ptr actualCond; + SymbolicFactorGraph actualSfg; + boost::tie(actualCond, actualSfg) = sfgOrig.eliminateFrontals(2); + + vector condIndices; + condIndices += 0,1,2,3,4; + IndexConditional expectedCond(condIndices, 2); + + SymbolicFactorGraph expectedSfg; + expectedSfg.push_factor(2,3); + expectedSfg.push_factor(4,5); + expectedSfg.push_factor(2,3,4); + + EXPECT(assert_equal(expectedSfg, actualSfg)); + EXPECT(assert_equal(expectedCond, *actualCond)); +} + /* ************************************************************************* */ //TEST(SymbolicFactorGraph, eliminateFrontals) { // diff --git a/gtsam/symbolic/tests/testJunctionTree.cpp0 b/gtsam/symbolic/tests/testSymbolicJunctionTree.cpp similarity index 100% rename from gtsam/symbolic/tests/testJunctionTree.cpp0 rename to gtsam/symbolic/tests/testSymbolicJunctionTree.cpp