1 ## Copyright (C) 2008, 2009, 2010 Luca Favatella <slackydeb@gmail.com>
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn{Function File} {@var{options} =} gaoptimset
18 ## @deftypefnx{Function File} {@var{options} =} gaoptimset ('@var{param1}', @var{value1}, '@var{param2}', @var{value2}, @dots{})
19 ## Create genetic algorithm options structure.
24 ## Parameter to set. Unspecified parameters are set to their default
25 ## values; specifying no parameters is allowed.
27 ## Value of @var{param}.
33 ## Structure containing the options, or parameters, for the genetic algorithm.
40 ## @item CrossoverFraction
43 ## @item FitnessScalingFcn
45 ## @item InitialPopulation
47 ## @item InitialScores
48 ## column vector | [] (default) . Can be partial.
51 ## @item PopulationSize
55 ## "always" | "never" (default) . Parallel evaluation of objective function. TODO: parallel evaluation of nonlinear constraints
57 ## "on" | "off" (default) . Vectorized evaluation of objective function. TODO: vectorized evaluation of nonlinear constraints
63 ## Author: Luca Favatella <slackydeb@gmail.com>
66 function options = gaoptimset (varargin)
68 (mod (length (varargin), 2) == 1))
72 ## initialize the return variable to a structure with all parameters
73 ## set to their default value
74 options = __gaoptimset_default_options__ ();
77 for i = 1:2:length (varargin)
79 value = varargin{i + 1};
80 if (! isfield (options, param))
81 error ("wrong parameter");
83 options = setfield (options, param, value);
90 ## number of input arguments
91 %!error options = gaoptimset ("odd number of arguments")
92 %!error options = gaoptimset ("Generations", 123, "odd number of arguments")
94 ## number of output arguments
95 %!error gaoptimset ("Generations", 123)
96 %!error [a, b] = gaoptimset ("Generations", 123)
100 %!#error options = gaoptimset ("Vectorized", "bad value") # TODO: fix
101 %!#error options = gaoptimset ("UseParallel", "bad value") # TODO: fix
103 # TODO: structure/add tests below
105 %!assert (getfield (gaoptimset ("Generations", 123), "Generations"), 123)
108 %! options = gaoptimset ("EliteCount", 1,
109 %! "FitnessLimit", 1e-7,
110 %! "Generations", 1000,
111 %! "PopInitRange", [-5; 5],
112 %! "PopulationSize", 200);
114 %! ## "CrossoverFraction" is not specified, so gaoptimset should put the default value: testing this too
115 %! assert ([(getfield (options, "CrossoverFraction"));
116 %! (getfield (options, "EliteCount"));
117 %! (getfield (options, "FitnessLimit"));
118 %! (getfield (options, "Generations"));
119 %! (getfield (options, "PopInitRange"));
120 %! (getfield (options, "PopulationSize"))],
121 %! [0.8; 1; 1e-7; 1000; [-5; 5]; 200])