solvers/exacthessian.py

This example looks at a use of an exact hessian for the NLP solvers

View output (PDF) | source (python)

See also
Function object.
Definition: function.hpp:60
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 from casadi import *
28 from numpy import *
29 import casadi as c
30 
31 
32 
33 x=SX.sym('x')
34 y=SX.sym('y')
35 obj = (1-x)**2+100*(y-x**2)**2
36 constr = x**2+y**2
37 nlp={'x':vertcat(x,y), 'f':obj, 'g':constr}
38 
39 
40 
41 solver = nlpsol('solver', 'ipopt', nlp)
42 sol = solver(lbx=-10, ubx=10, lbg=0, ubg=1)
43 print('Optimal solution (exact Hessian): %s' % sol['x'])
44 
45 
46 
47 solver = nlpsol('solver', 'ipopt', nlp, {'ipopt.hessian_approximation':'limited-memory'})
48 sol = solver(lbx=-10, ubx=10, lbg=0, ubg=1)
49 print('Optimal solution (BFGS): %s' % sol['x'])
CASADI_EXPORT Function nlpsol(const std::string &name, const std::string &solver, const SXDict &nlp, const Dict &opts=Dict())