Fmincon finds no solution with break Points
1 次查看(过去 30 天)
显示 更早的评论
Hello, i want to solve the following Problem. I have the Problem that sometimes i get a solution to the Problem and sometimes not (for example if i set a breakpoint by cneq = f1(x)-z(1)-eps). If the Problem is not finding a solution then exitflag = -5 (does someone knows what -5 means?)
Does someone has an idea why sometimes i get a solution and sometimes not?
f1 =@(x) 10*(x(1)-2)^4+10*(x(1)-2)^3+10*(x(2)-2)^4+10*(x(2)-2)^3 + 10;
f2 =@(x) (x(1)-3)^2+(x(2)-3)^2 + 10;
Aneq = [-1 -1;
1 0;
0 1;
-1 0;
0 -1];
bneq = [-0.1; 10; 10; 0; 0];
x0 = [2.0595,2.0595];
z = [8.5913,14.6933];
eps = 1.4129;
[x,fval] = test(f1,f2,Aneq,bneq,x0,z,eps);
function [x,fval] = test(f1,f2,Aneq,bneq,x0,z,eps)
f = @(x) f2(x);
nonlincon = @constr;
function [cneq,cq] = constr(x)
cneq = f1(x)-z(1)-eps;
cq = [];
end
opts = optimoptions(@fmincon,'Algorithm','sqp', 'MaxFunctionEvaluations',3000,'FunctionTolerance', 1e-10,'ConstraintTolerance',1e-10);
problem = createOptimProblem('fmincon','objective',f,'x0',x0,'Aineq',Aneq,'bineq',bneq,'nonlcon',nonlincon,'options',opts);
gs = GlobalSearch;
gs.MaxTime = 1;
[x,fval,exitflag,output] = run(gs,problem);
if output.localSolverSuccess == 0
return;
end
end
Thank you.
1 个评论
Walter Roberson
2022-8-29
https://www.mathworks.com/help/gads/globalsearch.run.html#d123e65923
-5 is time limit exceeded.
回答(1 个)
Torsten
2022-8-29
The code below works. Do you have an example where it fails ?
f1 =@(x) 10*(x(1)-2)^4+10*(x(1)-2)^3+10*(x(2)-2)^4+10*(x(2)-2)^3 + 10;
f2 =@(x) (x(1)-3)^2+(x(2)-3)^2 + 10;
lb = [0 0];
ub = [10 10];
Aneq = [-1 -1];
bneq = [-0.1];
x0 = [2.0595,2.0595];
z = [8.5913,14.6933];
eps = 1.4129;
[x,fval] = test(f1,f2,Aneq,bneq,lb,ub,x0,z,eps)
function [x,fval] = test(f1,f2,Aneq,bneq,lb,ub,x0,z,eps)
f = @(x) f2(x);
nonlincon = @constr;
function [cneq,cq] = constr(x)
cneq = f1(x)-z(1)-eps;
cq = [];
end
opts = optimoptions(@fmincon,'Algorithm','sqp', 'MaxFunctionEvaluations',3000,'FunctionTolerance', 1e-10,'ConstraintTolerance',1e-10);
problem = createOptimProblem('fmincon','objective',f,'x0',x0,'Aineq',Aneq,'bineq',bneq,'lb',lb,'ub',ub,'nonlcon',nonlincon,'options',opts);
gs = GlobalSearch;
gs.MaxTime = 1;
[x,fval,exitflag,output] = run(gs,problem)
if output.localSolverSuccess == 0
return;
end
end
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multiobjective Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!