diff --git a/gtsam_unstable/linear/ActiveSetSolver-inl.h b/gtsam_unstable/linear/ActiveSetSolver-inl.h index 34d8e2b5d..18dc07aec 100644 --- a/gtsam_unstable/linear/ActiveSetSolver-inl.h +++ b/gtsam_unstable/linear/ActiveSetSolver-inl.h @@ -189,13 +189,6 @@ This::buildWorkingGraph(const InequalityFactorGraph& workingSet, return workingGraph; } -//****************************************************************************** -Template VectorValues -This::evaluateCostFunction(const VectorValues &xk) const { - GaussianFactorGraph costGraph; - costGraph.push_back(POLICY::buildCostFunction(problem_, xk)); - return costGraph.optimize(); -} //****************************************************************************** Template typename This::State This::iterate( const typename This::State& state) const { diff --git a/gtsam_unstable/linear/ActiveSetSolver.h b/gtsam_unstable/linear/ActiveSetSolver.h index 1780fdfd9..a5c60f311 100644 --- a/gtsam_unstable/linear/ActiveSetSolver.h +++ b/gtsam_unstable/linear/ActiveSetSolver.h @@ -168,8 +168,6 @@ public: /// Just for testing... const InequalityFactorGraph& workingSet, const VectorValues& xk = VectorValues()) const; - VectorValues evaluateCostFunction(const VectorValues& xk) const; - /// Iterate 1 step, return a new state with a new workingSet and values State iterate(const State& state) const; diff --git a/gtsam_unstable/linear/InequalityFactorGraph.h b/gtsam_unstable/linear/InequalityFactorGraph.h index f8aa0dc2b..c87645697 100644 --- a/gtsam_unstable/linear/InequalityFactorGraph.h +++ b/gtsam_unstable/linear/InequalityFactorGraph.h @@ -53,7 +53,7 @@ public: double error(const VectorValues& x) const { for (const sharedFactor& factor : *this) { if (factor) - if (factor->error(x) > 0) + if (factor->error(x) > 1e-7) return std::numeric_limits::infinity(); } return 0.0; diff --git a/gtsam_unstable/linear/RawQP.cpp b/gtsam_unstable/linear/RawQP.cpp index b03bcc079..ec71cae5b 100644 --- a/gtsam_unstable/linear/RawQP.cpp +++ b/gtsam_unstable/linear/RawQP.cpp @@ -216,7 +216,7 @@ QP RawQP::makeQP() { } } for (Key key1 : keys) { - gs.push_back(g[key1]); + gs.push_back(-g[key1]); } int dual_key_num = keys.size() + 1; QP madeQP; diff --git a/gtsam_unstable/linear/tests/testQPSolver.cpp b/gtsam_unstable/linear/tests/testQPSolver.cpp index 3b77e0a55..bc9dd1f98 100644 --- a/gtsam_unstable/linear/tests/testQPSolver.cpp +++ b/gtsam_unstable/linear/tests/testQPSolver.cpp @@ -217,8 +217,8 @@ pair testParser(QPSParser parser) { Key X1(Symbol('X', 1)), X2(Symbol('X', 2)); // min f(x,y) = 4 + 1.5x -y + 0.58x^2 + 2xy + 2yx + 10y^2 expectedqp.cost.push_back( - HessianFactor(X1, X2, 8.0 * I_1x1, 2.0 * I_1x1, 1.5 * kOne, 10.0 * I_1x1, - -2.0 * kOne, 4.0)); + HessianFactor(X1, X2, 8.0 * I_1x1, 2.0 * I_1x1, -1.5 * kOne, 10.0 * I_1x1, + 2.0 * kOne, 4.0)); // 2x + y >= 2 // -x + 2y <= 6 expectedqp.inequalities.push_back( @@ -263,12 +263,12 @@ TEST(QPSolver, QPExampleTest){ VectorValues expectedSolution; expectedSolution.insert(Symbol('X',1),0.7625*I_1x1); expectedSolution.insert(Symbol('X',2),0.4750*I_1x1); - VectorValues actualCost = solver.evaluateCostFunction(actualSolution); - VectorValues expectedCost = solver.evaluateCostFunction(expectedCost); - GTSAM_PRINT(actualCost); - CHECK(assert_equal(expectedCost, actualCost)) + double error_expected = problem.cost.error(expectedSolution); + double error_actual = problem.cost.error(actualSolution); CHECK(assert_equal(expectedSolution, actualSolution, 1e-7)) + CHECK(assert_equal(error_expected, error_actual)) } + /* ************************************************************************* */ // Create Matlab's test graph as in http://www.mathworks.com/help/optim/ug/quadprog.html QP createTestMatlabQPEx() {