Why is fmincon not finding the right solution?
이전 댓글 표시
Hello, i have the following Problem:
min x1,x2
s.t x1,x2 >= 1
x1 mod 1 = 0 %that i have only integer solutions
x2 mod 1 = 0 %that i have only integer solutions
x1 + x2 = 4
What i want to calculate first is the utopia Point of this Problem so:
u1 = min {f1, x \in X}
u2 = min {f2, x \in X}
Thats my Code to it:
f1 =@(x) x(1);
f2= @(x) x(2);
Aneq = [0 -1;
-1 0];
bneq = [-1; -1];
Aeq = [1,1];
beq = 4;
ceq = cell(2,1);
ceq{1} = @(x) mod(x(1),1);
ceq{2} = @(x) mod(x(2),1);
function [u] = generate_Utopia_Point(f1,f2,Aneq,bneq,Aeq,beq,ceq)
nonlincon = @constr;
function [cneq,cq] = constr(x)
cneq = [];
cq = zeros(size(ceq,1),1);
for j=1:size(ceq,1)
cq(j) = ceq{j,1}(x);
end
end
x0 = [1,3] % x0 is generated by a function which just takes an efficient solution of the Problem
opts = optimoptions(@fmincon,'Algorithm','sqp', 'MaxFunctionEvaluations',300000,'FunctionTolerance', 1e-10,'ConstraintTolerance',1e-10);
problem1 = createOptimProblem('fmincon','objective',f1,'x0',x0,'Aineq',Aneq,'bineq',bneq,'Aeq',Aeq,'beq',beq,'nonlcon',nonlincon,'options',opts);
x1 = run(GlobalSearch,problem1);
u(1) = f1(x1);
problem2 = createOptimProblem('fmincon','objective',f2,'x0',x0,'Aineq',Aneq,'bineq',bneq,'Aeq',Aeq,'beq',beq,'nonlcon',nonlincon,'options',opts);
x2 = run(GlobalSearch,problem2);
u(2) = f2(x2);
disp(u);
end
Normally the solution should be x1 = (1,3) and x2 = (3,1) and therefore u = (1,1).
But if i run the code sometimes the solution is x1 = (1,3) and x2=(1,3) and therefore u = (1,3) and sometimes i get x1 = (3,1) and x2=(3,1) and therefore u = (3,1).
If i change for example x0 = [0,0] (for fmincon) the solution (x1 = (1,1) and x2=(1,1)) is not even efficient.
Does someone see a mistake in my Code?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Choose a Solver에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!