/** * @file timeGaussianFactorGraph.cpp * @brief Time elimination with simple Kalman Smoothing example * @author Frank Dellaert */ #include #include #include "smallExample.h" #include "Ordering.h" using namespace std; using namespace gtsam; /* ************************************************************************* */ // Create a Kalman smoother for t=1:T and optimize double timeKalmanSmoother(int T) { GaussianFactorGraph smoother = createSmoother(T); Ordering ordering; for (int t = 1; t <= T; t++) ordering.push_back(symbol('x',t)); clock_t start = clock(); smoother.optimize(ordering); clock_t end = clock (); double dif = (double)(end - start) / CLOCKS_PER_SEC; return dif; } /* ************************************************************************* */ // Create a planar factor graph and optimize double timePlanarSmoother(int N) { GaussianFactorGraph fg; VectorConfig config; boost::tie(fg,config) = planarGraph(N); Ordering ordering = fg.getOrdering(); clock_t start = clock(); fg.optimize(ordering); clock_t end = clock (); double dif = (double)(end - start) / CLOCKS_PER_SEC; return dif; } /* ************************************************************************* */ TEST(timeGaussianFactorGraph, linearTime) { int T = 1000; double time1 = timeKalmanSmoother( T); cout << time1 << endl; double time2 = timeKalmanSmoother(2*T); cout << time2 << endl; DOUBLES_EQUAL(2*time1,time2,0.1); } /* ************************************************************************* */ TEST(timeGaussianFactorGraph, planar) { // 1741: 8.12, 8.12, 8.12, 8.16, 8.14 // 1742: 5.99, 5.97, 5.97, 6.02, 5.97 int N = 30; double time = timePlanarSmoother(N); cout << time << endl; DOUBLES_EQUAL(5.97,time,0.1); } /* ************************************************************************* */ int main() { TestResult tr; TestRegistry::runAllTests(tr); return 0; } /* ************************************************************************* */