Issues in the constraint functions of the Optimization Problem solving
4 次查看(过去 30 天)
显示 更早的评论
I want to add more than two constraints which are linear, nonlinear and with both equality and inequality signs. As per the MATLAB documentation the examples shown are mostly of same variables which are written as array Examples.
I am using the following shown constraint for the optimisation. The constraint function is named as "area", this same function is called for the 'nonlcon' (default function for constraints).
#1 The equations commented are also to be considered as Constraints for the Optimisation. Do MATLAB optimisation considers this kind of constraint equations?
#2 How to check whether all constraints are satisfied.
function [c,ceq]= area(x0)
M=5;
x0=[5,8];
M2=m(M,x0(1));
M3=m(M2,x0(2));
M4=m(M3,(x0(1)+x0(2)));
beta1=b(M,(x0(1)));
beta2=b(M2,(x0(2)));
beta3=b(M3,((x0(1)+x0(2))));
% M*sin(beta1)==M2*sin(beta2) & M2*sin(beta2)==M3*sin(beta3)
% (M4/M) <= 0.38
% beta1,beta2,beta3 < 62 degrees (This can be written in terms of Thetas)
% Some more constraints will be added
c=[];
ceq = log(2.4/((2.8*M*(sin(beta1)^2))-0.4)) + log(2.4/((2.8*M2*(sin(beta2)^2))-0.4)) + log(P(x0))
end
Below code shows the use of constraint function 'area' in the optimisation algorithm as "nonlcon".
%Initial Condition
% x0=[5,5] ;
% Lower bounds
lb=[1,1];
% Upper Bounds
ub=[30,40];
%constraint
nonlcon=@area
opts = optimoptions('fmincon','PlotFcn',["optimplotx","optimplotfunccount","optimplotfvalconstr","optimplotfval"],'Display','iter')
opts1 = optimoptions(opts,'MaxIterations',50,'StepTolerance',1e-9,'ConstraintTolerance',1e-9)
[x,fval,exitflag,output,lambda,grad,hessian]= fmincon(@f,x0,[],[],[],[],lb,ub,nonlcon,opts1)
The optimisation is stopped between saying the below shown statement and then after enabling Feasibility Mode also the error is shown which is also mentioned in the end.
Converged to an infeasible point.
fmincon stopped because the size of the current step is less than
the value of the step size tolerance but constraints are not
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
Consider enabling the interior point method feasibility mode.
%Initial Condition
x0=[5,5] ;
% Lower bounds
lb=[1,1];
% Upper Bounds
ub=[30,40];
%constraint
nonlcon=@area
opts = optimoptions('fmincon','PlotFcn',["optimplotx","optimplotfunccount","optimplotfvalconstr","optimplotfval"],'Display','iter', ...
'Algorithm','interior-point','EnableFeasibilityMode',true)
opts1 = optimoptions(opts,'MaxIterations',50,'StepTolerance',1e-9,'ConstraintTolerance',1e-9); % Recommended
[x,fval,exitflag,output,lambda,grad,hessian]= fmincon(@f,x0,[],[],[],[],lb,ub,nonlcon,opts1);
Converged to an infeasible point.
fmincon stopped because it is unable to find a point locally that satisfies
the constraints within the value of the constraint tolerance.
<stopping criteria details>
Even after changing the Constraint Tolerance it is not helping. Tried in the range 1e-9 to 1e-3
Thank you!
回答(2 个)
Sulaymon Eshkabilov
2023-1-31
编辑:Sulaymon Eshkabilov
2023-1-31
There should be elementwise operations in ceq formulation if M2, beta1, beta2 and P are vectors.
0 个评论
Matt J
2023-1-31
编辑:Matt J
2023-1-31
function [c,ceq]= area(x0)
M=5;
% x0=[5,8];
M2=m(M,x0(1));
M3=m(M2,x0(2));
M4=m(M3,(x0(1)+x0(2)));
beta1=b(M,(x0(1)))*180/pi;
beta2=b(M2,(x0(2)))*180/pi;
beta3=b(M3,((x0(1)+x0(2))))*180/pi;
c(1)=M4-0.38*M;
c(2:4)=[beta1,beta2,beta3]-62;
ceq(1) = log(2.4/((2.8*M*(sin(beta1)^2))-0.4)) + log(2.4/((2.8*M2*(sin(beta2)^2))-0.4)) + log(P(x0));
ceq(2) = M*sin(beta1)-M2*sin(beta2) ;
ceq(3) = M2*sin(beta2)-M3*sin(beta3) ;
end
10 个评论
Matt J
2023-2-2
@Vivek I think you need to consider the possibility that your constraints might truly be infeasible. First, however, you should plot the constraint functions over the bounded region lb<=x<=ub and see if they are simultaneously satisfied anywhere. Because you only have two unknowns, this should be tractable. If you discover a region where they are satisfied, you should choose your initial guess x0 to lie in/near that region.
Torsten
2023-2-2
编辑:Torsten
2023-2-2
Using exponential function will change the range of all numbers and it cant be used in further calculations.
Taking the exponential of a constraint does not change anything in the range of the parameters.
It doesn't matter whether you set
log(x)-2 = 0
or
exp(log(x)-2) = exp(0)
as a constraint.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!