Why is fmincon not finding the right solution?

2 ビュー (過去 30 日間)
Daniela Würmseer
Daniela Würmseer 2022 年 8 月 22 日
回答済み: Alan Weiss 2022 年 8 月 22 日
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?

採用された回答

Alan Weiss
Alan Weiss 2022 年 8 月 22 日
Your mistake is trying to use fmincon to solve a problem with integer constraints. fmincon does not apply to this type of problem. Even if you manage to get fmincon not to throw an error, it is never going to do anything useful for this type of problem.
The only three solvers that handle integer constraints are intlinprog, which requires a linear objective function and linear constraints, and ga and surrogateopt, which are part of Global Optimization Toolbox, and allow nonlinear objectives and constraints.
Alan Weiss
MATLAB mathematical toolbox documentation

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by