fmincon is nonlinear constraints satisfied, then not satisfied when I include objective function

17 vues (au cours des 30 derniers jours)
My problem is that I'm trying to optimise something with fmincon, and it can't find a point which doesn't violate the non-linear constraints. The strange thing is that it can find such a point if the objective function is replaced with a dummy function - so I know that the non-linear constraints themselves aren't the problem. Here's the structure of my code:
%First some set up
args = MakeArgs; %These are just arguments used for the objective and constraints
bounds = MakeBounds(args);
LC = MakeLinearConstraints(args);
x01 = ones(1,args.xlength); %This and f are dummy vectors
f = zeros(1,args.xlength);
optionsLinProg = optimoptions('linprog','Display','off');
%Next check that the linear constraints are OK
[xlin , ~, linflag] = linprog(f,LC.A,LC.B,LC.Aeq,LC.Beq,bounds.LB,bounds.UB,optionsLinProg);
%Then a potential error warning
if ~(linflag==1)
error('Error. The linear constraints are badly defined')
end
fprintf('Linear Satisfied');
xlin = xlin'; %This is because fmincon deals with row vectors, wheras linprog uses column vectors.
options = optimoptions('fmincon');
options = optimoptions(options,'Algorithm','sqp');
%Next we want to test the nonlinear constraints. Again, we create a dummy function (zf) to serve as the objective.
nlconopt = @(y) nlcon(y,args,x01);
zf = @(x)0;
%
[xnlin,~,nonlinflag,~] = fmincon(zf,xlin,LC.A,LC.B,LC.Aeq,LC.Beq,bounds.LB,bounds.UB,nlconopt,options);
% Next we have a potential error warning
if ~(nonlinflag == 1)
error('Error. Non linear constraints not satisfiable here.')
end
%And a success output
fprintf('Nonlinear constraints satisfied\n')
Now, up until this point, everything seems to work fine. The "Nonlinear constraints satisfied" message outputs every time, with various choices going into the args.
But when I then replace the dummy objective zf with the real one, and use xnlin as a starting point (The following code comes directly after the code above):
objectiveopt = @(y) objective(y,args,x01);
[xnew,newval,xnewflag,out] = fmincon(objectiveopt,xnlin,LC.A,LC.B,LC.Aeq,LC.Beq,bounds.LB,bounds.UB,nlconopt,options);
if ~(xnewflag == 1)
error('Error. Non linear constraints not satisfied when taken with objective.')
end
I get my error message every time. This initially because it hits the evaluations limit - if I increase this, then it hits the iterations limit. I can play with these but what perplexes me is that it should fail to satisfy the constraints at all, or converge to an infeasible point. Since the bounds and constraints are all clearly satisfiable (as shown by the code up until this point), and since it is starting from an initial point which satisfies all of them, I can't understand how the optimisation is crashing out in this way.
I've also tried it with active-set and interior-point algorithms, to no avail.

Réponse acceptée

Matt J
Matt J le 11 Sep 2019
Modifié(e) : Matt J le 11 Sep 2019
The algorithms of fmincon try only to satisfy the nonlinear and A,b,Aeq,beq constraints at convergence. They do not pledge to satisfy those constraints at all iterations, nor to remain in the feasible region even if they are lucky enough to land there at some iteration. Even the lb,ub bounds may not be satisfied under certain non-default options settings.
Since in your case fmincon bails out early because of various tolerances and stopping limits, convergence does not take place and the nonlinear constraints never get satisfied.
  6 commentaires
Nourhan Elsayed
Nourhan Elsayed le 7 Oct 2020
Hi Matt J
i am facing a similar problem, where my priority is to extract the points that satisfy the nonlinear equality constraint. whould you please clarify what is xnlin and how to return that ?
Thank YOu
Matt J
Matt J le 7 Oct 2020
@Nourhan, xnlin was generated in the OP's code on this line
[xnlin,~,nonlinflag,~] = fmincon(zf,xlin,LC.A,LC.B,LC.Aeq,LC.Beq,bounds.LB,bounds.UB,nlconopt,options);

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