A sparse MPC solver for walking motion generation.
ip_chol_solve.cpp
Go to the documentation of this file.
1 
9 /****************************************
10  * INCLUDES
11  ****************************************/
12 
13 #include "ip_chol_solve.h"
14 
15 
16 /****************************************
17  * FUNCTIONS
18  ****************************************/
19 namespace IP
20 {
21  //==============================================
22  // constructors / destructors
23 
29  chol_solve::chol_solve (const int N) : ecL(N)
30  {
31  w = new double[N*SMPC_NUM_STATE_VAR];
32  }
33 
34 
36  {
37  if (w != NULL)
38  delete w;
39  }
40  //==============================================
41 
42 
53  const problem_parameters& ppar,
54  const double *i2hess_grad,
55  const double *i2hess,
56  const double *x,
57  double *dx)
58  {
59  double *s_w = w;
60  int i,j;
61 
62 
63  // generate L
64  ecL.form (ppar, i2hess);
65 
66  // obtain s = E * x;
67  E.form_Ex (ppar, i2hess_grad, s_w);
68 
69  // obtain w
70  ecL.solve_forward(ppar.N, s_w);
71  ecL.solve_backward(ppar.N, s_w);
72 
73  // E' * w
74  E.form_ETx (ppar, s_w, dx);
75 
76 
77  // dx = -iH*(grad + E'*w)
78  //
79  // dx -( -i2hess_grad + inv(H) * dx )
80  const double i2H[3] = {ppar.i2Q[1], ppar.i2Q[2], ppar.i2P};
81  for (i = 0, j = 0; i < ppar.N*2; i += 2, j += SMPC_NUM_STATE_VAR)
82  {
83  // dx for state variables
84  dx[j] = i2hess_grad[j] - i2hess[i] * dx[j];
85  dx[j+1] = i2hess_grad[j+1] - i2H[0] * dx[j+1];
86  dx[j+2] = i2hess_grad[j+2] - i2H[1] * dx[j+2];
87  dx[j+3] = i2hess_grad[j+3] - i2hess[i+1] * dx[j+3];
88  dx[j+4] = i2hess_grad[j+4] - i2H[0] * dx[j+4];
89  dx[j+5] = i2hess_grad[j+5] - i2H[1] * dx[j+5];
90  }
91  for (i = ppar.N*SMPC_NUM_STATE_VAR; i < ppar.N*SMPC_NUM_VAR; i += 2)
92  {
93  // dx for control variables
94  dx[i] = i2hess_grad[i] - i2H[2] * dx[i];
95  dx[i+1] = i2hess_grad[i+1] - i2H[2] * dx[i+1];
96  }
97  }
98 }
#define SMPC_NUM_STATE_VAR
Number of state variables.
Definition: smpc_solver.h:24
A set of problem parameters.
double * w
Lagrange multipliers.
Definition: ip_chol_solve.h:52
#define SMPC_NUM_VAR
Total number of variables.
Definition: smpc_solver.h:28
void solve_backward(const int, double *)
Solve system ecL' * x = b using backward substitution.
matrix_ecL ecL
L for equality constraints.
Definition: ip_chol_solve.h:49
matrix_E E
matrix of equality constraints
Definition: ip_chol_solve.h:46
void form_Ex(const problem_parameters &, const double *, double *)
Forms E*x.
Definition: ip_matrix_E.cpp:30
chol_solve(const int)
Constructor.
void form(const problem_parameters &, const double *)
Builds matrix L.
void form_ETx(const problem_parameters &, const double *, double *)
Forms E' * x.
Definition: ip_matrix_E.cpp:83
void solve_forward(const int, double *)
Solve system ecL * x = b using forward substitution.
void solve(const problem_parameters &, const double *, const double *, const double *, double *)
Determines feasible descent direction.