PANOC-ALM  quadratic-penalty
Nonconvex constrained optimization
main.py
Go to the documentation of this file.
1 import panocpy as pa
2 import numpy as np
3 import casadi as cs
4 
5 # Problem specification
6 # minimize ½ xᵀHx
7 # s.t. Ax ≤ b
8 H = np.array([[3, -1],
9  [-1, 3]])
10 A = np.array([[2, 1]])
11 b = np.array([-1])
12 
13 x = cs.SX.sym("x", 2)
14 f = cs.Function("f", [x], [0.5 * cs.dot(x, H @ x)])
15 g = cs.Function("g", [x], [A @ x])
16 problem = pa.generate_and_compile_casadi_problem(f, g, "example_name")
17 
18 # Specify the bounds
19 problem.C.lowerbound = np.full((problem.n,), -np.inf)
20 problem.C.upperbound = np.full((problem.n,), np.inf)
21 problem.D.lowerbound = np.full((problem.m,), -np.inf)
22 problem.D.upperbound = b
23 
24 # Settings for the outer augmented Lagrangian method
25 almparam = pa.ALMParams(
26  ε = 1e-8, # tolerance
27  δ = 1e-8,
28  Δ = 10, # penalty update factor
29  max_iter = 20,
30  print_interval = 1,
31 )
32 # Settings for the inner PANOC solver
33 panocparam = pa.PANOCParams(
34  max_iter = 500,
35  print_interval = 10,
36 )
37 # Settings for the L-BFGS algorithm used by PANOC
38 lbfgsparam = pa.LBFGSParams(
39  memory = 2,
40 )
41 
42 # Create an ALM solver using PANOC as inner solver
43 solver = pa.ALMSolver(
44  almparam, # Params for outer solver
45  pa.PANOCSolver(panocparam, lbfgsparam), # Inner solver
46 )
47 
48 # Initial guess
49 x = np.array([2, 2]) # decision variables
50 y = np.array([1]) # Lagrange multipliers
51 
52 # Solve the problem
53 x_sol, y_sol, stats = solver(problem, x, y)
54 
55 # Print the results
56 print(f"""
57 status: {stats['status']}
58 inner iterations: {stats['inner']['iterations']}
59 outer iterations: {stats['outer_iterations']}
60 elapsed time: {stats['elapsed_time']}
61 x = {x_sol}
62 y = {y_sol}
63 f = {problem.f(x_sol)}
64 """)
pa::ALMSolver
Augmented Lagrangian Method solver.
Definition: decl/alm.hpp:82
pa::PANOCParams
Tuning parameters for the PANOC algorithm.
Definition: inner/decl/panoc.hpp:20
pa::ALMParams
Parameters for the Augmented Lagrangian solver.
Definition: decl/alm.hpp:13
pa::LBFGSParams
Parameters for the LBFGS and SpecializedLBFGS classes.
Definition: decl/lbfgs.hpp:12
pa::PANOCSolver
PANOC solver for ALM.
Definition: inner/decl/panoc.hpp:88
main.solver
solver
Definition: main.py:43