Optimo  0.1.0
A C++ header library for optimization
 All Classes Functions Variables Pages
primal_dual_qp_api.h
1 // Copyright (C) 2014 Victor Fragoso <vfragoso@cs.ucsb.edu>
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following
13 // disclaimer in the documentation and/or other materials provided
14 // with the distribution.
15 //
16 // * Neither the name of the University of California, Santa Barbara nor the
17 // names of its contributors may be used to endorse or promote products
18 // derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 // ARE DISCLAIMED. IN NO EVENT SHALL VICTOR FRAGOSO BE LIABLE FOR ANY DIRECT,
24 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 //
31 
32 #ifndef OPTIMO_SOLVERS_PRIMAL_DUAL_QP_API_H_
33 #define OPTIMO_SOLVERS_PRIMAL_DUAL_QP_API_H_
34 
35 #include <Eigen/Core>
36 #include <glog/logging.h>
37 #include "optimo/solvers/solver.h"
38 
39 namespace optimo {
40 namespace solvers {
41 
42 using Eigen::Matrix;
43 using Eigen::Dynamic;
45 
76 template <typename Scalar, uint n, uint m, uint p>
77 class PrimalDualQP : public Solver<Scalar> {
78  public:
80  struct Params {
81  Params(void) : Q(n, n), d(n), Aeq(p, n), beq(p), Ain(m, n), bin(m) { }
82 
83  // QP objective params
84  Matrix<Scalar, Dynamic, Dynamic> Q;
85  Matrix<Scalar, Dynamic, 1> d;
86  // Constraints
87  Matrix<Scalar, Dynamic, Dynamic> Aeq;
88  Matrix<Scalar, Dynamic, 1> beq;
89  Matrix<Scalar, Dynamic, Dynamic> Ain;
90  Matrix<Scalar, Dynamic, 1> bin;
91  };
92 
93  // Constructor
94  PrimalDualQP(void) : ones_(Matrix<Scalar, Dynamic, 1>::Ones(m)) { }
95 
96  // Destructor
97  virtual ~PrimalDualQP(void) { }
98 
100  TERMINATION_TYPE
101  operator()(const PrimalDualQP<Scalar, n, m, p>::Params& params,
102  Matrix<Scalar, n, 1>* x,
103  Scalar* min_value);
104 
105  protected:
107  Scalar backTracking(const Scalar t_inv,
108  const Scalar r_norm,
109  const Matrix<Scalar, Dynamic, 1>& ynt,
110  const Matrix<Scalar, Dynamic, 1>& y,
111  const Matrix<Scalar, Dynamic, 1>& d,
112  const Matrix<Scalar, p, 1>& beq,
113  const Matrix<Scalar, m, 1>& bin,
114  Matrix<Scalar, Dynamic, 1>* y_plus,
115  Matrix<Scalar, Dynamic, 1>* r_plus,
116  bool* exit_flag);
117 
119  inline
120  void calculateResiduals(const Matrix<Scalar, Dynamic, 1>& y,
121  const Matrix<Scalar, Dynamic, 1>& d,
122  const Matrix<Scalar, Dynamic, 1>& diag,
123  const Matrix<Scalar, p, 1>& beq,
124  const Scalar t_inv,
125  Matrix<Scalar, Dynamic, 1>* r);
126 
127  private:
128  Matrix<Scalar, Dynamic, Dynamic> F_; // Matrix for KKT system
129  Matrix<Scalar, Dynamic, 1> r_; // Residual vector
130  const Matrix<Scalar, Dynamic, 1> ones_; // Helper vector
131 };
132 } // solvers
133 } // optimo
134 #endif // OPTIMO_SOLVERS_PRIMAL_DUAL_QP_API_H_
QP parameters defining the problem.
Definition: primal_dual_qp_api.h:80
Abstract class for a Solver algorithm.
Definition: solver.h:53
Matrix< Scalar, Dynamic, Dynamic > Ain
Inequality constraints.
Definition: primal_dual_qp_api.h:89
Matrix< Scalar, Dynamic, Dynamic > Aeq
Equality constraints.
Definition: primal_dual_qp_api.h:87
Matrix< Scalar, Dynamic, 1 > bin
Inequality constraints vector.
Definition: primal_dual_qp_api.h:90
Solves a constrained quadratic program (QP).
Definition: primal_dual_qp_api.h:77
Matrix< Scalar, Dynamic, 1 > beq
Equality constraints vector.
Definition: primal_dual_qp_api.h:88
Matrix< Scalar, Dynamic, 1 > d
d vector
Definition: primal_dual_qp_api.h:85
TERMINATION_TYPE operator()(const PrimalDualQP< Scalar, n, m, p >::Params &params, Matrix< Scalar, n, 1 > *x, Scalar *min_value)
Solve the QP program.
Matrix< Scalar, Dynamic, Dynamic > Q
Q matrix.
Definition: primal_dual_qp_api.h:84