diff --git a/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp b/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp index 6a3fb2388..ac5eccd14 100644 --- a/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp +++ b/gtsam/discrete/tests/testAlgebraicDecisionTree.cpp @@ -25,10 +25,7 @@ #include // for convert only #define DISABLE_TIMING -#include -#include #include -using namespace boost::assign; #include #include diff --git a/gtsam/discrete/tests/testDecisionTree.cpp b/gtsam/discrete/tests/testDecisionTree.cpp index 5ccbcf916..63b14b05e 100644 --- a/gtsam/discrete/tests/testDecisionTree.cpp +++ b/gtsam/discrete/tests/testDecisionTree.cpp @@ -27,9 +27,6 @@ #include -#include -using namespace boost::assign; - using namespace std; using namespace gtsam; diff --git a/gtsam/discrete/tests/testDecisionTreeFactor.cpp b/gtsam/discrete/tests/testDecisionTreeFactor.cpp index 84e45a0f5..1829db034 100644 --- a/gtsam/discrete/tests/testDecisionTreeFactor.cpp +++ b/gtsam/discrete/tests/testDecisionTreeFactor.cpp @@ -23,9 +23,6 @@ #include #include -#include -using namespace boost::assign; - using namespace std; using namespace gtsam; diff --git a/gtsam/discrete/tests/testDiscreteBayesNet.cpp b/gtsam/discrete/tests/testDiscreteBayesNet.cpp index 19af676f7..6303a5487 100644 --- a/gtsam/discrete/tests/testDiscreteBayesNet.cpp +++ b/gtsam/discrete/tests/testDiscreteBayesNet.cpp @@ -26,11 +26,6 @@ #include -#include -#include - -using namespace boost::assign; - #include #include #include @@ -115,11 +110,11 @@ TEST(DiscreteBayesNet, Asia) { EXPECT(assert_equal(expected2, *chordal->back())); // now sample from it - DiscreteValues expectedSample; + DiscreteValues expectedSample{{Asia.first, 1}, {Dyspnea.first, 1}, + {XRay.first, 1}, {Tuberculosis.first, 0}, + {Smoking.first, 1}, {Either.first, 1}, + {LungCancer.first, 1}, {Bronchitis.first, 0}}; SETDEBUG("DiscreteConditional::sample", false); - insert(expectedSample)(Asia.first, 1)(Dyspnea.first, 1)(XRay.first, 1)( - Tuberculosis.first, 0)(Smoking.first, 1)(Either.first, 1)( - LungCancer.first, 1)(Bronchitis.first, 0); auto actualSample = chordal2->sample(); EXPECT(assert_equal(expectedSample, actualSample)); } diff --git a/gtsam/discrete/tests/testDiscreteBayesTree.cpp b/gtsam/discrete/tests/testDiscreteBayesTree.cpp index ab69e82d7..0a7dc72f4 100644 --- a/gtsam/discrete/tests/testDiscreteBayesTree.cpp +++ b/gtsam/discrete/tests/testDiscreteBayesTree.cpp @@ -21,9 +21,6 @@ #include #include -#include -using namespace boost::assign; - #include #include diff --git a/gtsam/discrete/tests/testDiscreteConditional.cpp b/gtsam/discrete/tests/testDiscreteConditional.cpp index 13a34dd19..9098f7a1d 100644 --- a/gtsam/discrete/tests/testDiscreteConditional.cpp +++ b/gtsam/discrete/tests/testDiscreteConditional.cpp @@ -17,10 +17,7 @@ * @date Feb 14, 2011 */ -#include -#include #include -using namespace boost::assign; #include #include diff --git a/gtsam/discrete/tests/testDiscreteFactor.cpp b/gtsam/discrete/tests/testDiscreteFactor.cpp index db0491c9d..7fc5ee248 100644 --- a/gtsam/discrete/tests/testDiscreteFactor.cpp +++ b/gtsam/discrete/tests/testDiscreteFactor.cpp @@ -21,9 +21,6 @@ #include #include -#include -using namespace boost::assign; - using namespace std; using namespace gtsam; using namespace gtsam::serializationTestHelpers; diff --git a/gtsam/discrete/tests/testDiscreteFactorGraph.cpp b/gtsam/discrete/tests/testDiscreteFactorGraph.cpp index 3d9621aff..2d79b9de9 100644 --- a/gtsam/discrete/tests/testDiscreteFactorGraph.cpp +++ b/gtsam/discrete/tests/testDiscreteFactorGraph.cpp @@ -23,9 +23,6 @@ #include -#include -using namespace boost::assign; - using namespace std; using namespace gtsam; @@ -49,9 +46,7 @@ TEST_UNSAFE(DiscreteFactorGraph, debugScheduler) { // Check MPE. auto actualMPE = graph.optimize(); - DiscreteValues mpe; - insert(mpe)(0, 2)(1, 1)(2, 0)(3, 0); - EXPECT(assert_equal(mpe, actualMPE)); + EXPECT(assert_equal({{0, 2}, {1, 1}, {2, 0}, {3, 0}}, actualMPE)); } /* ************************************************************************* */ @@ -149,8 +144,7 @@ TEST(DiscreteFactorGraph, test) { EXPECT(assert_equal(expectedBayesNet, *actual2)); // Test mpe - DiscreteValues mpe; - insert(mpe)(0, 0)(1, 0)(2, 0); + DiscreteValues mpe { {0, 0}, {1, 0}, {2, 0}}; auto actualMPE = graph.optimize(); EXPECT(assert_equal(mpe, actualMPE)); EXPECT_DOUBLES_EQUAL(9, graph(mpe), 1e-5); // regression @@ -182,8 +176,7 @@ TEST_UNSAFE(DiscreteFactorGraph, testMaxProduct) { graph.add(C & B, "0.1 0.9 0.4 0.6"); // Created expected MPE - DiscreteValues mpe; - insert(mpe)(0, 0)(1, 1)(2, 1); + DiscreteValues mpe{{0, 0}, {1, 1}, {2, 1}}; // Do max-product with different orderings for (Ordering::OrderingType orderingType : @@ -209,8 +202,7 @@ TEST(DiscreteFactorGraph, marginalIsNotMPE) { bayesNet.add(A % "10/9"); // The expected MPE is A=1, B=1 - DiscreteValues mpe; - insert(mpe)(0, 1)(1, 1); + DiscreteValues mpe { {0, 1}, {1, 1} }; // Which we verify using max-product: DiscreteFactorGraph graph(bayesNet); @@ -240,8 +232,7 @@ TEST(DiscreteFactorGraph, testMPE_Darwiche09book_p244) { graph.add(T1 & T2 & A, "1 0 0 1 0 1 1 0"); graph.add(A, "1 0"); // evidence, A = yes (first choice in Darwiche) - DiscreteValues mpe; - insert(mpe)(4, 0)(2, 1)(3, 1)(0, 1)(1, 1); + DiscreteValues mpe { {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 0}}; EXPECT_DOUBLES_EQUAL(0.33858, graph(mpe), 1e-5); // regression // You can check visually by printing product: // graph.product().print("Darwiche-product"); @@ -267,112 +258,6 @@ TEST(DiscreteFactorGraph, testMPE_Darwiche09book_p244) { EXPECT_LONGS_EQUAL(2, bayesTree->size()); } -#ifdef OLD - -/* ************************************************************************* */ -/** - * Key type for discrete conditionals - * Includes name and cardinality - */ -class Key2 { -private: -std::string wff_; -size_t cardinality_; -public: -/** Constructor, defaults to binary */ -Key2(const std::string& name, size_t cardinality = 2) : -wff_(name), cardinality_(cardinality) { -} -const std::string& name() const { - return wff_; -} - -/** provide streaming */ -friend std::ostream& operator <<(std::ostream &os, const Key2 &key); -}; - -struct Factor2 { -std::string wff_; -Factor2() : -wff_("@") { -} -Factor2(const std::string& s) : -wff_(s) { -} -Factor2(const Key2& key) : -wff_(key.name()) { -} - -friend std::ostream& operator <<(std::ostream &os, const Factor2 &f); -friend Factor2 operator -(const Key2& key); -}; - -std::ostream& operator <<(std::ostream &os, const Factor2 &f) { -os << f.wff_; -return os; -} - -/** negation */ -Factor2 operator -(const Key2& key) { -return Factor2("-" + key.name()); -} - -/** OR */ -Factor2 operator ||(const Factor2 &factor1, const Factor2 &factor2) { -return Factor2(std::string("(") + factor1.wff_ + " || " + factor2.wff_ + ")"); -} - -/** AND */ -Factor2 operator &&(const Factor2 &factor1, const Factor2 &factor2) { -return Factor2(std::string("(") + factor1.wff_ + " && " + factor2.wff_ + ")"); -} - -/** implies */ -Factor2 operator >>(const Factor2 &factor1, const Factor2 &factor2) { -return Factor2(std::string("(") + factor1.wff_ + " >> " + factor2.wff_ + ")"); -} - -struct Graph2: public std::list { - -/** Add a factor graph*/ -// void operator +=(const Graph2& graph) { -// for(const Factor2& f: graph) -// push_back(f); -// } -friend std::ostream& operator <<(std::ostream &os, const Graph2& graph); - -}; - -/** Add a factor */ -//Graph2 operator +=(Graph2& graph, const Factor2& factor) { -// graph.push_back(factor); -// return graph; -//} -std::ostream& operator <<(std::ostream &os, const Graph2& graph) { -for(const Factor2& f: graph) -os << f << endl; -return os; -} - -/* ************************************************************************* */ -TEST(DiscreteFactorGraph, Sugar) -{ -Key2 M("Mythical"), I("Immortal"), A("Mammal"), H("Horned"), G("Magical"); - -// Test this desired construction -Graph2 unicorns; -unicorns += M >> -A; -unicorns += (-M) >> (-I && A); -unicorns += (I || A) >> H; -unicorns += H >> G; - -// should be done by adapting boost::assign: -// unicorns += (-M) >> (-I && A), (I || A) >> H , H >> G; - -cout << unicorns; -} -#endif - /* ************************************************************************* */ TEST(DiscreteFactorGraph, Dot) { // Create Factor graph diff --git a/gtsam/discrete/tests/testDiscreteLookupDAG.cpp b/gtsam/discrete/tests/testDiscreteLookupDAG.cpp index 04b859780..8c3ff5a1d 100644 --- a/gtsam/discrete/tests/testDiscreteLookupDAG.cpp +++ b/gtsam/discrete/tests/testDiscreteLookupDAG.cpp @@ -20,11 +20,7 @@ #include #include -#include -#include - using namespace gtsam; -using namespace boost::assign; /* ************************************************************************* */ TEST(DiscreteLookupDAG, argmax) { @@ -43,8 +39,7 @@ TEST(DiscreteLookupDAG, argmax) { dag.add(1, DiscreteKeys{A}, adtA); // The expected MPE is A=1, B=1 - DiscreteValues mpe; - insert(mpe)(0, 1)(1, 1); + DiscreteValues mpe{{0, 1}, {1, 1}}; // check: auto actualMPE = dag.argmax(); diff --git a/gtsam/discrete/tests/testDiscreteMarginals.cpp b/gtsam/discrete/tests/testDiscreteMarginals.cpp index 3208f81c5..3213e514f 100644 --- a/gtsam/discrete/tests/testDiscreteMarginals.cpp +++ b/gtsam/discrete/tests/testDiscreteMarginals.cpp @@ -19,9 +19,6 @@ #include -#include -using namespace boost::assign; - #include using namespace std; diff --git a/gtsam/discrete/tests/testDiscreteValues.cpp b/gtsam/discrete/tests/testDiscreteValues.cpp index 6cfc11531..47989481c 100644 --- a/gtsam/discrete/tests/testDiscreteValues.cpp +++ b/gtsam/discrete/tests/testDiscreteValues.cpp @@ -21,9 +21,6 @@ #include #include -#include -using namespace boost::assign; - using namespace std; using namespace gtsam; diff --git a/gtsam/discrete/tests/testSignature.cpp b/gtsam/discrete/tests/testSignature.cpp index 737bd8aef..02e7a1d10 100644 --- a/gtsam/discrete/tests/testSignature.cpp +++ b/gtsam/discrete/tests/testSignature.cpp @@ -21,12 +21,10 @@ #include #include -#include #include using namespace std; using namespace gtsam; -using namespace boost::assign; DiscreteKey X(0, 2), Y(1, 3), Z(2, 2); @@ -57,12 +55,8 @@ TEST(testSignature, simple_conditional) { /* ************************************************************************* */ TEST(testSignature, simple_conditional_nonparser) { - Signature::Table table; - Signature::Row row1, row2, row3; - row1 += 1.0, 1.0; - row2 += 2.0, 3.0; - row3 += 1.0, 4.0; - table += row1, row2, row3; + Signature::Row row1{1, 1}, row2{2, 3}, row3{1, 4}; + Signature::Table table{row1, row2, row3}; Signature sig(X | Y = table); CHECK(sig.key() == X); diff --git a/gtsam_unstable/discrete/examples/schedulingExample.cpp b/gtsam_unstable/discrete/examples/schedulingExample.cpp index 487edc97a..c9024e018 100644 --- a/gtsam_unstable/discrete/examples/schedulingExample.cpp +++ b/gtsam_unstable/discrete/examples/schedulingExample.cpp @@ -12,14 +12,11 @@ #include #include -#include -#include #include #include #include -using namespace boost::assign; using namespace std; using namespace gtsam; diff --git a/gtsam_unstable/discrete/examples/schedulingQuals12.cpp b/gtsam_unstable/discrete/examples/schedulingQuals12.cpp index 830d59ba7..d3529cb55 100644 --- a/gtsam_unstable/discrete/examples/schedulingQuals12.cpp +++ b/gtsam_unstable/discrete/examples/schedulingQuals12.cpp @@ -12,14 +12,11 @@ #include #include -#include -#include #include #include #include -using namespace boost::assign; using namespace std; using namespace gtsam; diff --git a/gtsam_unstable/discrete/examples/schedulingQuals13.cpp b/gtsam_unstable/discrete/examples/schedulingQuals13.cpp index b24f9bf0a..27c959675 100644 --- a/gtsam_unstable/discrete/examples/schedulingQuals13.cpp +++ b/gtsam_unstable/discrete/examples/schedulingQuals13.cpp @@ -12,14 +12,11 @@ #include #include -#include -#include #include #include #include -using namespace boost::assign; using namespace std; using namespace gtsam; diff --git a/gtsam_unstable/discrete/tests/testCSP.cpp b/gtsam_unstable/discrete/tests/testCSP.cpp index fb386b255..5756cb99c 100644 --- a/gtsam_unstable/discrete/tests/testCSP.cpp +++ b/gtsam_unstable/discrete/tests/testCSP.cpp @@ -8,8 +8,6 @@ #include #include -#include -using boost::assign::insert; #include #include @@ -133,8 +131,7 @@ TEST(CSP, allInOne) { // Solve auto mpe = csp.optimize(); - DiscreteValues expected; - insert(expected)(ID.first, 1)(UT.first, 0)(AZ.first, 1); + DiscreteValues expected {{ID.first, 1}, {UT.first, 0}, {AZ.first, 1}}; EXPECT(assert_equal(expected, mpe)); EXPECT_DOUBLES_EQUAL(1, csp(mpe), 1e-9); } @@ -172,8 +169,8 @@ TEST(CSP, WesternUS) { csp.addAllDiff(WY, CO); csp.addAllDiff(CO, NM); - DiscreteValues mpe; - insert(mpe)(0, 2)(1, 3)(2, 2)(3, 1)(4, 1)(5, 3)(6, 3)(7, 2)(8, 0)(9, 1)(10, 0); + DiscreteValues mpe{{0, 2}, {1, 3}, {2, 2}, {3, 1}, {4, 1}, {5, 3}, + {6, 3}, {7, 2}, {8, 0}, {9, 1}, {10, 0}}; // Create ordering according to example in ND-CSP.lyx Ordering ordering; @@ -224,8 +221,7 @@ TEST(CSP, ArcConsistency) { // Solve auto mpe = csp.optimize(); - DiscreteValues expected; - insert(expected)(ID.first, 1)(UT.first, 0)(AZ.first, 2); + DiscreteValues expected {{ID.first, 1}, {UT.first, 0}, {AZ.first, 2}}; EXPECT(assert_equal(expected, mpe)); EXPECT_DOUBLES_EQUAL(1, csp(mpe), 1e-9); diff --git a/gtsam_unstable/discrete/tests/testScheduler.cpp b/gtsam_unstable/discrete/tests/testScheduler.cpp index 086057a46..3b0528360 100644 --- a/gtsam_unstable/discrete/tests/testScheduler.cpp +++ b/gtsam_unstable/discrete/tests/testScheduler.cpp @@ -10,11 +10,8 @@ #include #include -#include -#include #include -using namespace boost::assign; using namespace std; using namespace gtsam; diff --git a/gtsam_unstable/discrete/tests/testSudoku.cpp b/gtsam_unstable/discrete/tests/testSudoku.cpp index 8b2858169..9796c25f1 100644 --- a/gtsam_unstable/discrete/tests/testSudoku.cpp +++ b/gtsam_unstable/discrete/tests/testSudoku.cpp @@ -9,8 +9,6 @@ #include #include -#include -using boost::assign::insert; #include #include @@ -128,11 +126,14 @@ TEST(Sudoku, small) { // optimize and check auto solution = csp.optimize(); DiscreteValues expected; - insert(expected)(csp.key(0, 0), 0)(csp.key(0, 1), 1)(csp.key(0, 2), 2)( - csp.key(0, 3), 3)(csp.key(1, 0), 2)(csp.key(1, 1), 3)(csp.key(1, 2), 0)( - csp.key(1, 3), 1)(csp.key(2, 0), 3)(csp.key(2, 1), 2)(csp.key(2, 2), 1)( - csp.key(2, 3), 0)(csp.key(3, 0), 1)(csp.key(3, 1), 0)(csp.key(3, 2), 3)( - csp.key(3, 3), 2); + expected = {{csp.key(0, 0), 0}, {csp.key(0, 1), 1}, + {csp.key(0, 2), 2}, {csp.key(0, 3), 3}, // + {csp.key(1, 0), 2}, {csp.key(1, 1), 3}, + {csp.key(1, 2), 0}, {csp.key(1, 3), 1}, // + {csp.key(2, 0), 3}, {csp.key(2, 1), 2}, + {csp.key(2, 2), 1}, {csp.key(2, 3), 0}, // + {csp.key(3, 0), 1}, {csp.key(3, 1), 0}, + {csp.key(3, 2), 3}, {csp.key(3, 3), 2}}; EXPECT(assert_equal(expected, solution)); // csp.printAssignment(solution);