From: <sla...@us...> - 2008-08-03 19:03:52
|
Revision: 5211 http://octave.svn.sourceforge.net/octave/?rev=5211&view=rev Author: slackydeb Date: 2008-08-03 19:04:01 +0000 (Sun, 03 Aug 2008) Log Message: ----------- modifying interface of the ga function; it is no more possible to invoke something as ga (fitnessfcn, nvars, options) Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__ga_problem__.m trunk/octave-forge/main/ga/inst/ga.m trunk/octave-forge/main/ga/inst/gaoptimset.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 16:19:44 UTC (rev 5210) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-03 19:04:01 UTC (rev 5211) @@ -1,6 +1,6 @@ Name: ga -Version: 0.3 -Date: 2008-07-23 +Version: 0.4 +Date: 2008-08-03 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Modified: trunk/octave-forge/main/ga/inst/__ga_problem__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-03 16:19:44 UTC (rev 5210) +++ trunk/octave-forge/main/ga/inst/__ga_problem__.m 2008-08-03 19:04:01 UTC (rev 5211) @@ -17,9 +17,9 @@ ## 02110-1301, USA. ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0 +## Version: 4.1 -function x = __ga_problem__ (problem) +function [x fval exitflag output population scores] = __ga_problem__ (problem) individui_migliori = []; Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 16:19:44 UTC (rev 5210) +++ trunk/octave-forge/main/ga/inst/ga.m 2008-08-03 19:04:01 UTC (rev 5211) @@ -44,26 +44,53 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.4 +## Version: 5.0 -function x = ga (varargin) - if ((nargout > 1) || (length (varargin) < 1) || (length (varargin) > 3)) +function [x fval exitflag output population scores] = ga (varargin) + if ((nargout > 6) || + (length (varargin) < 1) || + (length (varargin) == 3) || + (length (varargin) == 5) || + (length (varargin) == 7) || + (length (varargin) > 10)) print_usage (); else - switch (length (varargin)) - case (1) - problem = varargin{1}; - case (2) - problem.fitnessfcn = varargin{1}; - problem.nvars = varargin{2}; - problem.options = gaoptimset; - case (3) - problem.fitnessfcn = varargin{1}; - problem.nvars = varargin{2}; - problem.options = varargin{3}; - endswitch - x = __ga_problem__ (problem); + ## retrieve problem structure + if (length (varargin) == 1) + problem = varargin{1}; + else ## length (varargin) >= 2 + + ## set default options field + problem.options = gaoptimset; + + ## set fields specified + problem.fitnessfcn = varargin{1}; + problem.nvars = varargin{2}; + if (length (varargin) >= 4) + problem.Aineq = varargin{3}; + problem.Bineq = varargin{4}; + if (length (varargin) >= 6) + problem.Aeq = varargin{5}; + problem.Beq = varargin{6}; + if (length (varargin) >= 8) + problem.lb = varargin{7}; + problem.ub = varargin{8}; + if (length (varargin) >= 9) + problem.nonlcon = varargin{9}; + + ## if a custom options field is specified, overwrite the + ## default one + if (length (varargin) == 10) + problem.options = varargin{10}; + endif + endif + endif + endif + endif + endif + + [x fval exitflag output population scores] = __ga_problem__ (problem); endif endfunction @@ -75,21 +102,21 @@ %! retval += (x(3) ** 2) - (cos (2 * pi * x(3))) + 1; %! retval += x(4) ** 2; -%!assert (ga (@test_4_variabili, 4, gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) +%!assert (ga (@test_4_variabili, 4, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) %!function retval = test_rastriginsfcn_traslato (t) %! min = [1, 0]; %! x = t - min; %! retval = 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); -%!assert (ga (@test_rastriginsfcn_traslato, 2, gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) +%!assert (ga (@test_rastriginsfcn_traslato, 2, [], [], [], [], [], [], [], gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-2; 2], 'PopulationSize', 100)), [1, 0], sqrt(0.001)) %!function retval = test_f_con_inf_minimi_locali (x) %! retval = (x ** 2) - (cos (2 * pi * x)) + 1; -%!assert (ga (@test_f_con_inf_minimi_locali, 1, gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) +%!assert (ga (@test_f_con_inf_minimi_locali, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 25, 'PopInitRange', [-5; 5])), 0, sqrt(0.001)) %!function retval = test_parabola (x) %! retval = x ** 2; -%!assert (ga (@test_parabola, 1, gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) \ No newline at end of file +%!assert (ga (@test_parabola, 1, [], [], [], [], [], [], [], gaoptimset ('CrossoverFcn', @crossoversinglepoint, 'EliteCount', 1, 'FitnessLimit', 0.001, 'Generations', 10, 'PopInitRange', [-1; 1])), 0, sqrt(0.001)) \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/gaoptimset.m =================================================================== --- trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-03 16:19:44 UTC (rev 5210) +++ trunk/octave-forge/main/ga/inst/gaoptimset.m 2008-08-03 19:04:01 UTC (rev 5211) @@ -17,8 +17,7 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn{Function File} gaoptimset -## @deftypefnx{Function File} {@var{options} =} gaoptimset +## @deftypefn{Function File} {@var{options} =} gaoptimset ## @deftypefnx{Function File} {@var{options} =} gaoptimset ('@var{param1}', @var{value1}, '@var{param2}', @var{value2}, @dots{}) ## Create genetic algorithm options structure. ## @@ -54,14 +53,11 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 3.3 +## Version: 3.4 function options = gaoptimset (varargin) - if (nargout == 0) - warning ("Should show a complete list of parameters with their arguments."); + if (nargout != 1) print_usage (); - elseif (nargout > 1) - print_usage (); else if (mod (length (varargin), 2) == 1) print_usage (); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |