Hi,
I have a multiobjective opimization problem and want to solve it with gamultiobj. I want to save the optimized values of my objective functions after every iteration in an array. I found the example code for the output function here: http://de.mathworks.com/help/optim/ug/output-functions.html . But when I apply the example code to my problem, like this:
function [history,searchdir] = runfmincon FitnessFunction = @needfunction; numberOfVariables = 8; lb = zeros(1,8); ub = [];% Set up shared variables with OUTFUN
history.x = []; history.fval = []; searchdir = []; options = gaoptimset('PlotFcns',@gaplotpareto,'UseParallel',true,'OutputFcns', @outfun,'PopulationSize',5); xsol = gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,[],options); function stop = outfun(x,optimValues,state) stop = false; switch state case 'init' hold on case 'iter' % Concatenate current point and objective function
% value with history. x must be a row vector.
history.fval = [history.fval; optimValues.fval]; history.x = [history.x; x]; % Concatenate current search direction with
% searchdir.
searchdir = [searchdir;... optimValues.searchdirection']; plot(x(1),x(2),'o'); % Label points with iteration number and add title.
% Add .15 to x(1) to separate label from plotted 'o'
text(x(1)+.15,x(2),... num2str(optimValues.iteration)); title('Sequence of Points Computed by fmincon'); case 'done' hold off otherwise end end end
I get the following error:
Error using runfmincon/outfun Too many output arguments. Error in gaoutput (line 39) [state,optnew,changed] = feval(functions{i},options.OutputPlotFcnOptions,state,flag,args{i}{:}); Error in gamultiobjsolve (line 13) [state,options] = gaoutput(FitnessFcn,options,state,currentState); Error in gamultiobj (line 274) [x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ... Error in runfmincon (line 16) xsol = gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,[],options);
It would be great, if someone could help me out
Best Answer