I am trying to make a plot of the best function value versus generation with gamultiobj. I have set the options as follows:
options = gaoptimset('PlotFcns', @gaplotbestf);
and provide these to gamultiobj:
fitnessFunction = @schaffer2;lowerBound = 0;upperBound = 5;[x1, f1, exitflag1, output1, population1, score1] = gamultiobj(fitnessFunction,... 1, [], [], [], [], lowerBound, upperBound, options);
Where fitnessFunction is the schaffer2 function from the gamultiobj documentation:
function y = schaffer2(x) % y has two columns
% Initialize y for two objectives and for all x
y = zeros(length(x),2); % ready for vectorization
% Evaluate first objective.
% This objective is piecewise continuous.
for i = 1:length(x) if x(i) <= 1 y(i,1) = -x(i); elseif x(i) <=3 y(i,1) = x(i) -2; elseif x(i) <=4 y(i,1) = 4 - x(i); else y(i,1) = x(i) - 4; endend% Evaluate second objective
y(:,2) = (x -5).^2;
The output of the algorithm is not empty. However, the plot is blank with the title "Best fitness plot: not available". I have tried other plots such as @gaplotselection and @gaplotpareto which do work. What does this mean? Am I doing something wrong?
Best Answer