| 1 | /* ---------------------------------------------------------------------------- |
|---|---|
| 2 | |
| 3 | * GTSAM Copyright 2010, Georgia Tech Research Corporation, |
| 4 | * Atlanta, Georgia 30332-0415 |
| 5 | * All Rights Reserved |
| 6 | * Authors: Frank Dellaert, et al. (see THANKS for the full author list) |
| 7 | |
| 8 | * See LICENSE for the license information |
| 9 | |
| 10 | * -------------------------------------------------------------------------- */ |
| 11 | |
| 12 | /** |
| 13 | * @file QPSolver.h |
| 14 | * @brief Policy of ActiveSetSolver to solve Quadratic Programming Problems |
| 15 | * @author Duy Nguyen Ta |
| 16 | * @author Ivan Dario Jimenez |
| 17 | * @date 6/16/16 |
| 18 | */ |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include <gtsam_unstable/linear/QP.h> |
| 23 | #include <gtsam_unstable/linear/ActiveSetSolver.h> |
| 24 | #include <gtsam_unstable/linear/QPInitSolver.h> |
| 25 | #include <limits> |
| 26 | #include <algorithm> |
| 27 | |
| 28 | namespace gtsam { |
| 29 | |
| 30 | /// Policy for ActivetSetSolver to solve Linear Programming \sa QP problems |
| 31 | struct QPPolicy { |
| 32 | /// Maximum alpha for line search x'=xk + alpha*p, where p is the cost gradient |
| 33 | /// For QP, maxAlpha = 1 is the minimum point of the quadratic cost |
| 34 | static constexpr double maxAlpha = 1.0; |
| 35 | |
| 36 | /// Simply the cost of the QP problem |
| 37 | static const GaussianFactorGraph buildCostFunction(const QP& qp, |
| 38 | const VectorValues& xk = VectorValues()) { |
| 39 | GaussianFactorGraph no_constant_factor; |
| 40 | for (auto factor : qp.cost) { |
| 41 | HessianFactor hf = static_cast<HessianFactor>(*factor); |
| 42 | no_constant_factor.push_back(factor: hf); |
| 43 | } |
| 44 | return no_constant_factor; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | using QPSolver = ActiveSetSolver<QP, QPPolicy, QPInitSolver>; |
| 49 | |
| 50 | } |
| 51 |