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 Ansichten (letzte 30 Tage)
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 Kommentare
汉森 戴
汉森 戴 am 29 Nov. 2022
Bearbeitet: 汉森 戴 am 29 Nov. 2022
hope you can give me some suggestion.
here is my code(four portfolio total)
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)));
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 = [];
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',1e2,'MaxIter', 10);
[x,y] = fmincon('optf',ones(3,1),[],[],[1,1,1],n,[],[m(1);m(2);m(3)],...
'limf', options);
i make a experiment on this code,namda is the sum of decision variables(Linear constraints in fmincon),so i traverse namda then take the the sum of x in result to determine whether the x of the output is satisfied with linear constraints(x1 + x2 + x3 = namda).the result is that at beginning the linear constraint is satisfied at first, but it is not satisfied later.
theoretically, the two points should be 12 and 13.
汉森 戴
汉森 戴 am 29 Nov. 2022
but in picture(mode = 1),decision variables tend to stabilize and converge during the iteration process,no change more.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Torsten
Torsten am 29 Nov. 2022
Bearbeitet: Torsten am 29 Nov. 2022
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
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. 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. 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. 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. 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. 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. 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. 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. 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. 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.
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 Kommentare
Torsten
Torsten am 29 Nov. 2022
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by