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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!