function obj = loadobj(s)
%

%   Copyright 2016-2022 The MathWorks, Inc.

if isstruct(s)
    obj = builtin('loadobj',s);
else
    obj = s;
end
% TotalElapsedTimeTrace was added as a property in R2017b
if isempty(obj.TotalElapsedTimeTrace)
    obj.TotalElapsedTimeTrace = cumsum(obj.PrivIterationTimeTrace, 'omitnan')';
end
% Changes in 2020a:
%
% The following properties were renamed, and the GP models were
% packaged up inside objects of class
% bayesoptim.BayesOptGPModel:
%
%   ObjectiveFcnGP              --> ObjectiveFcnModel
%   ObjectiveEvaluationTimeGP   --> ObjectiveEvaluationTimeModel
%   ConstraintGPs               --> ConstraintModels
%   ErrorGP                     --> ErrorModel
%
% Also, a new property was added: 'ModelStrategy', which should
% be set to bayesoptim.GPStrategy() for old models.
if isempty(obj.ModelStrategy)
    obj.ModelStrategy = bayesoptim.GPStrategy();
    if ~isempty(obj.ObjectiveFcnGP)
        obj.ObjectiveFcnModel = bayesoptim.BayesOptGPModel(...
            obj.ObjectiveFcnGP.Sigma, ...
            obj.ObjectiveFcnGP, ...
            obj.ObjectiveFcnGP.KernelInformation, ...
            obj.ObjectiveFcnGP.Beta);
        obj.ObjectiveFcnGP = [];
    end
    if ~isempty(obj.ObjectiveEvaluationTimeGP)
        obj.ObjectiveEvaluationTimeModel = bayesoptim.BayesOptGPModel(...
            obj.ObjectiveEvaluationTimeGP.Sigma, ...
            obj.ObjectiveEvaluationTimeGP, ...
            obj.ObjectiveEvaluationTimeGP.KernelInformation, ...
            obj.ObjectiveEvaluationTimeGP.Beta);
        obj.ObjectiveEvaluationTimeGP = [];
    end
    obj.ConstraintModels = cellfun(@(m)bayesoptim.BayesOptGPModel(...
        m.Sigma, m, m.KernelInformation, m.Beta), obj.ConstraintGPs, 'UniformOutput', false);
    obj.ConstraintGPs = {};
    if ~isempty(obj.ErrorGP)
        obj.ErrorModel = bayesoptim.BayesOptGPModel(...
            obj.ErrorGP.Sigma, ...
            obj.ErrorGP, ...
            obj.ErrorGP.KernelInformation, ...
            obj.ErrorGP.Beta);
        obj.ErrorGP = [];
    end
end
end
