Replies: 1 comment
-
Hi @HariP19 @se-hwan My qp solver looks like this (penalty-based like yours) def create_qp_solver_function(num_z:int, num_eq:int, num_ineq:int):
"""
casadi funcion arguments:
H: torch.Tensor of shape (nz, nz)
g: torch.Tensor of shape (nz, 1)
A: torch.Tensor of shape (neq, nz)
b: torch.Tensor of shape (neq, 1)
G: torch.Tensor of shape (nineq, nz)
h: torch.Tensor of shape (nineq, 1)
solve
min_z 1/2 z^T H z + g^T
s.t.
Az = b
Gz <= h
Move inequality constraint to objective function using penalty method
min _z, lambda L = 1/2 z^T H z + g^T z + rho/2 (max(0, Gz - h))^2
s.t.
Az = b
Use augmented lagrangian and construct KKT matrix, then solve linear problem.
L = 1/2 z^T H z + g^T z + rho/2 (max(0, Gz - h))^2 + lambda^T (Az - b)
KKT condition
H z + g + A^T lambda + G^T mu + rho * G^T (Gz-h) = 0 (stationarity)
Az -b = 0 (primal feasibility)
Above KKT condition reduces problem to linear problem
Px= q
P =
[H+rho*G^TG, A^T;
A, 0]
q = [-g+rho*G^Th; b]
"""
# define input qp matrices
H = casadi.SX.sym('H', num_z, num_z)
g = casadi.SX.sym('g', num_z)
A = casadi.SX.sym('A', num_eq, num_z)
b = casadi.SX.sym('b', num_eq)
G = casadi.SX.sym('G', num_ineq, num_z)
h = casadi.SX.sym('h', num_ineq)
rho = casadi.SX.sym('rho', 1)
# construct KKT matrix
P1 = casadi.horzcat(H + rho*G.T @ G, A.T)
P2 = casadi.horzcat(A, casadi.SX.zeros(num_eq, num_eq))
P = casadi.vertcat(P1, P2)
q = casadi.vertcat(-g + rho*G.T @ h, b)
# solve KKT system Px = q
res = casadi.solve(P, q)
z_prime = res[:num_z]
# multiplier = res[num_z:]
# create function
qp_solver = casadi.Function('qp_solver', [H, g, A, b, G, h, rho], [z_prime])
return qp_solver |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! First off, thank you for developing and sharing Cusadi. I've been looking for something like this my work. I'm currently trying to implement a parallel QP solver for a MPC application. I read through your paper tried recreating the Pentaly QP solver that you've discussed in the paper I had a few questions after reading your implementation.
Here's the Pseudo code of the Penalty QP solver that I implemented.
The above code works as expected and I'm seeing very good results when I benchmarked the parallel QP against other QP solvers sequentially solving multiple QP problems (decision variables 16, inequality constraints 32). However I have a few questions before I can proceed further and I was hoping you can answer them.
Questions:
run_codegen.py
is taking very long time. Can I check if you encountered this problem for the humanoid SQP solver? Are there any strategies or optimizations within Cusadi to solve this long compilation time for large problems?I greatly appreciate any insights or guidance you can provide. Thanks again for your work!
Beta Was this translation helpful? Give feedback.
All reactions