From ed616a26eda086e931474bb500ad843932bd775d Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sun, 18 Oct 2009 16:49:10 +0000 Subject: [PATCH] Finally gave in and made LinearFactorSet into a vector. Pragmatism wins. --- cpp/LinearFactor.cpp | 2 +- cpp/LinearFactor.h | 5 +---- cpp/LinearFactorGraph.cpp | 4 ++-- cpp/LinearFactorGraph.h | 1 - cpp/LinearFactorSet.h | 3 ++- cpp/testLinearFactor.cpp | 20 ++++++++------------ 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/cpp/LinearFactor.cpp b/cpp/LinearFactor.cpp index 72134546d..20a3b4bd1 100644 --- a/cpp/LinearFactor.cpp +++ b/cpp/LinearFactor.cpp @@ -149,7 +149,7 @@ void MutableLinearFactor::append_factor(LinearFactor::shared_ptr f, const size_t } /* ************************************************************************* */ -MutableLinearFactor::MutableLinearFactor(const set & factors) +MutableLinearFactor::MutableLinearFactor(const vector & factors) { // Create RHS vector of the right size by adding together row counts size_t m = 0; diff --git a/cpp/LinearFactor.h b/cpp/LinearFactor.h index dcec35345..ff4f7a55e 100644 --- a/cpp/LinearFactor.h +++ b/cpp/LinearFactor.h @@ -187,13 +187,10 @@ public: /** * Constructor that combines a set of factors - * NOTE: the combined factor will be depends on a system-dependent - * ordering of the input set of factors. Do not rely on this order - * when using the function. * @param factors Set of factors to combine */ CONSTRUCTOR - MutableLinearFactor(const std::set & factors); + MutableLinearFactor(const std::vector & factors); /** Construct unary mutable factor */ CONSTRUCTOR diff --git a/cpp/LinearFactorGraph.cpp b/cpp/LinearFactorGraph.cpp index 478a122a1..94f42b20a 100644 --- a/cpp/LinearFactorGraph.cpp +++ b/cpp/LinearFactorGraph.cpp @@ -57,7 +57,7 @@ LinearFactorGraph::find_factors_and_remove(const string& key) for(iterator factor=factors_.begin(); factor!=factors_.end(); ) if ((*factor)->involves(key)) { - found.insert(*factor); + found.push_back(*factor); factor = factors_.erase(factor); } else { factor++; // important, erase will have effect of ++ @@ -219,7 +219,7 @@ pair LinearFactorGraph::matrix(const Ordering& ordering) const { // get all factors LinearFactorSet found; BOOST_FOREACH(shared_factor factor,factors_) - found.insert(factor); + found.push_back(factor); // combine them MutableLinearFactor lf(found); diff --git a/cpp/LinearFactorGraph.h b/cpp/LinearFactorGraph.h index 859d03744..36aed3251 100644 --- a/cpp/LinearFactorGraph.h +++ b/cpp/LinearFactorGraph.h @@ -15,7 +15,6 @@ #include #include "LinearFactor.h" -//#include "Ordering.h" #include "VectorConfig.h" #include "FactorGraph.h" diff --git a/cpp/LinearFactorSet.h b/cpp/LinearFactorSet.h index 30e2f0f67..4f1c0f506 100644 --- a/cpp/LinearFactorSet.h +++ b/cpp/LinearFactorSet.h @@ -14,7 +14,8 @@ namespace gtsam { class LinearFactor; - struct LinearFactorSet : std::set > { + // We use a vector not a an STL set, to get predictable ordering across platforms + struct LinearFactorSet : std::vector > { LinearFactorSet() {} }; } diff --git a/cpp/testLinearFactor.cpp b/cpp/testLinearFactor.cpp index c418b1be6..af5c3192d 100644 --- a/cpp/testLinearFactor.cpp +++ b/cpp/testLinearFactor.cpp @@ -64,19 +64,15 @@ TEST( LinearFactor, variables ) } /* ************************************************************************* */ - -// NOTE: This test fails due to order dependency in the extraction of factors -// To fix it, it will be necessary to construct the expected version -// of the combined factor taking into account the ordering in the set TEST( LinearFactor, linearFactor2 ) { // create a small linear factor graph LinearFactorGraph fg = createLinearFactorGraph(); // get two factors from it and insert the factors into a set - std::set lfg; - lfg.insert(fg[4 - 1]); - lfg.insert(fg[2 - 1]); + vector lfg; + lfg.push_back(fg[4 - 1]); + lfg.push_back(fg[2 - 1]); // combine in a factor MutableLinearFactor combined(lfg); @@ -137,11 +133,11 @@ TEST( NonlinearFactorGraph, linearFactor3){ b(0) = 5 ; b(1) = -6; LinearFactor::shared_ptr f4(new LinearFactor("x1", A11, b)); - std::set lfg; - lfg.insert(f1); - lfg.insert(f2); - lfg.insert(f3); - lfg.insert(f4); + vector lfg; + lfg.push_back(f1); + lfg.push_back(f2); + lfg.push_back(f3); + lfg.push_back(f4); MutableLinearFactor combined(lfg); Matrix A22(8,2);