Get rid of all (pre c++11) += calls to create Orderings.

release/4.3a0
Frank Dellaert 2023-02-05 16:37:04 -08:00
parent a638f3a991
commit 285cbe4f22
25 changed files with 64 additions and 131 deletions

View File

@ -51,8 +51,7 @@ int main(int argc, char **argv) {
DiscreteFactorGraph fg(asia); DiscreteFactorGraph fg(asia);
// Create solver and eliminate // Create solver and eliminate
Ordering ordering; const Ordering ordering{0, 1, 2, 3, 4, 5, 6, 7};
ordering += Key(0), Key(1), Key(2), Key(3), Key(4), Key(5), Key(6), Key(7);
// solve // solve
auto mpe = fg.optimize(); auto mpe = fg.optimize();

View File

@ -94,8 +94,7 @@ TEST(DiscreteBayesNet, Asia) {
EXPECT(assert_equal(vs, marginals.marginalProbabilities(Smoking))); EXPECT(assert_equal(vs, marginals.marginalProbabilities(Smoking)));
// Create solver and eliminate // Create solver and eliminate
Ordering ordering; const Ordering ordering{0, 1, 2, 3, 4, 5, 6, 7};
ordering += Key(0), Key(1), Key(2), Key(3), Key(4), Key(5), Key(6), Key(7);
DiscreteBayesNet::shared_ptr chordal = fg.eliminateSequential(ordering); DiscreteBayesNet::shared_ptr chordal = fg.eliminateSequential(ordering);
DiscreteConditional expected2(Bronchitis % "11/9"); DiscreteConditional expected2(Bronchitis % "11/9");
EXPECT(assert_equal(expected2, *chordal->back())); EXPECT(assert_equal(expected2, *chordal->back()));

View File

@ -107,8 +107,7 @@ TEST(DiscreteFactorGraph, test) {
graph.add(C & B, "3 1 1 3"); graph.add(C & B, "3 1 1 3");
// Test EliminateDiscrete // Test EliminateDiscrete
Ordering frontalKeys; const Ordering frontalKeys{0};
frontalKeys += Key(0);
const auto [conditional, newFactor] = EliminateDiscrete(graph, frontalKeys); const auto [conditional, newFactor] = EliminateDiscrete(graph, frontalKeys);
// Check Conditional // Check Conditional
@ -123,8 +122,7 @@ TEST(DiscreteFactorGraph, test) {
EXPECT(assert_equal(expectedFactor, *newFactor)); EXPECT(assert_equal(expectedFactor, *newFactor));
// Test using elimination tree // Test using elimination tree
Ordering ordering; const Ordering ordering{0, 1, 2};
ordering += Key(0), Key(1), Key(2);
DiscreteEliminationTree etree(graph, ordering); DiscreteEliminationTree etree(graph, ordering);
const auto [actual, remainingGraph] = etree.eliminate(&EliminateDiscrete); const auto [actual, remainingGraph] = etree.eliminate(&EliminateDiscrete);
@ -231,8 +229,7 @@ TEST(DiscreteFactorGraph, testMPE_Darwiche09book_p244) {
EXPECT(assert_equal(mpe, actualMPE)); EXPECT(assert_equal(mpe, actualMPE));
// Check Bayes Net // Check Bayes Net
Ordering ordering; const Ordering ordering{0, 1, 2, 3, 4};
ordering += Key(0), Key(1), Key(2), Key(3), Key(4);
auto chordal = graph.eliminateSequential(ordering); auto chordal = graph.eliminateSequential(ordering);
EXPECT_LONGS_EQUAL(5, chordal->size()); EXPECT_LONGS_EQUAL(5, chordal->size());

View File

@ -91,7 +91,7 @@ TEST(SimpleParser, GibberishInMiddle) {
// A test with slash in the end // A test with slash in the end
TEST(SimpleParser, SlashInEnd) { TEST(SimpleParser, SlashInEnd) {
const auto table = SignatureParser::parse("1/1 2/"); const auto table = SignatureParser::Parse("1/1 2/");
EXPECT(!table); EXPECT(!table);
} }

View File

@ -97,7 +97,7 @@ TEST(HybridBayesTree, OptimizeAssignment) {
// Create ordering. // Create ordering.
Ordering ordering; Ordering ordering;
for (size_t k = 0; k < s.K; k++) ordering += X(k); for (size_t k = 0; k < s.K; k++) ordering.push_back(X(k));
const auto [hybridBayesNet, remainingFactorGraph] = const auto [hybridBayesNet, remainingFactorGraph] =
s.linearizedFactorGraph.eliminatePartialSequential(ordering); s.linearizedFactorGraph.eliminatePartialSequential(ordering);
@ -139,7 +139,7 @@ TEST(HybridBayesTree, Optimize) {
// Create ordering. // Create ordering.
Ordering ordering; Ordering ordering;
for (size_t k = 0; k < s.K; k++) ordering += X(k); for (size_t k = 0; k < s.K; k++) ordering.push_back(X(k));
const auto [hybridBayesNet, remainingFactorGraph] = const auto [hybridBayesNet, remainingFactorGraph] =
s.linearizedFactorGraph.eliminatePartialSequential(ordering); s.linearizedFactorGraph.eliminatePartialSequential(ordering);

View File

@ -83,10 +83,10 @@ TEST(HybridEstimation, Full) {
Ordering hybridOrdering; Ordering hybridOrdering;
for (size_t k = 0; k < K; k++) { for (size_t k = 0; k < K; k++) {
hybridOrdering += X(k); hybridOrdering.push_back(X(k));
} }
for (size_t k = 0; k < K - 1; k++) { for (size_t k = 0; k < K - 1; k++) {
hybridOrdering += M(k); hybridOrdering.push_back(M(k));
} }
HybridBayesNet::shared_ptr bayesNet = HybridBayesNet::shared_ptr bayesNet =
@ -442,8 +442,7 @@ TEST(HybridEstimation, eliminateSequentialRegression) {
DiscreteConditional expected(m % "0.51341712/1"); // regression DiscreteConditional expected(m % "0.51341712/1"); // regression
// Eliminate into BN using one ordering // Eliminate into BN using one ordering
Ordering ordering1; const Ordering ordering1{X(0), X(1), M(0)};
ordering1 += X(0), X(1), M(0);
HybridBayesNet::shared_ptr bn1 = fg->eliminateSequential(ordering1); HybridBayesNet::shared_ptr bn1 = fg->eliminateSequential(ordering1);
// Check that the discrete conditional matches the expected. // Check that the discrete conditional matches the expected.
@ -451,8 +450,7 @@ TEST(HybridEstimation, eliminateSequentialRegression) {
EXPECT(assert_equal(expected, *dc1, 1e-9)); EXPECT(assert_equal(expected, *dc1, 1e-9));
// Eliminate into BN using a different ordering // Eliminate into BN using a different ordering
Ordering ordering2; const Ordering ordering2{X(0), X(1), M(0)};
ordering2 += X(0), X(1), M(0);
HybridBayesNet::shared_ptr bn2 = fg->eliminateSequential(ordering2); HybridBayesNet::shared_ptr bn2 = fg->eliminateSequential(ordering2);
// Check that the discrete conditional matches the expected. // Check that the discrete conditional matches the expected.

View File

@ -126,10 +126,7 @@ TEST(HybridGaussianElimination, IncrementalInference) {
/********************************************************/ /********************************************************/
// Run batch elimination so we can compare results. // Run batch elimination so we can compare results.
Ordering ordering; const Ordering ordering {X(0), X(1), X(2)};
ordering += X(0);
ordering += X(1);
ordering += X(2);
// Now we calculate the expected factors using full elimination // Now we calculate the expected factors using full elimination
const auto [expectedHybridBayesTree, expectedRemainingGraph] = const auto [expectedHybridBayesTree, expectedRemainingGraph] =
@ -158,12 +155,10 @@ TEST(HybridGaussianElimination, IncrementalInference) {
// We only perform manual continuous elimination for 0,0. // We only perform manual continuous elimination for 0,0.
// The other discrete probabilities on M(2) are calculated the same way // The other discrete probabilities on M(2) are calculated the same way
Ordering discrete_ordering; const Ordering discreteOrdering{M(0), M(1)};
discrete_ordering += M(0);
discrete_ordering += M(1);
HybridBayesTree::shared_ptr discreteBayesTree = HybridBayesTree::shared_ptr discreteBayesTree =
expectedRemainingGraph->BaseEliminateable::eliminateMultifrontal( expectedRemainingGraph->BaseEliminateable::eliminateMultifrontal(
discrete_ordering); discreteOrdering);
DiscreteValues m00; DiscreteValues m00;
m00[M(0)] = 0, m00[M(1)] = 0; m00[M(0)] = 0, m00[M(1)] = 0;
@ -225,7 +220,7 @@ TEST(HybridGaussianElimination, Approx_inference) {
// Create ordering. // Create ordering.
Ordering ordering; Ordering ordering;
for (size_t j = 0; j < 4; j++) { for (size_t j = 0; j < 4; j++) {
ordering += X(j); ordering.push_back(X(j));
} }
// Now we calculate the actual factors using full elimination // Now we calculate the actual factors using full elimination

View File

@ -265,7 +265,7 @@ TEST(HybridFactorGraph, EliminationTree) {
// Create ordering. // Create ordering.
Ordering ordering; Ordering ordering;
for (size_t k = 0; k < self.K; k++) ordering += X(k); for (size_t k = 0; k < self.K; k++) ordering.push_back(X(k));
// Create elimination tree. // Create elimination tree.
HybridEliminationTree etree(self.linearizedFactorGraph, ordering); HybridEliminationTree etree(self.linearizedFactorGraph, ordering);
@ -286,8 +286,7 @@ TEST(GaussianElimination, Eliminate_x0) {
factors.push_back(self.linearizedFactorGraph[1]); factors.push_back(self.linearizedFactorGraph[1]);
// Eliminate x0 // Eliminate x0
Ordering ordering; const Ordering ordering{X(0)};
ordering += X(0);
auto result = EliminateHybrid(factors, ordering); auto result = EliminateHybrid(factors, ordering);
CHECK(result.first); CHECK(result.first);
@ -310,8 +309,7 @@ TEST(HybridsGaussianElimination, Eliminate_x1) {
factors.push_back(self.linearizedFactorGraph[2]); // involves m1 factors.push_back(self.linearizedFactorGraph[2]); // involves m1
// Eliminate x1 // Eliminate x1
Ordering ordering; const Ordering ordering{X(1)};
ordering += X(1);
auto result = EliminateHybrid(factors, ordering); auto result = EliminateHybrid(factors, ordering);
CHECK(result.first); CHECK(result.first);
@ -346,9 +344,7 @@ TEST(HybridGaussianElimination, EliminateHybrid_2_Variable) {
auto factors = self.linearizedFactorGraph; auto factors = self.linearizedFactorGraph;
// Eliminate x0 // Eliminate x0
Ordering ordering; const Ordering ordering{X(0), X(1)};
ordering += X(0);
ordering += X(1);
const auto [hybridConditionalMixture, factorOnModes] = const auto [hybridConditionalMixture, factorOnModes] =
EliminateHybrid(factors, ordering); EliminateHybrid(factors, ordering);
@ -379,7 +375,7 @@ TEST(HybridFactorGraph, Partial_Elimination) {
// Create ordering of only continuous variables. // Create ordering of only continuous variables.
Ordering ordering; Ordering ordering;
for (size_t k = 0; k < self.K; k++) ordering += X(k); for (size_t k = 0; k < self.K; k++) ordering.push_back(X(k));
// Eliminate partially i.e. only continuous part. // Eliminate partially i.e. only continuous part.
const auto [hybridBayesNet, remainingFactorGraph] = const auto [hybridBayesNet, remainingFactorGraph] =
@ -415,7 +411,7 @@ TEST(HybridFactorGraph, Full_Elimination) {
{ {
// Create ordering. // Create ordering.
Ordering ordering; Ordering ordering;
for (size_t k = 0; k < self.K; k++) ordering += X(k); for (size_t k = 0; k < self.K; k++) ordering.push_back(X(k));
// Eliminate partially. // Eliminate partially.
const auto [hybridBayesNet_partial, remainingFactorGraph_partial] = const auto [hybridBayesNet_partial, remainingFactorGraph_partial] =
@ -430,15 +426,15 @@ TEST(HybridFactorGraph, Full_Elimination) {
} }
ordering.clear(); ordering.clear();
for (size_t k = 0; k < self.K - 1; k++) ordering += M(k); for (size_t k = 0; k < self.K - 1; k++) ordering.push_back(M(k));
discreteBayesNet = discreteBayesNet =
*discrete_fg.eliminateSequential(ordering, EliminateDiscrete); *discrete_fg.eliminateSequential(ordering, EliminateDiscrete);
} }
// Create ordering. // Create ordering.
Ordering ordering; Ordering ordering;
for (size_t k = 0; k < self.K; k++) ordering += X(k); for (size_t k = 0; k < self.K; k++) ordering.push_back(X(k));
for (size_t k = 0; k < self.K - 1; k++) ordering += M(k); for (size_t k = 0; k < self.K - 1; k++) ordering.push_back(M(k));
// Eliminate partially. // Eliminate partially.
HybridBayesNet::shared_ptr hybridBayesNet = HybridBayesNet::shared_ptr hybridBayesNet =
@ -479,7 +475,7 @@ TEST(HybridFactorGraph, Printing) {
// Create ordering. // Create ordering.
Ordering ordering; Ordering ordering;
for (size_t k = 0; k < self.K; k++) ordering += X(k); for (size_t k = 0; k < self.K; k++) ordering.push_back(X(k));
// Eliminate partially. // Eliminate partially.
const auto [hybridBayesNet, remainingFactorGraph] = const auto [hybridBayesNet, remainingFactorGraph] =
@ -705,11 +701,7 @@ TEST(HybridFactorGraph, DefaultDecisionTree) {
initialEstimate.insert(L(1), Point2(4.1, 1.8)); initialEstimate.insert(L(1), Point2(4.1, 1.8));
// We want to eliminate variables not connected to DCFactors first. // We want to eliminate variables not connected to DCFactors first.
Ordering ordering; const Ordering ordering {L(0), L(1), X(0), X(1)};
ordering += L(0);
ordering += L(1);
ordering += X(0);
ordering += X(1);
HybridGaussianFactorGraph linearized = *fg.linearize(initialEstimate); HybridGaussianFactorGraph linearized = *fg.linearize(initialEstimate);

View File

@ -143,10 +143,7 @@ TEST(HybridNonlinearISAM, IncrementalInference) {
/********************************************************/ /********************************************************/
// Run batch elimination so we can compare results. // Run batch elimination so we can compare results.
Ordering ordering; const Ordering ordering {X(0), X(1), X(2)};
ordering += X(0);
ordering += X(1);
ordering += X(2);
// Now we calculate the actual factors using full elimination // Now we calculate the actual factors using full elimination
const auto [expectedHybridBayesTree, expectedRemainingGraph] = const auto [expectedHybridBayesTree, expectedRemainingGraph] =
@ -176,12 +173,10 @@ TEST(HybridNonlinearISAM, IncrementalInference) {
// We only perform manual continuous elimination for 0,0. // We only perform manual continuous elimination for 0,0.
// The other discrete probabilities on M(1) are calculated the same way // The other discrete probabilities on M(1) are calculated the same way
Ordering discrete_ordering; const Ordering discreteOrdering{M(0), M(1)};
discrete_ordering += M(0);
discrete_ordering += M(1);
HybridBayesTree::shared_ptr discreteBayesTree = HybridBayesTree::shared_ptr discreteBayesTree =
expectedRemainingGraph->BaseEliminateable::eliminateMultifrontal( expectedRemainingGraph->BaseEliminateable::eliminateMultifrontal(
discrete_ordering); discreteOrdering);
DiscreteValues m00; DiscreteValues m00;
m00[M(0)] = 0, m00[M(1)] = 0; m00[M(0)] = 0, m00[M(1)] = 0;
@ -244,7 +239,7 @@ TEST(HybridNonlinearISAM, Approx_inference) {
// Create ordering. // Create ordering.
Ordering ordering; Ordering ordering;
for (size_t j = 0; j < 4; j++) { for (size_t j = 0; j < 4; j++) {
ordering += X(j); ordering.push_back(X(j));
} }
// Now we calculate the actual factors using full elimination // Now we calculate the actual factors using full elimination

View File

@ -66,15 +66,6 @@ public:
return boost::assign::make_list_inserter( return boost::assign::make_list_inserter(
boost::assign_detail::call_push_back<This>(*this))(key); boost::assign_detail::call_push_back<This>(*this))(key);
} }
#else
/** A simple inserter to insert one key at a time
* @param key The key to insert
* @return The ordering
*/
This& operator+=(Key key) {
push_back(key);
return *this;
}
#endif #endif
/** /**

View File

@ -211,8 +211,7 @@ TEST(GaussianBayesNet, MonteCarloIntegration) {
/* ************************************************************************* */ /* ************************************************************************* */
TEST(GaussianBayesNet, ordering) TEST(GaussianBayesNet, ordering)
{ {
Ordering expected; const Ordering expected{_x_, _y_};
expected += _x_, _y_;
const auto actual = noisyBayesNet.ordering(); const auto actual = noisyBayesNet.ordering();
EXPECT(assert_equal(expected, actual)); EXPECT(assert_equal(expected, actual));
} }

View File

@ -35,8 +35,7 @@ namespace gtsam {
// Compute the marginal on the last key // Compute the marginal on the last key
// Solve the linear factor graph, converting it into a linear Bayes Network // Solve the linear factor graph, converting it into a linear Bayes Network
// P(x0,x1) = P(x0|x1)*P(x1) // P(x0,x1) = P(x0|x1)*P(x1)
Ordering lastKeyAsOrdering; const Ordering lastKeyAsOrdering{lastKey};
lastKeyAsOrdering += lastKey;
const GaussianConditional::shared_ptr marginal = const GaussianConditional::shared_ptr marginal =
linearFactorGraph.marginalMultifrontalBayesNet(lastKeyAsOrdering)->front(); linearFactorGraph.marginalMultifrontalBayesNet(lastKeyAsOrdering)->front();

View File

@ -80,8 +80,7 @@ TEST(SymbolicFactorGraph, eliminatePartialSequential) {
/* ************************************************************************* */ /* ************************************************************************* */
TEST(SymbolicFactorGraph, eliminateFullMultifrontal) { TEST(SymbolicFactorGraph, eliminateFullMultifrontal) {
Ordering ordering; Ordering ordering{0, 1, 2, 3};
ordering += 0, 1, 2, 3;
SymbolicBayesTree actual1 = *simpleChain.eliminateMultifrontal(ordering); SymbolicBayesTree actual1 = *simpleChain.eliminateMultifrontal(ordering);
EXPECT(assert_equal(simpleChainBayesTree, actual1)); EXPECT(assert_equal(simpleChainBayesTree, actual1));
@ -223,8 +222,7 @@ TEST(SymbolicFactorGraph, eliminate_disconnected_graph) {
expected.emplace_shared<SymbolicConditional>(3, 4); expected.emplace_shared<SymbolicConditional>(3, 4);
expected.emplace_shared<SymbolicConditional>(4); expected.emplace_shared<SymbolicConditional>(4);
Ordering order; const Ordering order{0, 1, 2, 3, 4};
order += 0, 1, 2, 3, 4;
SymbolicBayesNet actual = *fg.eliminateSequential(order); SymbolicBayesNet actual = *fg.eliminateSequential(order);
EXPECT(assert_equal(expected, actual)); EXPECT(assert_equal(expected, actual));

View File

@ -35,7 +35,7 @@ using namespace std;
****************************************************************************/ ****************************************************************************/
TEST( JunctionTree, constructor ) TEST( JunctionTree, constructor )
{ {
Ordering order; order += 0, 1, 2, 3; const Ordering order{0, 1, 2, 3};
SymbolicJunctionTree actual(SymbolicEliminationTree(simpleChain, order)); SymbolicJunctionTree actual(SymbolicEliminationTree(simpleChain, order));

View File

@ -248,7 +248,7 @@ DiscreteBayesNet::shared_ptr Scheduler::eliminate() const {
// TODO: fix this!! // TODO: fix this!!
size_t maxKey = keys().size(); size_t maxKey = keys().size();
Ordering defaultKeyOrdering; Ordering defaultKeyOrdering;
for (size_t i = 0; i < maxKey; ++i) defaultKeyOrdering += Key(i); for (size_t i = 0; i < maxKey; ++i) defaultKeyOrdering.push_back(i);
DiscreteBayesNet::shared_ptr chordal = DiscreteBayesNet::shared_ptr chordal =
this->eliminateSequential(defaultKeyOrdering); this->eliminateSequential(defaultKeyOrdering);
gttoc(my_eliminate); gttoc(my_eliminate);

View File

@ -173,9 +173,7 @@ TEST(CSP, WesternUS) {
{6, 3}, {7, 2}, {8, 0}, {9, 1}, {10, 0}}; {6, 3}, {7, 2}, {8, 0}, {9, 1}, {10, 0}};
// Create ordering according to example in ND-CSP.lyx // Create ordering according to example in ND-CSP.lyx
Ordering ordering; const Ordering ordering{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
ordering += Key(0), Key(1), Key(2), Key(3), Key(4), Key(5), Key(6), Key(7),
Key(8), Key(9), Key(10);
// Solve using that ordering: // Solve using that ordering:
auto actualMPE = csp.optimize(ordering); auto actualMPE = csp.optimize(ordering);

View File

@ -34,7 +34,7 @@ TEST ( NestedDissection, oneIsland )
fg.addBearingRange(2, 1, Rot2(), 0., bearingRangeNoise); fg.addBearingRange(2, 1, Rot2(), 0., bearingRangeNoise);
fg.addPoseConstraint(1, Pose2()); fg.addPoseConstraint(1, Pose2());
Ordering ordering; ordering += x1, x2, l1; const Ordering ordering{x1, x2, l1};
int numNodeStopPartition = 1e3; int numNodeStopPartition = 1e3;
int minNodesPerMap = 1e3; int minNodesPerMap = 1e3;
@ -61,7 +61,7 @@ TEST ( NestedDissection, TwoIslands )
fg.addOdometry(3, 5, Pose2(), odoNoise); fg.addOdometry(3, 5, Pose2(), odoNoise);
fg.addPoseConstraint(1, Pose2()); fg.addPoseConstraint(1, Pose2());
fg.addPoseConstraint(4, Pose2()); fg.addPoseConstraint(4, Pose2());
Ordering ordering; ordering += x1, x2, x3, x4, x5; const Ordering ordering{x1, x2, x3, x4, x5};
int numNodeStopPartition = 2; int numNodeStopPartition = 2;
int minNodesPerMap = 1; int minNodesPerMap = 1;
@ -96,7 +96,7 @@ TEST ( NestedDissection, FourIslands )
fg.addOdometry(3, 5, Pose2(), odoNoise); fg.addOdometry(3, 5, Pose2(), odoNoise);
fg.addPoseConstraint(1, Pose2()); fg.addPoseConstraint(1, Pose2());
fg.addPoseConstraint(4, Pose2()); fg.addPoseConstraint(4, Pose2());
Ordering ordering; ordering += x1, x2, x3, x4, x5; const Ordering ordering{x1, x2, x3, x4, x5};
int numNodeStopPartition = 2; int numNodeStopPartition = 2;
int minNodesPerMap = 1; int minNodesPerMap = 1;
@ -144,7 +144,7 @@ TEST ( NestedDissection, weekLinks )
fg.addPoseConstraint(1, Pose2()); fg.addPoseConstraint(1, Pose2());
fg.addPoseConstraint(4, Pose2()); fg.addPoseConstraint(4, Pose2());
fg.addPoseConstraint(5, Pose2()); fg.addPoseConstraint(5, Pose2());
Ordering ordering; ordering += x1, x2, x3, x4, x5, l6; const Ordering ordering{x1, x2, x3, x4, x5, l6};
int numNodeStopPartition = 2; int numNodeStopPartition = 2;
int minNodesPerMap = 1; int minNodesPerMap = 1;
@ -206,7 +206,7 @@ TEST ( NestedDissection, manual_cuts )
fg.addPrior(x0, Pose2(0.1, 0, 0), priorNoise); fg.addPrior(x0, Pose2(0.1, 0, 0), priorNoise);
// generate ordering // generate ordering
Ordering ordering; ordering += x0, x1, x2, l1, l2, l3, l4, l5, l6; const Ordering ordering{x0, x1, x2, l1, l2, l3, l4, l5, l6};
// define cuts // define cuts
std::shared_ptr<Cuts> cuts(new Cuts()); std::shared_ptr<Cuts> cuts(new Cuts());
@ -301,9 +301,9 @@ TEST( NestedDissection, Graph3D) {
graph.addMeasurement(3, j, cameras[3].project(points[j-1]).expmap(measurementZeroNoise->sample()), measurementNoise); graph.addMeasurement(3, j, cameras[3].project(points[j-1]).expmap(measurementZeroNoise->sample()), measurementNoise);
// make an easy ordering // make an easy ordering
Ordering ordering; ordering += x0, x1, x2, x3; const Ordering ordering{x0, x1, x2, x3};
for (int j=1; j<=24; j++) for (int j=1; j<=24; j++)
ordering += Symbol('l', j); ordering.push_back(Symbol('l', j));
// nested dissection // nested dissection
const int numNodeStopPartition = 10; const int numNodeStopPartition = 10;

View File

@ -114,8 +114,7 @@ TEST(GaussianBayesTree, balanced_smoother_marginals) {
GaussianFactorGraph smoother = createSmoother(7); GaussianFactorGraph smoother = createSmoother(7);
// Create the Bayes tree // Create the Bayes tree
Ordering ordering; const Ordering ordering{X(1), X(3), X(5), X(7), X(2), X(6), X(4)};
ordering += X(1), X(3), X(5), X(7), X(2), X(6), X(4);
GaussianBayesTree bayesTree = *smoother.eliminateMultifrontal(ordering); GaussianBayesTree bayesTree = *smoother.eliminateMultifrontal(ordering);
VectorValues actualSolution = bayesTree.optimize(); VectorValues actualSolution = bayesTree.optimize();
@ -162,8 +161,7 @@ TEST( GaussianBayesTree, balanced_smoother_shortcuts )
GaussianFactorGraph smoother = createSmoother(7); GaussianFactorGraph smoother = createSmoother(7);
// Create the Bayes tree // Create the Bayes tree
Ordering ordering; const Ordering ordering{X(1), X(3), X(5), X(7), X(2), X(6), X(4)};
ordering += X(1),X(3),X(5),X(7),X(2),X(6),X(4);
GaussianBayesTree bayesTree = *smoother.eliminateMultifrontal(ordering); GaussianBayesTree bayesTree = *smoother.eliminateMultifrontal(ordering);
// Check the conditional P(Root|Root) // Check the conditional P(Root|Root)
@ -194,8 +192,7 @@ TEST( GaussianBayesTree, balanced_smoother_shortcuts )
//TEST( BayesTree, balanced_smoother_clique_marginals ) //TEST( BayesTree, balanced_smoother_clique_marginals )
//{ //{
// // Create smoother with 7 nodes // // Create smoother with 7 nodes
// Ordering ordering; // const Ordering ordering{X(1),X(3),X(5),X(7),X(2),X(6),X(4)};
// ordering += X(1),X(3),X(5),X(7),X(2),X(6),X(4);
// GaussianFactorGraph smoother = createSmoother(7, ordering).first; // GaussianFactorGraph smoother = createSmoother(7, ordering).first;
// //
// // Create the Bayes tree // // Create the Bayes tree
@ -223,8 +220,7 @@ TEST( GaussianBayesTree, balanced_smoother_shortcuts )
TEST( GaussianBayesTree, balanced_smoother_joint ) TEST( GaussianBayesTree, balanced_smoother_joint )
{ {
// Create smoother with 7 nodes // Create smoother with 7 nodes
Ordering ordering; const Ordering ordering{X(1), X(3), X(5), X(7), X(2), X(6), X(4)};
ordering += X(1),X(3),X(5),X(7),X(2),X(6),X(4);
GaussianFactorGraph smoother = createSmoother(7); GaussianFactorGraph smoother = createSmoother(7);
// Create the Bayes tree, expected to look like: // Create the Bayes tree, expected to look like:

View File

@ -78,8 +78,7 @@ TEST(GaussianFactorGraph, eliminateOne_x1) {
/* ************************************************************************* */ /* ************************************************************************* */
TEST(GaussianFactorGraph, eliminateOne_x2) { TEST(GaussianFactorGraph, eliminateOne_x2) {
Ordering ordering; const Ordering ordering{X(2), L(1), X(1)};
ordering += X(2), L(1), X(1);
GaussianFactorGraph fg = createGaussianFactorGraph(); GaussianFactorGraph fg = createGaussianFactorGraph();
auto actual = EliminateQR(fg, Ordering{X(2)}).first; auto actual = EliminateQR(fg, Ordering{X(2)}).first;
@ -94,8 +93,7 @@ TEST(GaussianFactorGraph, eliminateOne_x2) {
/* ************************************************************************* */ /* ************************************************************************* */
TEST(GaussianFactorGraph, eliminateOne_l1) { TEST(GaussianFactorGraph, eliminateOne_l1) {
Ordering ordering; const Ordering ordering{L(1), X(1), X(2)};
ordering += L(1), X(1), X(2);
GaussianFactorGraph fg = createGaussianFactorGraph(); GaussianFactorGraph fg = createGaussianFactorGraph();
auto actual = EliminateQR(fg, Ordering{L(1)}).first; auto actual = EliminateQR(fg, Ordering{L(1)}).first;
@ -282,8 +280,7 @@ TEST(GaussianFactorGraph, elimination) {
fg.emplace_shared<JacobianFactor>(X(2), Ap, b, sigma); fg.emplace_shared<JacobianFactor>(X(2), Ap, b, sigma);
// Eliminate // Eliminate
Ordering ordering; const Ordering ordering{X(1), X(2)};
ordering += X(1), X(2);
GaussianBayesNet bayesNet = *fg.eliminateSequential(); GaussianBayesNet bayesNet = *fg.eliminateSequential();
// Check matrix // Check matrix
@ -348,7 +345,6 @@ static SharedDiagonal model = noiseModel::Isotropic::Sigma(2,1);
/* ************************************************************************* */ /* ************************************************************************* */
TEST(GaussianFactorGraph, replace) TEST(GaussianFactorGraph, replace)
{ {
Ordering ord; ord += X(1),X(2),X(3),X(4),X(5),X(6);
SharedDiagonal noise(noiseModel::Isotropic::Sigma(3, 1.0)); SharedDiagonal noise(noiseModel::Isotropic::Sigma(3, 1.0));
GaussianFactorGraph::sharedFactor f1(new JacobianFactor( GaussianFactorGraph::sharedFactor f1(new JacobianFactor(

View File

@ -33,7 +33,7 @@ using symbol_shorthand::L;
TEST( ISAM, iSAM_smoother ) TEST( ISAM, iSAM_smoother )
{ {
Ordering ordering; Ordering ordering;
for (int t = 1; t <= 7; t++) ordering += X(t); for (int t = 1; t <= 7; t++) ordering.push_back(X(t));
// Create smoother with 7 nodes // Create smoother with 7 nodes
GaussianFactorGraph smoother = createSmoother(7); GaussianFactorGraph smoother = createSmoother(7);

View File

@ -78,20 +78,7 @@ TEST( GaussianJunctionTreeB, constructor2 ) {
SymbolicEliminationTree stree(*symbolic, ordering); SymbolicEliminationTree stree(*symbolic, ordering);
GaussianJunctionTree actual(etree); GaussianJunctionTree actual(etree);
Ordering o324; const Ordering o324{X(3), X(2), X(4)}, o56{X(5), X(6)}, o7{X(7)}, o1{X(1)};
o324 += X(3), X(2), X(4);
Ordering o56;
o56 += X(5), X(6);
Ordering o7;
o7 += X(7);
Ordering o1;
o1 += X(1);
// Can no longer test these:
// Ordering sep1;
// Ordering sep2; sep2 += X(4);
// Ordering sep3; sep3 += X(6);
// Ordering sep4; sep4 += X(2);
GaussianJunctionTree::sharedNode x324 = actual.roots().front(); GaussianJunctionTree::sharedNode x324 = actual.roots().front();
LONGS_EQUAL(2, x324->children.size()); LONGS_EQUAL(2, x324->children.size());
@ -228,8 +215,7 @@ TEST(GaussianJunctionTreeB, optimizeMultiFrontal2) {
// init.insert(X(0), Pose2()); // init.insert(X(0), Pose2());
// init.insert(X(1), Pose2(1.0, 0.0, 0.0)); // init.insert(X(1), Pose2(1.0, 0.0, 0.0));
// //
// Ordering ordering; // const Ordering ordering{X(1), X(0)};
// ordering += X(1), X(0);
// //
// GaussianFactorGraph gfg = *fg.linearize(init, ordering); // GaussianFactorGraph gfg = *fg.linearize(init, ordering);
// //

View File

@ -78,13 +78,13 @@ TEST( NonlinearFactorGraph, keys )
/* ************************************************************************* */ /* ************************************************************************* */
TEST( NonlinearFactorGraph, GET_ORDERING) TEST( NonlinearFactorGraph, GET_ORDERING)
{ {
Ordering expected; expected += L(1), X(2), X(1); // For starting with l1,x1,x2 const Ordering expected{L(1), X(2), X(1)}; // For starting with l1,x1,x2
NonlinearFactorGraph nlfg = createNonlinearFactorGraph(); NonlinearFactorGraph nlfg = createNonlinearFactorGraph();
Ordering actual = Ordering::Colamd(nlfg); Ordering actual = Ordering::Colamd(nlfg);
EXPECT(assert_equal(expected,actual)); EXPECT(assert_equal(expected,actual));
// Constrained ordering - put x2 at the end // Constrained ordering - put x2 at the end
Ordering expectedConstrained; expectedConstrained += L(1), X(1), X(2); const Ordering expectedConstrained{L(1), X(1), X(2)};
FastMap<Key, int> constraints; FastMap<Key, int> constraints;
constraints[X(2)] = 1; constraints[X(2)] = 1;
Ordering actualConstrained = Ordering::ColamdConstrained(nlfg, constraints); Ordering actualConstrained = Ordering::ColamdConstrained(nlfg, constraints);
@ -198,8 +198,7 @@ TEST(NonlinearFactorGraph, UpdateCholesky) {
EXPECT(assert_equal(expected, fg.updateCholesky(initial))); EXPECT(assert_equal(expected, fg.updateCholesky(initial)));
// solve with Ordering // solve with Ordering
Ordering ordering; const Ordering ordering{L(1), X(2), X(1)};
ordering += L(1), X(2), X(1);
EXPECT(assert_equal(expected, fg.updateCholesky(initial, ordering))); EXPECT(assert_equal(expected, fg.updateCholesky(initial, ordering)));
// solve with new method, heavily damped // solve with new method, heavily damped
@ -251,8 +250,7 @@ TEST(testNonlinearFactorGraph, eliminate) {
auto linearized = graph.linearize(values); auto linearized = graph.linearize(values);
// Eliminate // Eliminate
Ordering ordering; const Ordering ordering{11, 21, 12, 22};
ordering += 11, 21, 12, 22;
auto bn = linearized->eliminateSequential(ordering); auto bn = linearized->eliminateSequential(ordering);
EXPECT_LONGS_EQUAL(4, bn->size()); EXPECT_LONGS_EQUAL(4, bn->size());
} }

View File

@ -217,7 +217,7 @@ BOOST_CLASS_EXPORT_GUID(GenericStereoFactor3D, "gtsam::GenericStereoFactor3D")
TEST (testSerializationSLAM, smallExample_linear) { TEST (testSerializationSLAM, smallExample_linear) {
using namespace example; using namespace example;
Ordering ordering; ordering += X(1),X(2),L(1); const Ordering ordering{X(1), X(2), L(1)};
EXPECT(equalsObj(ordering)); EXPECT(equalsObj(ordering));
EXPECT(equalsXML(ordering)); EXPECT(equalsXML(ordering));
EXPECT(equalsBinary(ordering)); EXPECT(equalsBinary(ordering));

View File

@ -42,11 +42,9 @@ Symbol key(int x, int y) { return symbol_shorthand::X(1000 * x + y); }
/* ************************************************************************* */ /* ************************************************************************* */
TEST(SubgraphPreconditioner, planarOrdering) { TEST(SubgraphPreconditioner, planarOrdering) {
// Check canonical ordering // Check canonical ordering
Ordering expected, ordering = planarOrdering(3); Ordering ordering = planarOrdering(3),
expected += expected{key(3, 3), key(2, 3), key(1, 3), key(3, 2), key(2, 2),
key(3, 3), key(2, 3), key(1, 3), key(1, 2), key(3, 1), key(2, 1), key(1, 1)};
key(3, 2), key(2, 2), key(1, 2),
key(3, 1), key(2, 1), key(1, 1);
EXPECT(assert_equal(expected, ordering)); EXPECT(assert_equal(expected, ordering));
} }

View File

@ -115,8 +115,7 @@ int main()
cout << ((double)n/seconds) << " calls/second" << endl; cout << ((double)n/seconds) << " calls/second" << endl;
// time matrix_augmented // time matrix_augmented
// Ordering ordering; // const Ordering ordering{_x2_, _l1_, _x1_};
// ordering += _x2_, _l1_, _x1_;
// size_t n1 = 10000000; // size_t n1 = 10000000;
// timeLog = clock(); // timeLog = clock();
// //