NonLinear Constraint not verified, although fmincon says it is
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi everyone,
I come to you with an constrainted optimization problem to which I cannot find a satisfying solution.
The problem consists of linear equality constraints, linear inequality constraints and nonlinear constraints. To solve this, I use fmincon and the sqp algorithm. My issue is the following : the optimization stops because the step size is too small and moreover the constraints are satisfied.
It is true that the constraints are satisfied, but only the linear ones : in fmincon nomencalture, my x_out satisfies c(x_out) > 0 ! Which is paradoxical with the definition of the nonlinear constraint c(x) <= 0. In addition, c(x_out) is bigger than my ConstraintTolerance of 10^-4.
% Linear Constraints and bounds
load('Optim_Vars.mat'); % Contains A,b_optim,Aeq,beq,ub_optim,lb_optim,targetfun
% Non Linear Constraint definition
Target_thresh = 0.4;
non_lin_buffzone = 10^-2; % A parameter to satisfy "more sharply" the condition, but bigger than the constraint tolerance,
% so that constraint_violation < buffzone => c(x) + constraint_violation <= 0
nonlcon = @(x)the_non_linear_con(x,Target_thresh,non_lin_buffzone);
function [c,ceq] = the_non_linear_con(x,threshhold,buffzone)
ceq = [];
Idx = and(x <= 0.1, x >= 0.05);
c = sum(x(Idx)) - threshhold + buffzone; % Sum of elements of x within range [0.05,0.1] has to be lower than threshhold
end
% Ignore this part as is it only suited to build a good
% initial point for a the more constrained latter optimization
options_x0 = optimoptions(@fmincon,'Algorithm','sqp','MaxFunctionEvaluations',10^5,'ConstraintTolerance',10^-8,'StepTolerance',10^-8);%'sqp','active-set'
x0_g = fmincon(funobj,x0,A(1:end-1,:),b_optim(1:end-1,:),Aeq,beq,lb,ub,nonlcon,options_x0);
% Optimization - Core problem
@(x) 0.5*x'*H*x + x'*f; % Some target function
options = optimoptions(@fmincon,'Algorithm','sqp','MaxFunctionEvaluations',10^5,'ConstraintTolerance',10^-4,...
'StepTolerance',10^-10);
[x_out,fval,exitflag,output] = fmincon(funobj,x0_g,A,b_optim,Aeq,beq,lb_optim,ub_optim,nonlcon,options);
After the optimization, I check the constraints. As you can see, Ax <= b is satisfied, Aeq * x = beq is satisfied, but c(x) <= 0 is not satisfied :
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than
the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
K>> [c,~] = nonlcon(x_out)
c =
0.0729
K>> sum(A*x_out > b_optim)
ans =
0
K>> sum(Aeq *x_out ~= beq)
ans =
0
Could someone enlighten me please ? I would like the optimization to stop if all constraints are satisfied, including the non linear one...
댓글 수: 0
채택된 답변
Matt J
2023년 12월 22일
편집: Matt J
2023년 12월 22일
For the sqp algorithm, the ConstraintTolerance is relative, not absolute. See the table here,
댓글 수: 8
Bruno Luong
2023년 12월 22일
Found an old message from @Alan Weiss here on relative constraint tolerance. His answer is a little bit evasive at the time.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!