function stop = psplotspread(optimValues,flag)
    %PSPLOTSPREAD Plots spread of individuals on Pareto front every iteration.
    %   STOP = PSPLOTSPREAD(OPTIMVALUES,FLAG) where OPTIMVALUES is a
    %   structure with the following fields:
    %
    %    PARETOSEARCH:
    %               x: current Pareto set in parameter space
    %            fval: current Pareto set in functional space
    %       iteration: iteration count
    %       funccount: number of function evaluations
    %      nonlinineq: nonlinear inequality constraints at X
    %        nonlineq: nonlinear equality constraints at X
    %          volume: total volume of polytope defined by Pareto set
    % averagedistance: weighted average distance between Pareto points
    %          spread: measure of how far apart Pareto points are from outliers in the Pareto set
    %
    %   FLAG: Current state in which PlotFcn is called. Possible values are:
    %            init: initialization state
    %            iter: iteration state
    %       interrupt: intermediate state
    %            done: final state
    %
    %   STOP: A boolean to stop the algorithm.
    %
    %   See also PARETOSEARCH, OPTIMOPTIONS.

    %   Copyright 2018-2023 The MathWorks, Inc.

    % Always return a "stop" flag of false
    stop = false;

    % Persistent variables
    persistent thePlot

    switch flag
        case "init"
            thePlot = matlab.internal.optimfun.plotfcns.Factory.psplotspread(optimValues);
        case "iter"
            thePlot.update(optimValues);
    end
end
