Opti constraints vs bounds

1,779 views
Skip to first unread message

tom van wouwe

unread,
Oct 23, 2018, 4:16:53 AM10/23/18
to CasADi
Hi,

When using the Opti syntax we can bound the variables of an optimization using the syntax Opti.subject_to( -1 < x < 1).
However, it seems that ipopt interprets these bounds as inequality constraints. 
Is there a way to impose real bounds on the variables? For feasibility the inequality constraints are equal to the bounds, but during iterations there is a difference: 
e.g.: ipopt does not violate bounds, but does violate constraints. This appears to impact the convergence rate.

Regards
Tom

Joris Gillis

unread,
Oct 29, 2018, 3:49:41 PM10/29/18
to CasADi
Dear Tom,

This is a the moment not supported, but it makes sense to add it for next release.
I haven't made up my mind if it's best to have it explicitly done by the user, or to detect it from the problem structure..

For reference, I'm linking to some unpolished code that does an automatic detection. Perhaps you can already improve your results with it?


Best,
  Joris

R Sandeep kumar

unread,
Oct 30, 2018, 7:00:23 AM10/30/18
to Joris Gillis, casadi...@googlegroups.com
I am also facing similar issues but not sure what exactly is happening. I'll attach few of the screenshots. Most of the time ipopt stops with message as infeasible problem detected (Screenshots attached). I have not been able to solve this issue in a long time.The violations also are small here. Any help on this would be appreciated.
Regards 
R Sandeep Kumar
AE17S017
Research Scholar
Department of Aerospace Engineering IIT Madras
Chennai - 600036


--
Sent from CasADi's user forum at http://forum.casadi.org.
---
You received this message because you are subscribed to the Google Groups "CasADi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to casadi-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/casadi-users/6265ea16-39e8-46e4-bfcb-373419d22841%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ipopt
infeasibilities

Joris Gillis

unread,
Nov 1, 2018, 2:35:48 PM11/1/18
to CasADi
The infeasibilities shown are marginal; better filter them with a certain tolerance to see where the problem really is:
e.g.
opti.debug.show_infeasibilities(1e-10)
To unsubscribe from this group and stop receiving emails from it, send an email to casadi-users+unsubscribe@googlegroups.com.

tom van wouwe

unread,
Nov 7, 2018, 10:52:27 AM11/7/18
to CasADi
Thanks, this works fine.

Op maandag 29 oktober 2018 20:49:41 UTC+1 schreef Joris Gillis:

zhangsh...@gmail.com

unread,
May 1, 2019, 12:10:01 AM5/1/19
to CasADi
Hi Joris,

I just started using Casadi Opti interface to Ipopt from C++ and I noticed this issue: if we set variable bounds as inequality constraints, then the solver (Ipopt) reports infeasibility more often than expected. Is this issue solved in the latest release? If not, can we do anything to avoid this issue for now? Thanks for any help.

Best,
Shixuan

Antoine Falisse

unread,
Jan 20, 2020, 5:16:35 AM1/20/20
to CasADi
Hi Joris,

I am trying to convert the MATLAB code you shared above for automatic detection to Python:

CasADi reports this error when running my problem: CasADi -  WARNING("solver:nlp_grad_f failed: Inf detected for output grad_f_x, at (row 0, col 0).")

I am quite surprised cause when I run the following test, I do not get any Inf and actually get the same results as in my reference MATLAB code:
eval_Obj_grad = ca.Function('eval_Obj', [opti.x], [ca.jacobian(opti.f,opti.x)])
eval_Obj_grad_w0 = eval_Obj_grad(guess).full()

Note that when running my code with opti.solve() all is fine (but my goal here is to convert constraints into bounds).

Maybe CasADi expects something different when using Python? I am a newbie to Python so there might be an error in my code too.

Thanks very much in advance,
Best,

Antoine

Charles Khazoom

unread,
Jan 27, 2021, 9:39:16 AM1/27/21
to CasADi
Hi Antoine, have you been able to make automatic detection of bound variable work ? For me, this does not work in Matlab (https://gist.github.com/jgillis/c0517a3f51e09e3a7292e4c5814f3808), some NanS appear in lbx in the end, coming from the 0/0 in (lbg(find(is_simple))-f1)./abs(f2). Did you run is similar issue ? I did find https://github.com/casadi/casadi/blob/master/casadi/core/nlp_tools.cpp that runs fine, but I am unsure if it does exactly what I need.


Charles

Joris Gillis

unread,
Feb 6, 2021, 5:42:24 PM2/6/21
to CasADi
Dear Charles,

NaN would mean that you have a constraint not dependent on decision variables I think.
Could you eliminate that one?

If it's something else, do post a failing example.

Best regards,
  Joris

Charles Khazoom

unread,
Feb 7, 2021, 9:55:21 AM2/7/21
to CasADi
Hi Joris,

I never solved the NaN problem using this example script  : https://gist.github.com/jgillis/c0517a3f51e09e3a7292e4c5814f3808

but i was able to use the function casadi.detect_simple_bounds()  in Matlab (from https://github.com/casadi/casadi/blob/master/casadi/core/nlp_tools.cpp).  It seems to work very well.

see example below  : 

% detect simple bounds
[not_simple_indx,lbx,ubx,lam_f,lam_b] = casadi.detect_simple_bounds(opti.x,opti.p,opti.g,opti.lbg,opti.ubg);  % https://github.com/casadi/casadi/blob/master/casadi/core/nlp_tools.cpp 
not_simple_indx = not_simple_indx+1; % +1 for cpp to matlab indexing

% generate solver object with simple bounds removed from path constraints
solver = nlpsol('solver','ipopt',struct('x',opti.x,'p',opti.p,'f',opti.f,'g',g(not_simple_indx)),nlp_opts);

updated_bounds.lbg = lbg(not_simple_indx);
updated_bounds.ubg = ubg(not_simple_indx);
updated_bounds.lbx = lbx;
updated_bounds.ubx = ubx;

Reply all
Reply to author
Forward
0 new messages