发布网友 发布时间:2022-04-22 14:16
共1个回答
热心网友 时间:2023-08-03 14:24
创建output function
%%% 代码
% state.Generation 当前代数
% state.Score 种群的目标函数值
function [state, options,optchanged] = outfun(options,state,flag)
optchanged = false;
switch flag
case 'init'
disp('Starting the algorithm');
case {'iter','interrupt'}
plot(state.Generation,min(state.Score(:,1)),'.');
hold on;
disp('Iterating ...');
disp(state.Generation);
case 'done'
disp('Performing final task');
end
%%%
创建options
在optimset中加入'OutputFcn', @outfun
%%%
options = optimset('OutputFcn', @outfun);
%%%
运行程序
[x,fval,flag,output,population] = gamultiobj(@objfun,nvars,...
[],[],[],[],lb,ub,options);