Expressing non-linear conditions in an NLP optimization problem

Dear Community,
I would like to solve following NLP optimization problem (for example with the fmincon function):
My objective function (to be minimized) is
f=2*x1+3*x2
where x1 and x2 are my two variables.
Furthermore:
y01=5*x1
y02=3*x2
where y01 and y02 are the initial conditions used to solve following ODE system:
dy1dl=(-a0/y2)*log((b0-c0)/(b0-(1-exp(-(a*y1^1.7+y2*y1^1.2)))))
dy2dl=d0*(e0-y2)+(-a0/y2)*log((b0-c0)/(b0-(1-exp(-(a*y1^1.7+y2*y1^1.2)))))/(1+y1)
y1 and y2 for the whole interval L are calculated by iterational solving of the ODE system using ODE45 (since the parameters a0, b0, c0, d0, e0 are different on each small interval)
Now I have the constraint
C=sum(y1)+sum(y2)<100
I am wondering how to integrate the ODE solving routine into the constraint expression and optimization solution line. I first thought having found indications in the chapter about passing extra parameters but finally I don't think it is so helpful in this case since my parameters a0, etc. are not supposed to change from one optimization to other (they just change within the interval L).
Thanks!

 Réponse acceptée

Matt J
Matt J le 24 Sep 2019
Modifié(e) : Matt J le 24 Sep 2019
You would need to use ga() for this, with the nonlinear constraints implemented in the nonlcon input argument
x = ga(fun,nvars,A,b,[],[],lb,ub,@(x)nonlcon(x,a0,b0,d0),1:2)
And yes, you would pass extra parameters to nonlcon in the way that you read. You would pass a vector of a0 values and similarly for the other parameters.
function [c,ceq]=nonlcon(x,a0,b0,d0)
%y1,y2=ode45....
c=C*sum(y1)+D*sum(y2)-100;
ceq=[];
end

5 commentaires

I want to add that I believe fmincon can be used in nearly the same way if that is the optimization algorithm desired.
Matt J
Matt J le 24 Sep 2019
Modifié(e) : Matt J le 24 Sep 2019
@Lenilein , in your previous post, you said there were integer constraints on x1 and x2. Is that no longer the case? Note that fmincon cannot handle integer constraints.
Also, fmincon requires differentiability of the constraints. I cannot tell if the constraints are differentiable - they are very complicated.
Lenilein
Lenilein le 24 Sep 2019
Modifié(e) : Lenilein le 24 Sep 2019
@ David: thank you for that input! I will try both functions.
@ Matt: you are perfectly right, I made a change compared to the previous post. My ultimate goal is to solve MINLP problem but in first step I need to learn syntax and that's a reason why I adapted my problem so that fmincon might be able to solve it.
Thank you for the tip concerning the ga() function, I didn't know a genetic algorithm function is readily available in matlab! It looks like I have a tool to solve my MINLP problem then :)
Note though, that if x1 and x2 are binary, like in your previous question, it doesn't really make sense to use an optimization algorithm at all. There are only 4 combinations of values to test.
Yes, I totally agree! But I'm actually building the model up step by step and at the end I shall have around 10 binary variables. I think that it will then be "worth" the efforts ...

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by