diff --git a/.cproject b/.cproject index c71ec5b6e..440f9e1a6 100644 --- a/.cproject +++ b/.cproject @@ -300,6 +300,7 @@ make + install true true @@ -307,6 +308,7 @@ make + check true true @@ -322,6 +324,7 @@ make + testSimpleCamera.run true true @@ -337,7 +340,6 @@ make - testVSLAMFactor.run true true @@ -345,6 +347,7 @@ make + testCalibratedCamera.run true true @@ -352,7 +355,6 @@ make - testGaussianConditional.run true true @@ -360,6 +362,7 @@ make + testPose2.run true true @@ -367,6 +370,7 @@ make + testRot3.run true true @@ -374,7 +378,6 @@ make - testNonlinearOptimizer.run true true @@ -382,6 +385,7 @@ make + testGaussianFactor.run true true @@ -389,6 +393,7 @@ make + testGaussianFactorGraph.run true true @@ -396,7 +401,6 @@ make - testNonlinearFactorGraph.run true true @@ -404,6 +408,7 @@ make + testPose3.run true true @@ -411,7 +416,6 @@ make - testVectorConfig.run true true @@ -419,7 +423,6 @@ make - testPoint2.run true true @@ -427,6 +430,7 @@ make + testNonlinearFactor.run true true @@ -434,6 +438,7 @@ make + timeGaussianFactor.run true true @@ -441,6 +446,7 @@ make + timeGaussianFactorGraph.run true true @@ -448,6 +454,7 @@ make + testGaussianBayesNet.run true true @@ -455,7 +462,6 @@ make - testBayesTree.run true false @@ -463,6 +469,7 @@ make + testSymbolicBayesNet.run true false @@ -470,7 +477,6 @@ make - testSymbolicFactorGraph.run true false @@ -478,6 +484,7 @@ make + testVector.run true true @@ -485,6 +492,7 @@ make + testMatrix.run true true @@ -492,7 +500,6 @@ make - testInference.run true true @@ -500,7 +507,6 @@ make - testVSLAMGraph.run true true @@ -508,15 +514,21 @@ make - testNonlinearEquality.run true true true + +make + +testSQP.run +true +true +true + make - install true true @@ -524,7 +536,6 @@ make - clean true true @@ -532,7 +543,6 @@ make - check true true diff --git a/cpp/Makefile.am b/cpp/Makefile.am index 85a8a8aff..63d3e291b 100644 --- a/cpp/Makefile.am +++ b/cpp/Makefile.am @@ -113,7 +113,7 @@ headers += NonlinearFactorGraph.h NonlinearFactorGraph-inl.h headers += NonlinearOptimizer.h NonlinearOptimizer-inl.h sources += NonlinearFactor.cpp sources += NonlinearEquality.h -check_PROGRAMS += testNonlinearFactor testNonlinearFactorGraph testNonlinearOptimizer testNonlinearEquality +check_PROGRAMS += testNonlinearFactor testNonlinearFactorGraph testNonlinearOptimizer testNonlinearEquality testSQP testNonlinearFactor_SOURCES = $(example) testNonlinearFactor.cpp testNonlinearFactor_LDADD = libgtsam.la testNonlinearFactorGraph_SOURCES = $(example) testNonlinearFactorGraph.cpp @@ -122,6 +122,8 @@ testNonlinearOptimizer_SOURCES = $(example) testNonlinearOptimizer.cpp testNonlinearOptimizer_LDADD = libgtsam.la testNonlinearEquality_SOURCES = testNonlinearEquality.cpp testNonlinearEquality_LDADD = libgtsam.la +testSQP_SOURCES = testSQP.cpp +testSQP_LDADD = libgtsam.la # geometry sources += Point2.cpp Pose2.cpp Point3.cpp Rot3.cpp Pose3.cpp Cal3_S2.cpp diff --git a/cpp/testSQP.cpp b/cpp/testSQP.cpp new file mode 100644 index 000000000..41e0788db --- /dev/null +++ b/cpp/testSQP.cpp @@ -0,0 +1,125 @@ +/* + * @file testSQP.cpp + * @brief demos of SQP using existing gtsam components + * @author Alex Cunningham + */ + +#include +#include +#include // for operator += +#include // for insert +#include +#include +#include +#include + +using namespace std; +using namespace gtsam; +using namespace boost::assign; + +// trick from some reading group +#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL) + +/** + * This example uses a nonlinear objective function and + * nonlinear equality constraint. The formulation is actually + * the Choleski form that creates the full Hessian explicitly, + * which should really be avoided with our QR-based machinery + */ +TEST (SQP, problem1 ) { + bool verbose = false; + // use a nonlinear function of f(x) = x^2+y^2 + // nonlinear equality constraint: g(x) = x^2-5-y=0 + // Lagrangian: f(x) + lam*g(x) + + // state structure: [x y lam] + VectorConfig init, state; + init.insert("x", Vector_(1, 1.0)); + init.insert("y", Vector_(1, 1.0)); + init.insert("lam", Vector_(1, 1.0)); + state = init; + + if (verbose) init.print("Initial State"); + + // loop until convergence + int maxIt = 50; + for (int i = 0; i