write Nonlinear constraints for fmincon with condition
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
how to write a constraint for x = [x1 x2 x3 x4 x5 x6] that is condintional, the constraint is active when the if statment is true. the following if function clarify what i mean
lb = zeros(1,6);
ub = ones(1,6);
if P-prop < 0.25 * mcr
x = 0;
end
P_Prop is inpt and knows value
mcr is input for fmincon,but at the same time, it is output of a parent optimization process that is defined by ga algorithm.
1 commentaire
Alan Weiss
le 5 Oct 2020
Sorry, I do not understand your question. You can write any sort of code to calculate an objective function or nonlinear constraint function. Is your question how to pass extra parameters? This documentation answers that question.
Alan Weiss
MATLAB mathematical toolbox documentation
Réponses (1)
Matt J
le 5 Oct 2020
Modifié(e) : Matt J
le 5 Oct 2020
It is not clear from your description whether mcr is itself a function of x. If not, then mcr can be treated as a constant , just like P_prop. You would simply check if P_prop < 0.25 * mcr and if it is, you can conclude that x=0 without ever needing to run an optimization.
On the other hand, if mcr is in fact a function mcr(x), the way you would deal with this is to check if you can rule out x=0 as the optimal solution. To do that, you first evaluate your objective f(x) at x=0, and verify that x=0 satisfies your other constraints. Then, you should solve subject to the nonlinear constraint mcr(x)<=P_prop/0.25, which is the complementary region where x does not have to be zero. You would compare the optimal f() in the complementary region to f(0) to see where the better solution lies.
function main
P_Prop=... %known value
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,@nonlcon)
function [c,ceq]=nonlcon(x)
ceq=[];
c=mcr(x)-P_prop/0.25;
end
end
What you need to keep in mind, though, is that mcr(x) is assumed by fmincon to be a differentiable function of x, which it probably is not since you say that it is the output of another optimization step. Therefore, it may be best just to do the whole optimization in ga(), since ga() does not require differentiable objectives or constraints.
0 commentaires
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!