2009-11-29 02:35:36 +08:00
|
|
|
/**
|
|
|
|
|
* @file testOrdering.cpp
|
|
|
|
|
* @author Alex Cunningham
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <boost/assign/std/list.hpp> // for operator +=
|
|
|
|
|
#include <CppUnitLite/TestHarness.h>
|
|
|
|
|
#include "Ordering.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
using namespace gtsam;
|
|
|
|
|
using namespace boost::assign;
|
|
|
|
|
|
Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just says something like
if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
2010-01-14 06:25:03 +08:00
|
|
|
/* ************************************************************************* *
|
2010-01-07 16:00:54 +08:00
|
|
|
// x1 -> x2
|
|
|
|
|
// -> x3 -> x4
|
|
|
|
|
// -> x5
|
Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just says something like
if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
2010-01-14 06:25:03 +08:00
|
|
|
TEST ( Ordering, constructorFromTree ) {
|
2010-01-07 16:00:54 +08:00
|
|
|
map<string, string> p_map;
|
|
|
|
|
p_map.insert(make_pair("x1", "x1"));
|
|
|
|
|
p_map.insert(make_pair("x2", "x1"));
|
|
|
|
|
p_map.insert(make_pair("x3", "x1"));
|
|
|
|
|
p_map.insert(make_pair("x4", "x3"));
|
|
|
|
|
p_map.insert(make_pair("x5", "x1"));
|
|
|
|
|
|
|
|
|
|
Ordering expected;
|
|
|
|
|
expected += "x4", "x5", "x3", "x2", "x1";
|
|
|
|
|
|
|
|
|
|
Ordering actual(p_map);
|
|
|
|
|
CHECK(assert_equal(expected, actual));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-11-29 02:35:36 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
TEST ( Ordering, subtract ) {
|
|
|
|
|
Ordering init, delta;
|
|
|
|
|
init += "a", "b", "c", "d", "e";
|
|
|
|
|
CHECK(assert_equal(init.subtract(delta), init));
|
|
|
|
|
|
|
|
|
|
delta += "b";
|
|
|
|
|
Ordering expected1;
|
|
|
|
|
expected1 += "a", "c", "d", "e";
|
|
|
|
|
CHECK(assert_equal(init.subtract(delta), expected1));
|
|
|
|
|
|
|
|
|
|
delta += "e";
|
|
|
|
|
Ordering expected2;
|
|
|
|
|
expected2 += "a", "c", "d";
|
|
|
|
|
CHECK(assert_equal(init.subtract(delta), expected2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
|
int main() { TestResult tr; return TestRegistry::runAllTests(tr); }
|
|
|
|
|
/* ************************************************************************* */
|