Finally gave in and made LinearFactorSet into a vector. Pragmatism wins.

release/4.3a0
Frank Dellaert 2009-10-18 16:49:10 +00:00
parent 82d541f6a3
commit ed616a26ed
6 changed files with 14 additions and 21 deletions

View File

@ -149,7 +149,7 @@ void MutableLinearFactor::append_factor(LinearFactor::shared_ptr f, const size_t
}
/* ************************************************************************* */
MutableLinearFactor::MutableLinearFactor(const set<shared_ptr> & factors)
MutableLinearFactor::MutableLinearFactor(const vector<shared_ptr> & factors)
{
// Create RHS vector of the right size by adding together row counts
size_t m = 0;

View File

@ -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<shared_ptr> & factors);
MutableLinearFactor(const std::vector<shared_ptr> & factors);
/** Construct unary mutable factor */
CONSTRUCTOR

View File

@ -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<Matrix,Vector> 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);

View File

@ -15,7 +15,6 @@
#include <boost/shared_ptr.hpp>
#include "LinearFactor.h"
//#include "Ordering.h"
#include "VectorConfig.h"
#include "FactorGraph.h"

View File

@ -14,7 +14,8 @@ namespace gtsam {
class LinearFactor;
struct LinearFactorSet : std::set<boost::shared_ptr<LinearFactor> > {
// We use a vector not a an STL set, to get predictable ordering across platforms
struct LinearFactorSet : std::vector<boost::shared_ptr<LinearFactor> > {
LinearFactorSet() {}
};
}

View File

@ -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<LinearFactor::shared_ptr> lfg;
lfg.insert(fg[4 - 1]);
lfg.insert(fg[2 - 1]);
vector<LinearFactor::shared_ptr> 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<LinearFactor::shared_ptr> lfg;
lfg.insert(f1);
lfg.insert(f2);
lfg.insert(f3);
lfg.insert(f4);
vector<LinearFactor::shared_ptr> lfg;
lfg.push_back(f1);
lfg.push_back(f2);
lfg.push_back(f3);
lfg.push_back(f4);
MutableLinearFactor combined(lfg);
Matrix A22(8,2);