/* * @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