In fmincon I set the linear constraint x1+x2+x3=12, but the sum of decision variables in the iteration result does not meet the condition
3 ビュー (過去 30 日間)
古いコメントを表示
I saved the changes of three decision variables in the iteration process. At the end of the iteration, each variable tends to be stable, but does not meet the linear constraints I set.
Here is the variable change process, the sum of varaible is 11 not 12
4 件のコメント
採用された回答
Torsten
2022 年 11 月 29 日
編集済み: Torsten
2022 年 11 月 29 日
Tighten your ConstraintTolerance, and you'll see that fmincon converges to an infeasible point for n=12 and n=13.
1st: (main.m)
clc;clear;
%% Parameter initialization
bb = [0.3 0.4 0.3]; pp = [5 5 5]; mm = [4.5 5 6]; cc = [1 5 7];nn = 13.6; TKK = [6 1 2 3]; REE = [11 13 15];
namda = [4:1:13]; %namda is the sum of decision variables
xx = [];
for i=1:length(namda)
%The optimal solution module is substituted
[x, y(i)] = M2Mallocation(bb,pp,mm,cc,namda(i),TKK,REE);
xx = [xx,sum(x)]; %Verify that the decision variable sum satisfies the linear constraint (whether the sum of x is namda)
end
figure(1);
stem(xx);
figure(2);
plot(namda,y,':r*');hold on;
2nd: (optf.m)
function f = optf(x) %Objective function
global b c p m c
f = b(1).*(1/(m(1)-x(1)) + 1/(m(2)-x(2)) + 1/(m(3)-x(3)))...
+ b(2).*(x(1).*c(1)/(m(1)-x(1)) + x(2).*c(2)/(m(2)-x(2)) + x(3).*c(3)/(m(3)-x(3)))...
+ b(3).*(x(1).*p(1)/(m(1)-x(1)) + x(2).*p(2)/(m(2)-x(2)) + x(3).*p(3)/(m(3)-x(3)));
end
3rd: (limf.m)
function [g,h] = limf(x) %Nonlinear constraints
global p m TK RE
g = [1/(m(1) - x(1))-TK(1)+TK(2);1/(m(2) - x(2))-TK(1)+TK(3);1/(m(3) - x(3))-TK(1)+TK(4);...
x(1).*p(1)/(m(1) - x(1))-RE(1);x(2).*p(2)/(m(2) - x(2))-RE(2); x(3).*p(3)/(m(3) - x(3))-RE(3)];
h = [];
end
4th:(M2Mallocation.m)
function [x,y] = M2Mallocation(b1,p1,m1,c1,n1,TK1,RE1)
global b m c n TK RE p
b = b1; p = p1; m = m1; c = c1; n = n1; TK = TK1; RE = RE1;
options = optimoptions('fmincon',...
'Algorithm','sqp',...
'StepTolerance',1e-5, 'MaxFunctionEvaluations', 1e5,'OptimalityTolerance',1e-40,...
'ConstraintTolerance',1e-3,'MaxIter', 10);
[x,y,exitflag,~] = fmincon(@optf,ones(3,1),[],[],[1,1,1],n,[],[m(1);m(2);m(3)],...
@limf, options);
end
3 件のコメント
Torsten
2022 年 11 月 29 日
I don't know what the reason is that your sum constraint cannot be satisfied.
Maybe it contradicts your constraints defined in limf - I didn't check it in detail.
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!