
MATLAB相关技术,跟踪每次迭代的数值,包括目标函数值,种群等等所有优化算法的状态,平台是MATLAB2015R,其他版本类似。本处以多目标遗传算法为例,对每次迭代的种群某一个目标函数最小值与相应代数画图。
创建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);
