"Failure in initial objective function evaluation"
8 ビュー (過去 30 日間)
古いコメントを表示
Hello everybody,
I'm trying to set up a optimization. As a function for the optimization I want to use a Class I wrote with a bunch of calculations. The class itself is working as it should. But when I try to run the fmincon solver I get an error warning: "Failure in initial objective function evaluation. FMINCON cannot continue"
I think I'm calling the method from the Class in the wrong way, wherever my attempts to change the way I call it didn't work either. Has anybody some advice?
%Instanz erstellen
myHoltropObject = Holtrop_R_T(12.86, 900);
x0 = [50 12 3.2 -4.5];
lb = [40 10 3 -5];
ub = [60 15 5 5];
gs = GlobalSearch;
options = optimoptions('fmincon','Algorithm', 'interior-point',...
'UseParallel',true, 'Display','off','MaxFunctionEvaluations',6000, 'TolCon', 1e-4, 'TolFun', 1e-4);
objectiveA = @(in) calcRT(in);
constraintA = @(in) RT_equal84(in, calcRT);
problem = createOptimProblem('fmincon', ...
'objective',objectiveA, ...
'x0',x0, ...
'lb',lb, ...
'ub',ub, ...
'nonlcon',constraintA, ...
'options',options)
% Run optim search
%[resultVector,~,exitFlag,~,~] = run(gs,problem); % this is for global optimization
[resultVector,~,exitFlag,~,~,~,~] = fmincon(problem) % this is for local search of optimum
% ERROR:
problem =
objective: @(in)calcRT(in)
x0: [50 12 3.2000 -4.5000]
Aineq: []
bineq: []
Aeq: []
beq: []
lb: [40 10 3 -5]
ub: [60 15 5 5]
nonlcon: @(in)RT_equal84(in,calcRT)
solver: 'fmincon'
options: [1×1 optim.options.Fmincon]
Unable to resolve the name myHoltropObject.getR_T.
Error in User>calcRT (line 31)
RT = myHoltropObject.getR_T([Lwl B T lcb]);
Error in User (line 10)
objectiveA = @(in) calcRT(in);
Error in fmincon (line 552)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
%
%Ergebnisausgabe
fprintf('Optimale Abmessungen: \nLänge: %5.3f \nBreite: %5.3f \nTiefgang: %5.3f \nlcb: %5.3f \n',resultVector(1), resultVector(2), resultVector(3), resultVector(4));
%Objective function
function RT = calcRT(in)
Lwl = in(1);
B = in(2);
T = in(3);
lcb = in(4);
RT = myHoltropObject.getR_T([Lwl B T lcb]);
end
%Constraint function
function [c, ceq] = RT_equal84(in)
RT = calcRT(in);
ceq = RT-616;
c = [];
end
0 件のコメント
採用された回答
Geoff Hayes
2020 年 4 月 7 日
Leon - where have you defined your objective and constraint functions relative to the "main" code (i.e. that code where you create myHoltropObject, set up the optimization problem, etc.)? Are they in separate m-files? Is your main code a script?
The error message is suggesting that when the objective function is called (or even the constraint function since it calls the ojective function too), that the myHoltropObject.getR_T is unknown. If these two functions are defined in separate m-files, then they won't "know" about this object. If this is the case, then I recommend that you put your main code in a function and then nest the constraint and objective functions so that they have access to the variables defined in the parent/main function. Perhaps something like
function myMainFunction
myHoltropObject = Holtrop_R_T(12.86, 900);
x0 = [50 12 3.2 -4.5];
lb = [40 10 3 -5];
ub = [60 15 5 5];
gs = GlobalSearch;
options = optimoptions('fmincon','Algorithm', 'interior-point',...
'UseParallel',true, 'Display','off','MaxFunctionEvaluations',6000, 'TolCon', 1e-4, 'TolFun', 1e-4);
objectiveA = @(in) calcRT(in);
constraintA = @(in) RT_equal84(in, calcRT);
problem = createOptimProblem('fmincon', ...
'objective',objectiveA, ...
'x0',x0, ...
'lb',lb, ...
'ub',ub, ...
'nonlcon',constraintA, ...
'options',options)
% Run optim search
%[resultVector,~,exitFlag,~,~] = run(gs,problem); % this is for global optimization
[resultVector,~,exitFlag,~,~,~,~] = fmincon(problem) % this is for local search of optimum
% Objective function
function RT = calcRT(in)
Lwl = in(1);
B = in(2);
T = in(3);
lcb = in(4);
RT = myHoltropObject.getR_T([Lwl B T lcb]);
end
%Constraint function
function [c, ceq] = RT_equal84(in)
RT = calcRT(in);
ceq = RT-616;
c = [];
end
end
where the above code is saved to a file named myMainFunction.m. This may help. Please see nested functions for more information.
11 件のコメント
Torsten
2020 年 4 月 8 日
The error message from above stems from this error. So what is the error message now after correction ?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surrogate Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!