cureos / csnumerics

Portable numerical algorithms in C#
GNU Lesser General Public License v3.0
32 stars 11 forks source link

Replace Matlab's 'fmincon' on the cvnumerics #4

Closed alexbuyval closed 8 years ago

alexbuyval commented 8 years ago

Hi,

I am looking for C# library to replace 'fmincon' Matlab function in my application. It seems that COBYLA is suitable for me. However, in my 'fmicon' solution I have got equality constraints as set functions like this:

function [c, ceq] = confun(x)
global at aw;
% Nonlinear inequality constraints
c = [];
% Nonlinear equality constraints
ceq = [x(1)-(at(3)+x(4)*(1-x(5)/x(6))+x(7)*x(8)/x(6));
       x(7)-(at(5)+x(9)*(1-x(10)/x(11)));
       aw(1)+aw(2)+aw(3)+aw(4)-at(1)-at(2)-at(3)-at(4)-at(5)-at(6)-x(4)-x(9)];

Can I use COBYLA in that case? If so, is there any example how can I code it?

Best Regards, Alex

anders9ustafsson commented 8 years ago

Hi Alex,

COBYLA as such only supports inequality constraints, C(x) ≥ 0, so you will need to formulate some kind of replacement constraint(s).

Assuming a non-equivalence tolerance of ε you could for example replace C(x) = 0 with

ε - |C(x)| ≥ 0

It should be noted that COBYLA is probably not very efficient with these kinds of constraints, but maybe fmincon has difficulty with equality constraints too, or?

Best regards, Anders @ Cureos

alexbuyval commented 8 years ago

Hi Anders,

Thank you for your quick answer!

I understood this idea.

How should I code these inequality constraints? Are there any examples?

Best Regards, Alex

anders9ustafsson commented 8 years ago

Please look in the unit tests folders, you will find several usage examples there. For COBYLA, here.

alexbuyval commented 8 years ago

Thank you! I will try.