classdef (Sealed) PatternsearchOptions < optim.options.MultiAlgorithm
    %PatternsearchOptions Options for PATTERNSEARCHOPTIONS
    %
    %   The OPTIM.OPTIONS.PATTERNSEARCHOPTIONS class allows the user to create a set
    %   of options for the PATTERNSEARCHOPTIONS solver. For a list of options that can
    %   be set, see the documentation for patternsearch.
    %
    %   OPTS = OPTIM.OPTIONS.PATTERNSEARCHOPTIONS creates a set of options for
    %   PATTERNSEARCHOPTIONS with the options set to their default values.
    %
    %   OPTS = OPTIM.OPTIONS.PATTERNSEARCHOPTIONS(PARAM, VAL, ...) creates a set of
    %   options for PATTERNSEARCHOPTIONS with the named parameters altered with the
    %   specified values.
    %
    %   OPTS = OPTIM.OPTIONS.PATTERNSEARCHOPTIONS(OLDOPTS, PARAM, VAL, ...) creates a
    %   copy of OLDOPTS with the named parameters altered with the specified
    %   values.
    %
    %   See also OPTIM.OPTIONS.SINGLEALGORITHM, OPTIM.OPTIONS.SOLVEROPTIONS
    
    %   Copyright 2015-2023 The MathWorks, Inc.
    
    properties (Dependent)
        
        %DISPLAY Level of display
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        Display
        
        %CONSTRAINTTOLERANCE Tolerance on the constraints
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        ConstraintTolerance
                
        %FUNCTIONTOLERANCE Tolerance on the function value
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        FunctionTolerance
                
        %MAXFUNCTIONEVALUATIONS Maximum number of objective function evaluations
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        MaxFunctionEvaluations
        
        %MAXITERATIONS Maximum number of iterations
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        MaxIterations
        
        %MAXTIME Total time (in seconds) allowed for optimization
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        MaxTime
                
        %MESHTOLERANCE Tolerance on the mesh size
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        MeshTolerance
        
        %STEPTOLERANCE Tolerance on the change in position and mesh size
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        StepTolerance
        
        %OUTPUTFCN Functions that get iterative data and can change options
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        OutputFcn
        
        %PLOTFCN Plots various measures of progress while the algorithm executes
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        PlotFcn
                        
        %USEPARALLEL Compute the objective function of particles in parallel
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        UseParallel
        
        %USEVECTORIZED Compute the objective function with a vectorized function call
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        UseVectorized
        
        %INITIALMESHSIZE Initial mesh size for pattern algorithm
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        InitialMeshSize
        
        %SEARCHFCN Function that performs the search phase of patternsearch
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        SearchFcn

        %SCALEMESH Automatic scaling of variables
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        ScaleMesh
        
        %MESHCONTRACTIONFACTOR Mesh contraction factor, used when iteration is unsuccessful
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        MeshContractionFactor
        
        %MESHEXPANSIONFACTOR Mesh expansion factor, used when iteration is successful
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        MeshExpansionFactor
        
        %POLLMETHOD Polling strategy used in pattern search
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        PollMethod
                
        %POLLORDERALGORITHM Algorithm selecting order of poll directions in pattern search
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        PollOrderAlgorithm
                
        %USECOMPLETEPOLL Perform complete poll around current iterate
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        UseCompletePoll
        
        %USECOMPLETESEARCH Perform complete search around current iterate when the search method is a poll method
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        UseCompleteSearch

        %ACCELERATEMESH Accelerate convergence near a minimum
        %
        %   For more information, type "doc patternsearch" and see the "Options"
        %   section in the PATTERNSEARCHOPTIONS documentation page.
        AccelerateMesh       
    end
    
    % Hidden properties
    properties (Hidden, Dependent)
        %ImprovementThreshold Tolerance used for improvement checks
        ImprovementThreshold
        
        %CACHE Keep history of points polled
        %
        Cache
        
        %CACHESIZE Size of the cache history
        %
        CacheSize
        
        %CACHETOL Tolerance on points in the cache
        %
        CacheTol
        
        %COMPLETEPOLL Perform complete poll around current iterate
        %
        CompletePoll

        %COMPLETESEARCH Perform complete search around current iterate when
        %               the search method is a poll method
        %
        CompleteSearch
        
        %INITIALPENALTY Initial value of the penalty parameter
        %
        InitialPenalty

        %MAXMESHSIZE Maximum number of objective function evaluations
        %
        MaxFunEvals

        %MAXMESHSIZE Maximum number of iterations
        %
        MaxIter
        
        %MAXMESHSIZE Maximum mesh size used in a poll/search step
        %
        MaxMeshSize

        %MESHACCELERATOR Accelerate convergence near a minimum
        %
        MeshAccelerator

        %MESHCONTRACTION Mesh contraction factor, used when iteration is unsuccessful
        %
        MeshContraction

        %MESHEXPANSIONFACTOR Mesh expansion factor, used when iteration is successful
        %
        MeshExpansion
        
        %MESHROTATE Rotate the pattern before declaring a point to be optimum
        %
        MeshRotate
        
        %OUTPUTFCNS Functions that get iterative data and can change options
        %
        OutputFcns
        
        %PLOTFCNS Plots various measures of progress while the algorithm executes
        %
        PlotFcns
        
        %PENALTYFACTOR  Penalty update parameter
        %
        PenaltyFactor
        
        %PLOTINTERVAL  Specifies that plot functions will be called at every interval
        %
        PlotInterval
        
        %POLLINGORDER Algorithm selecting order of poll directions in pattern search
        %
        PollingOrder        
        
        %SEARCHMETHOD Function that performs the search phase of patternsearch
        %
        SearchMethod

        %TIMELIMIT Total time (in seconds) allowed for optimization
        %
        TimeLimit
        
        %TOLBIND  Binding tolerance
        %
        TolBind
        
        %TOLBIND  Constraint tolerance
        %        
        TolCon
        
        %TOLFUN  Function tolerance
        %                
        TolFun
        
        %TOLMESH  Mesh tolerance
        %                        
        TolMesh
        
        %TOLX  Step tolerance
        %                                
        TolX        
        
        %USEVECTORIZED Compute the objective function with a vectorized function call
        %
        Vectorized
        
    end
    
    properties (Hidden, Access = protected)
        
        %OPTIONSSTORE Contains the option values and meta-data for the class
        %
        OptionsStore = createOptionsStore;
    end
    
    properties (Hidden)
        
        %SOLVERNAME Name of the solver that the options are intended for
        %
        SolverName = 'patternsearch';

    end
    
    properties (SetAccess = private, GetAccess = private)
        
        % Version number for the optim.options.PatternsearchOptions class.
        % We do not change the Version property (base class).
        PatternsearchVersion = 2
    end
    
     properties(Hidden, GetAccess=public)
        % Globally visible metadata about this class.       
        % This data is used to spec the options in this class for internal
        % clients such as: tab-complete, and the options validation
        PropertyMetaInfo = genPropInfo();    
    end
    
    % -------------------------------------------------------
    
    methods (Hidden)
        
        function obj = PatternsearchOptions(varargin)
            %PatternsearchOptions Options for PATTERNSEARCHOPTIONS
            %
            %   The OPTIM.OPTIONS.PATTERNSEARCHOPTIONS class allows the user to create a set
            %   of options for the PATTERNSEARCHOPTIONS solver. For a list of options that can
            %   be set, see the documentation for PATTERNSEARCHOPTIONS.
            %
            %   OPTS = OPTIM.OPTIONS.PATTERNSEARCHOPTIONS creates a set of options for
            %   PATTERNSEARCHOPTIONS with the options set to their default values.
            %
            %   OPTS = OPTIM.OPTIONS.PATTERNSEARCHOPTIONS(PARAM, VAL, ...) creates a set of
            %   options for PATTERNSEARCHOPTIONS with the named parameters altered with the
            %   specified values.
            %
            %   OPTS = OPTIM.OPTIONS.PATTERNSEARCHOPTIONS(OLDOPTS, PARAM, VAL, ...) creates a
            %   copy of OLDOPTS with the named parameters altered with the specified
            %   values.
            %
            %   See also OPTIM.OPTIONS.SINGLEALGORITHM, OPTIM.OPTIONS.SOLVEROPTIONS
            
            % Call the superclass constructor
            obj = obj@optim.options.MultiAlgorithm(varargin{:});
            
        end
        
    end
    
    % Set/get methods
    methods
        function obj = set.AccelerateMesh(obj, value)
            obj = setNewProperty(obj, 'AccelerateMesh', value);
        end
        
        function obj = set.ConstraintTolerance(obj, value)
            obj = setAliasProperty(obj, 'ConstraintTolerance', 'TolCon', value);
        end
        
        function obj = set.Display(obj, value)
            obj = setProperty(obj, 'Display', value);
        end
        
        function obj = set.FunctionTolerance(obj, value)
            obj = setAliasProperty(obj, 'FunctionTolerance', 'TolFunValue', value);
        end
        
        function obj = set.InitialMeshSize(obj, value)
            obj = setProperty(obj, 'InitialMeshSize', value);
        end
        
        function obj = set.MaxFunctionEvaluations(obj, value)
            obj = setAliasProperty(obj, 'MaxFunctionEvaluations', 'MaxFunEvals', value);
        end
        
        function obj = set.MaxIterations(obj, value)
            obj = setAliasProperty(obj, 'MaxIterations', 'MaxIter', value);
        end
        
        function obj = set.MaxTime(obj, value)
            obj = setAliasProperty(obj, 'MaxTime', 'TimeLimit', value);
        end
        
        function obj = set.MeshContractionFactor(obj, value)
            obj = setAliasProperty(obj, 'MeshContractionFactor', 'MeshContraction', value);
        end
        
        function obj = set.MeshExpansionFactor(obj, value)
            obj = setAliasProperty(obj, 'MeshExpansionFactor', 'MeshExpansion', value);
        end
        
        function obj = set.MeshTolerance(obj, value)
            obj = setAliasProperty(obj, 'MeshTolerance', 'TolMesh', value);
        end
        
        function obj = set.OutputFcn(obj, value)
            obj = setAliasProperty(obj, 'OutputFcn', 'OutputFcns', value);
        end
        
        function obj = set.PlotFcn(obj, value)
            obj = setAliasProperty(obj, 'PlotFcn', 'PlotFcns', value);
        end
        
        function obj = set.PollMethod(obj, value)
            obj = setProperty(obj, 'PollMethod', value);
        end
        
        function obj = set.PollOrderAlgorithm(obj, value)
            obj = setAliasProperty(obj, 'PollOrderAlgorithm', 'PollingOrder', value);
        end
        
        function obj = set.ScaleMesh(obj, value)
            % ScaleMesh for patternsearch still accepts the undocumented
            % values, 'on'/'off'
            if any(strcmpi(value, {'on', 'off'}))
                value = optim.options.OptionAliasStore.convertToLogical(value, 'on');
            end
            obj = setNewProperty(obj, 'ScaleMesh', value);
        end
        
        function obj = set.SearchFcn(obj, value)
            if isa(value,'SearchStepFunction')
                obj = setPropertyNoChecks(obj, 'SearchFcn', value);
                obj = setPropertyNoChecks(obj, 'SearchMethod', value);
            else    
                obj = setAliasProperty(obj, 'SearchFcn', 'SearchMethod', value);
            end
        end
        
        function obj = set.StepTolerance(obj, value)
            obj = setAliasProperty(obj, 'StepTolerance', 'TolX', value);
        end
        
        function obj = set.UseCompletePoll(obj, value)
            obj = setNewProperty(obj, 'UseCompletePoll', value);
        end
        
        function obj = set.UseCompleteSearch(obj, value)
            obj = setNewProperty(obj, 'UseCompleteSearch', value);
        end
        
        function obj = set.UseParallel(obj, value)
            obj = setProperty(obj, 'UseParallel', value);
        end
        
        function obj = set.UseVectorized(obj, value)
            obj = setNewProperty(obj, 'UseVectorized', value);
        end
        
        function obj = set.ImprovementThreshold(obj, value)
            obj = setProperty(obj, 'ImprovementThreshold', value);
        end

        %---------------------- Get functions -----------------------------
        
        function value = get.AccelerateMesh(obj)
            value = optim.options.OptionAliasStore.convertToLogical( ...
                obj.OptionsStore.Options.MeshAccelerator, 'on');
        end
        
        function value = get.ConstraintTolerance(obj)
            value = obj.OptionsStore.Options.TolCon;
        end
        
        function value = get.Display(obj)
            value = obj.OptionsStore.Options.Display;
        end
        
        function value = get.FunctionTolerance(obj)
            value = obj.OptionsStore.Options.TolFunValue;
        end
        
        function value = get.InitialMeshSize(obj)
            value = obj.OptionsStore.Options.InitialMeshSize;
        end
        
        function value = get.MaxFunctionEvaluations(obj)
            value = obj.OptionsStore.Options.MaxFunEvals;
        end
        
        function value = get.MaxIterations(obj)
            value = obj.OptionsStore.Options.MaxIter;
        end
        
        function value = get.MaxTime(obj)
            value = obj.OptionsStore.Options.TimeLimit;
        end
        
        function value = get.MeshContractionFactor(obj)
            value = obj.OptionsStore.Options.MeshContraction;
        end
        
        function value = get.MeshExpansionFactor(obj)
            value = obj.OptionsStore.Options.MeshExpansion;
        end
        
        function value = get.MeshTolerance(obj)
            value = obj.OptionsStore.Options.TolMesh;
        end
        
        function value = get.OutputFcn(obj)
            value = obj.OptionsStore.Options.OutputFcns;
        end
        
        function value = get.PlotFcn(obj)
            value = obj.OptionsStore.Options.PlotFcns;
        end
        
        function value = get.PollMethod(obj)
            value = obj.OptionsStore.Options.PollMethod;
        end
        
        function value = get.PollOrderAlgorithm(obj)
            value = obj.OptionsStore.Options.PollingOrder;
        end
        
        function value = get.ScaleMesh(obj)
            value = optim.options.OptionAliasStore.convertToLogical( ...
                obj.OptionsStore.Options.ScaleMesh, 'on');
        end
        
        function value = get.SearchFcn(obj)
            value = obj.OptionsStore.Options.SearchMethod;
        end
        
        function value = get.StepTolerance(obj)
            value = obj.OptionsStore.Options.TolX;
        end
        
        function value = get.UseCompletePoll(obj)
            value = optim.options.OptionAliasStore.convertToLogical( ...
                obj.OptionsStore.Options.CompletePoll, 'on');
        end
        
        function value = get.UseCompleteSearch(obj)
            value = optim.options.OptionAliasStore.convertToLogical( ...
                obj.OptionsStore.Options.CompleteSearch, 'on');
        end
        
        function value = get.UseParallel(obj)
            value = obj.OptionsStore.Options.UseParallel;
        end
        
        function value = get.UseVectorized(obj)
            value = optim.options.OptionAliasStore.convertToLogical( ...
                obj.OptionsStore.Options.Vectorized, 'on');
        end
    
        function val = get.ImprovementThreshold(obj)
            val = obj.OptionsStore.Options.ImprovementThreshold;
        end

    end % get/set methods
    
    % Set/get methods for hidden options
    methods
        
        %----------------------- Set functions ----------------------------

        function obj = set.Cache(obj, value)
            obj = setProperty(obj, 'Cache', value);
        end

        function obj = set.CacheSize(obj, value)
            obj = setProperty(obj, 'CacheSize', value);
        end
        
        function obj = set.CacheTol(obj, value)
            obj = setProperty(obj, 'CacheTol', value);
        end
        
        function obj = set.CompletePoll(obj, value)
            obj = setProperty(obj, 'CompletePoll', value);
        end
        
        function obj = set.CompleteSearch(obj, value)
            obj = setProperty(obj, 'CompleteSearch', value);
        end
        
        function obj = set.InitialPenalty(obj, value)
            obj = setProperty(obj, 'InitialPenalty', value);
        end

        function obj = set.MaxFunEvals(obj, value)
            obj = setProperty(obj, 'MaxFunEvals', value);
        end

        function obj = set.MaxIter(obj, value)
            obj = setProperty(obj, 'MaxIter', value);
        end
        
        function obj = set.MaxMeshSize(obj, value)
            obj = setProperty(obj, 'MaxMeshSize', value);
        end

        function obj = set.MeshAccelerator(obj, value)
            obj = setProperty(obj, 'MeshAccelerator', value);
        end

        function obj = set.MeshContraction(obj, value)
            obj = setProperty(obj, 'MeshContraction', value);
        end
        
        function obj = set.MeshExpansion(obj, value)
            obj = setProperty(obj, 'MeshExpansion', value);
        end
        
        function obj = set.MeshRotate(obj, value)
            obj = setProperty(obj, 'MeshRotate', value);
        end

        function obj = set.OutputFcns(obj, value)
            obj = setProperty(obj, 'OutputFcns', value);
        end

        function obj = set.PenaltyFactor(obj, value)
            obj = setProperty(obj, 'PenaltyFactor', value);
        end
        
        function obj = set.PlotFcns(obj, value)
            obj = setProperty(obj, 'PlotFcns', value);
        end
                
        function obj = set.PlotInterval(obj, value)
            obj = setProperty(obj, 'PlotInterval', value);
        end

        function obj = set.PollingOrder(obj, value)
            obj = setProperty(obj, 'PollingOrder', value);
        end

        function obj = set.SearchMethod(obj, value)
            obj = setProperty(obj, 'SearchMethod', value);
        end

        function obj = set.TimeLimit(obj, value)
            obj = setProperty(obj, 'TimeLimit', value);
        end
        
        function obj = set.TolBind(obj, value)
            obj = setProperty(obj, 'TolBind', value);
        end
        
        function obj = set.TolCon(obj, value)
            obj = setProperty(obj, 'TolCon', value);
        end

        function obj = set.TolFun(obj, value)
            obj = setAliasProperty(obj, 'TolFun', 'TolFunValue', value);        
        end
        
        function obj = set.TolMesh(obj, value)
            obj = setProperty(obj, 'TolMesh', value);
        end

        function obj = set.TolX(obj, value)
            obj = setProperty(obj, 'TolX', value);
        end

        function obj = set.Vectorized(obj, value)
            obj = setProperty(obj, 'Vectorized', value);
        end
        
        %----------------------- Get functions ----------------------------

        function value =  get.Cache(obj)
            value = obj.OptionsStore.Options.Cache;
        end

        function value = get.CacheSize(obj)
            value = obj.OptionsStore.Options.CacheSize;
        end
        
        function value = get.CacheTol(obj)
            value = obj.OptionsStore.Options.CacheTol;
        end

        function value = get.CompletePoll(obj)
            value = obj.OptionsStore.Options.CompletePoll;
        end
        
        function value = get.CompleteSearch(obj)
            value = obj.OptionsStore.Options.CompleteSearch;
        end
        
        function value = get.InitialPenalty(obj)
            value = obj.OptionsStore.Options.InitialPenalty;
        end

        function value = get.MaxFunEvals(obj)
            value = obj.OptionsStore.Options.MaxFunEvals;
        end

        function value = get.MaxIter(obj)
            value = obj.OptionsStore.Options.MaxIter;
        end
        
        function value = get.MaxMeshSize(obj)
            value = obj.OptionsStore.Options.MaxMeshSize;
        end

        function value = get.MeshAccelerator(obj)
            value = obj.OptionsStore.Options.MeshAccelerator;
        end

        function value = get.MeshContraction(obj)
            value = obj.OptionsStore.Options.MeshContraction;
        end

        function value = get.MeshExpansion(obj)
            value = obj.OptionsStore.Options.MeshExpansion;
        end
        
        function value = get.MeshRotate(obj)
            value = obj.OptionsStore.Options.MeshRotate;
        end
        
        function value = get.OutputFcns(obj)
            value = obj.OptionsStore.Options.OutputFcns;
        end
        
        function value = get.PenaltyFactor(obj)
            value = obj.OptionsStore.Options.PenaltyFactor;
        end

        function value = get.PlotFcns(obj)
            value = obj.OptionsStore.Options.PlotFcns;
        end
        
        function value = get.PlotInterval(obj)
            value = obj.OptionsStore.Options.PlotInterval;
        end

        function value = get.PollingOrder(obj)
            value = obj.OptionsStore.Options.PollingOrder;
        end

        function value = get.SearchMethod(obj)
            value = obj.OptionsStore.Options.SearchMethod;
        end

        function value = get.TimeLimit(obj)
            value = obj.OptionsStore.Options.TimeLimit;
        end
        
        function value = get.TolBind(obj)
            value = obj.OptionsStore.Options.TolBind;
        end

        function value = get.TolCon(obj)
            value = obj.OptionsStore.Options.TolCon;
        end

        function value = get.TolFun(obj)
            value = obj.OptionsStore.Options.TolFunValue;
        end

        function value = get.TolMesh(obj)
            value = obj.OptionsStore.Options.TolMesh;
        end

        function value = get.TolX(obj)
            value = obj.OptionsStore.Options.TolX;
        end

        function value = get.Vectorized(obj)
            value = obj.OptionsStore.Options.Vectorized;
        end
        
    end
    
    methods (Hidden)
        function OptionsStruct = extractCustomOptionsStructure(obj)
            %EXTRACTCUSTOMOPTIONSSTRUCTURE Extract options structure from
            %OptionsStore
            %
            %   OPTIONSSTRUCT = EXTRACTCUSTOMOPTIONSSTRUCTURE(OBJ) extracts
            %   a plain structure containing the options from
            %   obj.OptionsStore. The solver calls convertForSolver, which
            %   in turn calls this method to obtain a plain options
            %   structure.
            
            % Call superclass to generate structure with options set by the
            % user and all other fields empty
            OptionsStruct = extractCustomOptionsStructure@optim.options.MultiAlgorithm(obj);
            
            % Add TolFun to the options struct since patternsearch doesn't
            % recognize TolFunValue
            OptionsStruct.TolFun = OptionsStruct.TolFunValue;
        end
        
    end   % Hidden methods
    
    methods (Static = true)
        function objNew = loadobj(obj)
            
            if obj.PatternsearchVersion < 2
                % Create new object
                objNew = optim.options.PatternsearchOptions;

                % Copy content over from loaded object to new object
                optsNames = fieldnames(obj.OptionsStore.Options);
                for ii=1:length(optsNames)
                    optsName = optsNames{ii};
                    if obj.OptionsStore.SetByUser.(optsName)
                        objNew.(optsName) = obj.(optsName) ; 
                    end
                end
            else
                objNew = obj;
            end            
        end
    end
end

function OS = createOptionsStore
%CREATEOPTIONSSTORE Create the OptionsStore
%
%   OS = createOptionsStore creates the OptionsStore structure. This
%   structure contains the options and meta-data for option display, e.g.
%   data determining whether an option has been set by the user. This
%   function is only called when the class is first instantiated to create
%   the OptionsStore structure in its default state. Subsequent
%   instantiations of this class pick up the default OptionsStore from the
%   MCOS class definition.
%
%   Class authors must create a structure containing all the options in a
%   field of OS called Defaults. This structure must then be passed to the
%   optim.options.generateSingleAlgorithmOptionsStore function to create
%   the full OptionsStore. See below for an example for PatternsearchOptions.

% Define the algorithm names
OS.AlgorithmNames = {'classic', 'nups', 'nups-gps', 'nups-mads'};

% Define the default algorithm
OS.DefaultAlgorithm = 'classic';

% Define the option defaults for the classic algorithm
OS.AlgorithmDefaults{1}.Cache = 'off';
OS.AlgorithmDefaults{1}.CacheSize = 10000;
OS.AlgorithmDefaults{1}.CacheTol = eps;
OS.AlgorithmDefaults{1}.CompletePoll = 'off';
OS.AlgorithmDefaults{1}.CompleteSearch = 'off';
OS.AlgorithmDefaults{1}.Display = 'final';
OS.AlgorithmDefaults{1}.InitialMeshSize = 1.0;
OS.AlgorithmDefaults{1}.InitialPenalty = 10;
OS.AlgorithmDefaults{1}.MaxFunEvals = '2000*numberOfVariables';
OS.AlgorithmDefaults{1}.MaxIter = '100*numberOfVariables';
OS.AlgorithmDefaults{1}.MaxMeshSize = Inf;
OS.AlgorithmDefaults{1}.MeshAccelerator = 'off';
OS.AlgorithmDefaults{1}.MeshContraction = 0.5;
OS.AlgorithmDefaults{1}.MeshExpansion = 2.0;
OS.AlgorithmDefaults{1}.MeshRotate = 'on';
OS.AlgorithmDefaults{1}.OutputFcns = [];
OS.AlgorithmDefaults{1}.PenaltyFactor = 100;
OS.AlgorithmDefaults{1}.PlotFcns = [];
OS.AlgorithmDefaults{1}.PlotInterval = 1;
OS.AlgorithmDefaults{1}.PollMethod = 'GPSPositiveBasis2N';
OS.AlgorithmDefaults{1}.PollingOrder = 'Consecutive';
OS.AlgorithmDefaults{1}.SearchMethod = [];
OS.AlgorithmDefaults{1}.ScaleMesh = 'on';
OS.AlgorithmDefaults{1}.SearchMethod = [];
OS.AlgorithmDefaults{1}.TimeLimit = Inf;
OS.AlgorithmDefaults{1}.TolBind = 1e-3;
OS.AlgorithmDefaults{1}.TolCon = 1e-6;
OS.AlgorithmDefaults{1}.TolFunValue = 1e-6;
OS.AlgorithmDefaults{1}.TolMesh = 1e-6;
OS.AlgorithmDefaults{1}.TolX = 1e-6;
OS.AlgorithmDefaults{1}.UseParallel = false;
OS.AlgorithmDefaults{1}.Vectorized = 'off';

% Define the option defaults for NUPS
OS.AlgorithmDefaults{2}.Cache = 'off';
OS.AlgorithmDefaults{2}.CacheSize = 10000;
OS.AlgorithmDefaults{2}.CacheTol = eps;
OS.AlgorithmDefaults{2}.Display = 'final';
OS.AlgorithmDefaults{2}.ImprovementThreshold = 1e-4; % This is new in NUPS
OS.AlgorithmDefaults{2}.InitialMeshSize = 1.0;
OS.AlgorithmDefaults{2}.InitialPenalty = 10;
OS.AlgorithmDefaults{2}.MaxFunEvals = '2000*numberOfVariables';
OS.AlgorithmDefaults{2}.MaxIter = '100*numberOfVariables';
OS.AlgorithmDefaults{2}.MaxMeshSize = Inf;
OS.AlgorithmDefaults{2}.SearchMethod = [];
OS.AlgorithmDefaults{2}.OutputFcns = [];
OS.AlgorithmDefaults{2}.PenaltyFactor = 100;
OS.AlgorithmDefaults{2}.PlotFcns = [];
OS.AlgorithmDefaults{2}.PlotInterval = 1;
OS.AlgorithmDefaults{2}.ScaleMesh = 'on';
OS.AlgorithmDefaults{2}.TimeLimit = Inf;
OS.AlgorithmDefaults{2}.TolBind = 1e-3;
OS.AlgorithmDefaults{2}.TolCon = 1e-6;
OS.AlgorithmDefaults{2}.TolFunValue = 1e-6;
OS.AlgorithmDefaults{2}.TolMesh = 1e-6;
OS.AlgorithmDefaults{2}.TolX = 1e-6;
OS.AlgorithmDefaults{2}.UseParallel = false;
OS.AlgorithmDefaults{2}.Vectorized = 'off';

% Define the option defaults for NUPS-GPS
OS.AlgorithmDefaults{3} = OS.AlgorithmDefaults{2};

% Define the option defaults for NUPS-MADS
OS.AlgorithmDefaults{4} = OS.AlgorithmDefaults{2};

% Call the package function to generate the OptionsStore
OS = optim.options.generateMultiAlgorithmOptionsStore(OS,'optim.options.PatternsearchOptions');
end

function propInfo = genPropInfo()
% Helper function to generate property metadata for the
% PatternsearchOptions options class.

import optim.options.meta.Factory
import optim.options.meta.category
import optim.options.meta.label

algorithmCat = category('Algorithm');
meshCat = category('Mesh');
pollCat = category('Poll');

propInfo.AccelerateMesh = Factory.logicalType(label('AccelMesh'),meshCat);
propInfo.ConstraintTolerance = Factory.constraintToleranceType;
propInfo.Display = Factory.displayType({'none','off','iter','diagnose','final'});
propInfo.FunctionTolerance = Factory.functionToleranceType;
propInfo.InitialMeshSize = Factory.positiveRealType(label('InitMesh'),meshCat);
propInfo.MaxFunctionEvaluations =  Factory.maxFunEvalsType;
propInfo.MaxIterations = Factory.maxIterType;
propInfo.MaxTime = Factory.maxTimeType;
propInfo.MeshContractionFactor = Factory.numericType('scalar',[0.0 1.0],[false false],label('MeshContract'),meshCat);
propInfo.MeshExpansionFactor = Factory.numericType('scalar',[1.0 Inf],[false false],label('MeshExpand'),meshCat);
propInfo.MeshTolerance = Factory.toleranceType(label('TolMesh'));
propInfo.OutputFcn = Factory.outputFcnType;
propInfo.PlotFcn = Factory.plotFcnType({'psplotbestf', 'psplotmeshsize', 'psplotfuncount', 'psplotbestx', 'psplotmaxconstr'});
propInfo.PollMethod = Factory.enumType({'GPSPositiveBasis2N','GPSPositiveBasisNp1','GSSPositiveBasis2N','GSSPositiveBasisNp1', ...
    'MADSPositiveBasis2N','MADSPositiveBasisNp1','OrthoMADSPositiveBasis2N','OrthoMADSPositiveBasisNp1'},label('PollMethod'),pollCat);
propInfo.PollOrderAlgorithm = Factory.enumType({'Random','Success','Consecutive'},label('PollOrder'),pollCat);
propInfo.ScaleMesh = Factory.logicalType(label('ScaleMesh'),meshCat);
propInfo.SearchFcn = Factory.fcnWithCellType(label('SearchFcn'),algorithmCat,{'GPSPositiveBasis2N', 'GPSPositiveBasisNp1', ...
    'GSSPositiveBasis2N', 'GSSPositiveBasisNp1', 'MADSPositiveBasis2N', 'MADSPositiveBasisNp1', ...
    'OrthoMADSPositiveBasis2N','OrthoMADSPositiveBasisNp1', 'searchga', 'searchlhs', 'searchneldermead', 'rbfsurrogate'});
propInfo.StepTolerance = Factory.stepToleranceType;
propInfo.UseCompletePoll = Factory.logicalType(label('CompletePoll'),pollCat);
propInfo.UseCompleteSearch = Factory.logicalType(label('CompleteSearch'),algorithmCat);
propInfo.UseParallel = Factory.logicalWithEnumType(label('UseParallel'),category('Algorithm'),{'always','never'});
propInfo.UseVectorized = Factory.useVectorizedType;
propInfo.Algorithm = Factory.algorithmType({'classic','nups','nups-gps','nups-mads'});
propInfo.ImprovementThreshold = Factory.numericType('scalar',[0 1],[true true],'','');

% Initialize some "empty" types for validation only
onOffType = Factory.onOffType();
emptyToleranceType = Factory.toleranceType('');
emptyPosRealType = Factory.positiveRealType('','');

% Hidden options - no need for labels, categories, etc. Reuse where possible.
propInfo.Cache = onOffType;
propInfo.CacheSize = emptyToleranceType;
propInfo.CacheTol = emptyToleranceType;
propInfo.CompletePoll = onOffType;
propInfo.CompleteSearch = onOffType;
propInfo.InitialPenalty = emptyPosRealType;
propInfo.MaxFunEvals = propInfo.MaxFunctionEvaluations;
propInfo.MaxIter = propInfo.MaxIterations;
propInfo.MaxMeshSize = emptyToleranceType;
propInfo.MeshAccelerator = onOffType;
propInfo.MeshContraction = propInfo.MeshContractionFactor;
propInfo.MeshExpansion = propInfo.MeshExpansionFactor;
propInfo.MeshRotate = onOffType;
propInfo.OutputFcns = propInfo.OutputFcn;
propInfo.PenaltyFactor = emptyPosRealType;
propInfo.PlotFcns = propInfo.PlotFcn;
propInfo.PlotInterval = Factory.resourceLimitType('');
propInfo.PollingOrder = propInfo.PollOrderAlgorithm;
propInfo.SearchMethod = propInfo.SearchFcn;
propInfo.TimeLimit = propInfo.MaxTime;
propInfo.TolBind = emptyToleranceType;
propInfo.TolCon = propInfo.ConstraintTolerance;
propInfo.TolFun = propInfo.FunctionTolerance;
propInfo.TolMesh = propInfo.MeshTolerance;
propInfo.TolX = propInfo.StepTolerance;
propInfo.Vectorized = onOffType;
end
