필터 지우기
필터 지우기

Fmincon finds no solution with break Points

조회 수: 2 (최근 30일)
Daniela Würmseer
Daniela Würmseer 2022년 8월 29일
댓글: Daniela Würmseer 2022년 8월 29일
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
Walter Roberson 2022년 8월 29일
https://www.mathworks.com/help/gads/globalsearch.run.html#d123e65923
-5 is time limit exceeded.

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
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)
GlobalSearch stopped because it analyzed all the trial points. All 13 local solver runs converged with a positive local solver exit flag.
x = 1×2
2.0583 2.0583
fval = 11.7735
exitflag = 1
output = struct with fields:
funcCount: 2692 localSolverTotal: 13 localSolverSuccess: 13 localSolverIncomplete: 0 localSolverNoSolution: 0 message: 'GlobalSearch stopped because it analyzed all the trial points.↵↵All 13 local solver runs converged with a positive local solver exit flag.'
x = 1×2
2.0583 2.0583
fval = 11.7735
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
Torsten
Torsten 2022년 8월 29일
편집: Torsten 2022년 8월 29일
Walter answered this as "Time limit exceeded".
And better put bounds on the variables in lb and ub instead of Aineq and bineq.
Daniela Würmseer
Daniela Würmseer 2022년 8월 29일
Thank you I tried to put bounds in my Alg where i could have. But as my Algorithmus should work for different kind of Problems i cannot put bounds here.
I even already tried with gs.MaxTime = 10 but it changes nothing.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by