📄 heurset.m
字号:
function problem = heurset(varargin)
%HEURSET Set options for the various heuristic optimizers
%
% Usage:
%
% heurset (to display a quick summary of all the options)
% options = heurset('option1', value1, 'option2', value2, ...)
% PROBLEM = heurset('option1', value1, 'option2', value2, ...)
%
% HEURSET is an easy way to set all options for the global optimization
% algorithms SWARM, DIFFEVOLVE, GENETIC, SIMANNEAL and GODLIKE. All
% options, and their possible values are:
%
% ======================================================================
% To define a full problem (PROBLEM = heurset(...)):
% ======================================================================
% CostFunction : function handle to the N-dimensional objective function
% Lb : [1 x N] vector defining the lower bounds for each
% dimension.
% Ub : [1 x N] vector defining the upper bounds for each
% dimension.
% Popsize : the population size to be used by the heuristic metod.
%
% ======================================================================
% General options for all optimizers:
% ======================================================================
% Grace : positive scalar. When nonzero, this will pass the result
% found after convergence to the FMINSEARCH function,
% allowing it this many function evaluations (on top of the
% "MaxFevals" option, see two options down). This function
% is part of the optimization toolbox, so it should be set
% to zero when this is not present. The default is 0.
% Display : string, either 'on' or 'off'. Determines whether progress
% will be displayed during the optimizations. The default
% is "on".
% MaxFevals : positive scalar, defining the maximum number of
% allowable function evaluations. The default is 1e6.
% Maxiters : positive scalar. This enables the "maximum iterations"
% convergence criterion. The optimizer will be "converged"
% when this number of iterations has been performed.
% BestInPop : positive scalar. This enables the "exhaustive" convergence
% criterion--The best individual ever found needs to remain
% the best for this many iterations before the algorithm is
% "converged".
% AchieveFval : scalar. This enables the "goal-attain" convergence
% criterion--basically, the algorithm continues until
% either this function value has been reached, or the
% maximum number of iterations has been superceeded.
%
% *NOTE*: only the last convergence criterion given will be used. The
% default convergence criterion is the "BestInPop", with a value of 100.
%
% ======================================================================
% Options specific to the Differential Evolution algorithm:
% ======================================================================
% Flb : scalar. This value defines the lower bound for the range
% from which the scaling parameter will be taken. The
% default value is -1.2.
% Fub : scalar. This value defines the upper bound for the range
% from which the scaling parameter will be taken. The
% default value is +1.2. These two values may be set equal
% to each other, in which case the scaling parameter F is
% simply a constant.
% Crossconst : positive scalar. It defines the probability with which a
% new trial individual will be inserted in the new
% population. The default value is 0.9.
% n : positive scalar. This defines the number of transversal
% steps that the Differential Evolution takes every
% iteration. The default value is 10. Note that setting this
% value to 1 results in the Neoteric Differential Evolution
% Algorithm.
%
% ======================================================================
% Options specific to the Genetic Algorithm:
% ======================================================================
% Crossprob : positive scalar, defining the probability for crossover
% for each individual. The default value is 0.25.
% Mutprob : positive scalar, defining the mutation probability for
% each individual. The default value is 0.01.
%
% ======================================================================
% Options specific to the Simulated Annealing Algorithm:
% ======================================================================
% T0 : scalar. This is the initial temperature for all particles. The
% default value is 1.
% minT : scalar. This is the minimum temperature before convergence. The
% default value is 1e-8.
% k : scalar. This is the (normalized) Bolzmann constant. The default
% is 1.
% cool : function handle, with "maxiters", T0, T, and minT as parameters.
% This function defines the cooling schedule to be applied each
% iteration. The default is
% @(T,T0,minT,maxiters)(minT/T0)^(1/maxiters).
%
% ======================================================================
% Options specific to the Particle Swarm Algorithm:
% ======================================================================
% eta1 : scalar < 4. This is the 'social factor', the
% acceleration factor in front of the difference with the
% particle's position and its neighorhood-best. The
% default value is 2. Note that negative values result in
% a Repulsive Particle Swarm algorithm.
% eta2 : scalar < 4. This is the 'cooperative factor', the
% acceleration factor in front of the difference with the
% particle's position and the location of the global
% minimum found so far. The default value is 2.
% eta3 : scalar < 4. This is the 'nostalgia factor', the
% acceleration factor in front of the difference with the
% particle's position and its personal-best. The default
% value is 0.5.
% omega : scalar. This is the 'inertial constant', the tendency of
% a particle to continue its motion undisturbed. The
% default value is 0.5.
% numneighbors : positive scalar. This defines the number of neighbors
% assigned to each particle. The default value is 5.
%
% ======================================================================
% Options specific to the GODLIKE Algorithm:
% ======================================================================
% AlgIters : positive scalar. This sets the number of iterations
% spent in each heuristic optimizer. The default value is
% 250.
% PutbackIters : positive scalar. This defines the number if iterations
% before the best individual ever found is inserted back
% into one of the populations. The default value is 25.
% SwapIters : positive scalar. This sets the number of iterations
% before the different populations are shuffled and
% swapped between the algorithms. The default value is 25.
%
% See also genetic, diffevolve, swarm, simanneal, godlike.
% Author: Rody P.S. Oldenhuis
% Delft University of Technology
% E-mail: oldenhuis@dds.nl
% Last edited: 28/Feb/2009
% display quick summary for HEURSET in case of zero input- and output-arguments
if (nargin == 0) && (nargout == 0)
fprintf(1, 'CostFunction: [ function handle | {[]} ]\n')
fprintf(1, ' Lb: [ (1 x N) vector | {[]} ] \n')
fprintf(1, ' Ub: [ (1 x N) vector | {[]} ] \n')
fprintf(1, ' Popsize: [ positive scalar | {[]} ]\n\n')
fprintf(1, ' Grace: [ positive scalar | {0} ]\n')
fprintf(1, ' Display: [ {on} | off ] \n')
fprintf(1, ' MaxFevals: [ positive scalar | {[]} ]\n')
fprintf(1, ' Maxiters: [ positive scalar | {[]} ]\n')
fprintf(1, ' BestInPop: [ positive scalar | {100} ]\n')
fprintf(1, ' AchieveFval: [ scalar | {[]} ]\n\n')
fprintf(1, ' Flb: [ scalar | {-1.2} ]\n')
fprintf(1, ' Fub: [ scalar | {1.2} ]\n')
fprintf(1, ' Crossconst: [ positive scalar | {0.9} ]\n')
fprintf(1, ' n: [ positive scalar | {10} ]\n\n')
fprintf(1, ' Crossprob: [ positive scalar | {0.5} ]\n')
fprintf(1, ' Mutprob: [ positive scalar | {0.01} ]\n\n')
fprintf(1, ' T0: [ scalar | {1} ]\n')
fprintf(1, ' minT: [ scalar | {1e-8} ]\n')
fprintf(1, ' k: [ scalar | {1} ]\n')
fprintf(1,[' cool: [ function handle | {@(T, T0, minT, maxiters)',...
'(minT/T0)^(1/maxiters)} ]\n\n'])
fprintf(1, ' eta1: [ scalar | {2} ]\n')
fprintf(1, ' eta2: [ scalar | {2} ]\n')
fprintf(1, ' eta3: [ scalar | {0.5} ]\n')
fprintf(1, ' omega: [ scalar | {0.5} ]\n')
fprintf(1, 'numneighbors: [ positive scalar | {5} ]\n\n')
fprintf(1, ' AlgIters: [ positive scalar | {10} ]\n')
fprintf(1, 'PutbackIters: [ positive scalar | {250} ]\n')
fprintf(1, ' SwapIters: [ positive scalar | {25} ]\n\n')
return
end
% create structure with default values if no input is given
if (nargin == 0) && (nargout ~= 0)
problem = struct;
problem.costfun = [];
problem.lb = [];
problem.ub = [];
problem.popsize = [];
problem.grace = 0;
problem.display = true;
problem.maxfevals = 1e6;
problem.conv.method = 'exhaustive';
problem.conv.value = 150;
% differential evolution
problem.DE.pop = [];
problem.DE.Flb = -1.2;
problem.DE.Fub = 1.2;
problem.DE.crossconst = 0.9;
problem.DE.n = 10;
% genetic algorithm
problem.GA.pop = [];
problem.GA.crossprob = 0.5;
problem.GA.mutprob = 0.01;
% simulated annealing
problem.SA.pop = [];
problem.SA.T0 = 1;
problem.SA.minT = 1e-8;
problem.SA.k = 1;
problem.SA.cool = @(T, T0, minT, maxiters) (minT/T0)^(1/maxiters);
% particle swarm
problem.PS.pop = [];
problem.PS.eta1 = 2;
problem.PS.eta2 = 2;
problem.PS.eta3 = 0.5;
problem.PS.omega = 0.5;
problem.PS.numneigh = 5;
% GODLIKE
problem.GODLIKE.swapiters = 10;
problem.GODLIKE.algiters = 250;
problem.GODLIKE.putbackiters = 25;
% otherwise, create structure with fields according to user input
else
% default values
problem = heurset;
% errortrap
if (mod(nargin, 2) ~= 0)
error('Please provide values for all the options.')
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -