Hi, octave-ga's upstream notified us that the current version in Lenny is in a bad shape and whether we could update it to current SVN, see
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=495489 Now, before you tar and feather me: upstream uses Lenny himself and has tested this version on Lenny. I attach a 'clarified' diffstat: clarified in that I removed changes to comments (line length changes in license texts account for quite some stuff), documentation files and unit tests run at build time. $ diffstat clarified_diff __ga_problem__.m | 49 +----------------------- __ga_stop__.m | 19 +++++---- crossoverscattered.m | 27 ++++++------- ga.m | 58 +++++++++++++++++++--------- gaoptimset.m | 103 ++++++++++----------------------------------------- 5 files changed, 90 insertions(+), 166 deletions(-) There are some new script files in the SVN version, that are not really accounted in the diffstat, but as these are new functions, there's no chance of a regression. Full diff attached. Thanks Thomas
diff -u -r octave-ga-0.1.1/ChangeLog ga-0.9.1~svn20080817/ChangeLog --- octave-ga-0.1.1/ChangeLog 2008-04-29 20:21:44.000000000 +0200 +++ ga-0.9.1~svn20080817/ChangeLog 2008-08-17 13:46:39.000000000 +0200 @@ -1,4 +1,291 @@ # Automatically generated file --- DO NOT EDIT +2008-08-16 18:14 slackydeb + + * DESCRIPTION, inst/__ga_crossoverfcn__.m, + inst/__ga_initial_population__.m, inst/__ga_mutationfcn__.m, + inst/__ga_popinitrange__.m, inst/__ga_problem__.m, + inst/__ga_problem_private_state__.m, + inst/__ga_problem_state_selection__.m, inst/__ga_scores__.m, + inst/__ga_selectionfcn__.m, + inst/__gaoptimset_default_options__.m, inst/crossoverscattered.m, + inst/fitscalingrank.m, inst/ga.m, inst/gacreationuniform.m, + inst/gaoptimset.m, inst/mutationgaussian.m: integrate most debug + asserts as matrix indices or tests; clean and modularize code; + little performance improvement in __ga_problem__ function; little + fixes + +2008-08-15 22:47 slackydeb + + * DESCRIPTION, inst/__ga_initial_population__.m, + inst/__ga_mutationfcn__.m, inst/ga.m, inst/gacreationuniform.m: + cleaned ga function tests; modified the invocation of the + creation function in the __ga_initial_population__ function to + prevent bugs (a modified PopulationSize can be misunderstood by + the creation function); hardcode some expectations removing + asserts + +2008-08-14 15:06 slackydeb + + * DESCRIPTION, INDEX, doc/todo.txt, inst/__ga_crossoverfcn__.m, + inst/__ga_initial_population__.m, inst/__ga_mutationfcn__.m, + inst/__ga_problem__.m, inst/__ga_problem_private_state__.m, + inst/__ga_problem_return_variables__.m, + inst/__ga_problem_state_selection__.m, + inst/__ga_problem_update_state_at_each_generation__.m, + inst/__ga_scores__.m, inst/__ga_selectionfcn__.m, + inst/__ga_stop__.m, inst/__gaoptimset_default_options__.m, + inst/crossoverscattered.m, inst/fitscalingrank.m, inst/ga.m, + inst/gacreationuniform.m, inst/gaoptimset.m, + inst/mutationgaussian.m, inst/rastriginsfcn.m, + inst/selectionstochunif.m: performance gain; fix a bug in + selectionstochunif function; clean license; clean ga function + tests + +2008-08-13 22:12 slackydeb + + * DESCRIPTION, inst/__ga_crossoverfcn__.m, + inst/__ga_mutationfcn__.m, inst/__ga_problem__.m, + inst/__ga_problem_private_state__.m, + inst/__ga_problem_return_variables__.m, + inst/__ga_problem_state_selection__.m, + inst/__ga_problem_update_state_at_each_generation__.m, + inst/__ga_scores__.m, inst/__ga_selectionfcn__.m, + inst/crossoverscattered.m, inst/fitscalingrank.m, + inst/mutationgaussian.m, inst/selectionstochunif.m: modularize to + semplify debug + +2008-08-12 21:37 slackydeb + + * DESCRIPTION, INDEX, doc/old_stuff/__bin2hex__.m, + doc/old_stuff/__bin2num__.m, + doc/old_stuff/__ga_concatenated_bitstring2doubles__.m, + doc/old_stuff/__ga_doubles2concatenated_bitstring__.m, + doc/old_stuff/__hex2bin__.m, doc/old_stuff/__num2bin__.m, + doc/old_stuff/crossoversinglepoint.m, + doc/old_stuff/mutationsinglepoint.m, + doc/old_stuff/selectionroulette.m, inst/__bin2hex__.m, + inst/__bin2num__.m, inst/__ga_concatenated_bitstring2doubles__.m, + inst/__ga_doubles2concatenated_bitstring__.m, + inst/__ga_initial_population__.m, inst/__ga_problem__.m, + inst/__ga_scores__.m, inst/__ga_set_initial_population__.m, + inst/__ga_stop__.m, inst/__gaoptimset_default_options__.m, + inst/__hex2bin__.m, inst/__num2bin__.m, + inst/crossoverscattered.m, inst/crossoversinglepoint.m, + inst/fitscalingrank.m, inst/gacreationuniform.m, + inst/gaoptimset.m, inst/mutationgaussian.m, + inst/mutationsinglepoint.m, inst/selectionroulette.m, + inst/selectionstochunif.m: worse performance; total restructure; + move unmantained files to old_stuff/; add standard functions + +2008-08-11 16:44 slackydeb + + * inst/rastriginsfcn.m: fix a previous commit: add rastriginsfcn + function + +2008-08-11 16:15 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m, inst/fitscalingrank.m: add + fitscalingrank (but not using it); fix a serious bug in elitism + in __ga_problem__ function caused by a previous commit; little + improvements in __ga_problem__ function + +2008-08-10 17:40 slackydeb + + * DESCRIPTION, doc/old_stuff/__ga_sort_ascend_population__.m, + inst/__ga_calcola_img_fitnessfcn__.m, inst/__ga_problem__.m, + inst/__ga_scores__.m, inst/__ga_sort_ascend_population__.m, + inst/__ga_stop__.m, inst/__gaoptimset_default_options__.m, + inst/gaoptimset.m, inst/selectionroulette.m: add TimeLimit + option; clean __ga_stop__ function; clean + __ga_calcola_img_fitnessfcn__ function and rename it to + __ga_scores__; heavily modify __ga_problem__ function; move + __ga_sort_ascend_population__.m script to doc/old_stuff/ folder + +2008-08-09 18:57 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m: better use of the state + structure + +2008-08-08 16:10 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m, + inst/__ga_set_initial_population__.m, inst/crossoverscattered.m, + inst/crossoversinglepoint.m: improve creation functions and tests + +2008-08-08 11:56 slackydeb + + * DESCRIPTION, inst/mutationgaussian.m: improve mutationscattered + +2008-08-07 22:12 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m, inst/mutationgaussian.m: + improve mutationscattered + +2008-08-07 13:21 slackydeb + + * DESCRIPTION, inst/__gaoptimset_default_options__.m, inst/ga.m, + inst/mutationgaussian.m: initial version of mutationgaussian; + switch default MutationFcn from mutationsinglepoint to + mutationgaussian; performance loss because mutationgaussian is + unoptimized + +2008-08-07 11:26 slackydeb + + * inst/__ga_problem__.m, inst/__gaoptimset_default_options__.m: + start using cell for mutation functions + +2008-08-07 08:36 slackydeb + + * DESCRIPTION, inst/__ga_concatenated_bitstring2doubles__.m, + inst/__ga_doubles2concatenated_bitstring__.m, + inst/crossoverscattered.m, inst/crossoversinglepoint.m: clean + crossover functions; bumped version because of new dependency on + communications package, to use the randint function + +2008-08-07 07:39 slackydeb + + * doc/old_stuff, doc/old_stuff/__gaoptimget__.m, + inst/__gaoptimget__.m: move gaoptimget function outside the inst + directory because at the moment it is not mantained + +2008-08-07 07:34 slackydeb + + * DESCRIPTION, inst/crossoverscattered.m, inst/gacreationuniform.m: + changed meaning of crossoverscattered + +2008-08-05 21:14 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m, inst/crossoverscattered.m, + inst/crossoversinglepoint.m, inst/mutationsinglepoint.m: fix + interface in MutationFcn call and function + +2008-08-05 20:48 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m, inst/crossoverscattered.m, + inst/crossoversinglepoint.m: fix interface in Crossoverfcn calls + and functions + +2008-08-05 19:03 slackydeb + + * inst/__ga_problem__.m: remove dead code + +2008-08-05 18:59 slackydeb + + * inst/__ga_set_initial_population__.m, inst/gacreationuniform.m: + little fixes + +2008-08-05 18:48 slackydeb + + * DESCRIPTION, inst/gacreationuniform.m: clean gacreationuniform + +2008-08-05 14:58 slackydeb + + * inst/__ga_set_initial_population__.m: clean the initialization of + the population + +2008-08-05 14:17 slackydeb + + * inst/__gaoptimset_default_options__.m: add + __gaoptimset_default_options__.m (to fix a previous commit) + +2008-08-05 14:08 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m, + inst/__ga_set_initial_population__.m, inst/gacreationuniform.m, + inst/gaoptimset.m: clean the initialization of the population; + initial support for the option InitialPopulation + +2008-08-05 12:24 slackydeb + + * DESCRIPTION, inst/ga.m, inst/gaoptimset.m: semplified the code + +2008-08-05 10:23 slackydeb + + * inst/__gaoptimget__.m, inst/gaoptimget.m: renamed gaoptimget.m to + __gaoptimget__.m (to fix a previous commit) + +2008-08-03 22:15 slackydeb + + * DESCRIPTION, inst/ga.m, inst/gaoptimset.m: doc of functions ga + and gaoptimset improved; gaoptimset reviewed and splitted in 2 + functions + +2008-08-03 20:22 slackydeb + + * DESCRIPTION, inst/ga.m, inst/gaoptimset.m: rewrote the ga + function to be simpler; more fields added to the problem + structure in the function ga + +2008-08-03 19:04 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m, inst/ga.m, inst/gaoptimset.m: + modifying interface of the ga function; it is no more possible to + invoke something as ga (fitnessfcn, nvars, options) + +2008-08-03 16:19 slackydeb + + * DESCRIPTION, inst/__ga_problem__.m, inst/__ga_stop__.m, + inst/gacreationuniform.m: removed gaoptimget function because it + is almost unuseful and too difficult to mantain; modified all + code not to use the removed function; bump version because of + these changes + +2008-08-03 15:00 slackydeb + + * DESCRIPTION: bumped version + +2008-08-03 14:59 slackydeb + + * INDEX, inst/ga.m: moved the definition of a common function to + test ga algorithms in a script file; modified ga.m to take + advantage of it + +2008-07-27 12:41 slackydeb + + * DESCRIPTION, inst/__bin2hex__.m, inst/__hex2bin__.m, + inst/__num2bin__.m: made ga tests working again; bug solved + observing that a double precision number is always 64 bit long + (not less) + +2008-07-24 11:43 slackydeb + + * inst/__bin2num__.m: added tests + +2008-07-24 08:52 slackydeb + + * inst/__bin2hex__.m: added tests + +2008-07-23 21:48 slackydeb + + * inst/__bin2hex__.m, inst/__bin2num__.m, inst/__ga_problem__.m, + inst/__hex2bin__.m, inst/__num2bin__.m, inst/ga.m, + inst/gaoptimget.m, inst/gaoptimset.m: cleaning code + +2008-07-23 13:10 slackydeb + + * DESCRIPTION: update version + +2008-07-23 13:09 slackydeb + + * inst/__bin2hex__.m, inst/__bin2num__.m, + inst/__ga_calcola_img_fitnessfcn__.m, + inst/__ga_concatenated_bitstring2doubles__.m, + inst/__ga_doubles2concatenated_bitstring__.m, + inst/__ga_problem__.m, inst/__ga_sort_ascend_population__.m, + inst/__ga_stop__.m, inst/__hex2bin__.m, inst/__num2bin__.m, + inst/crossoverscattered.m, inst/crossoversinglepoint.m, + inst/ga.m, inst/gacreationuniform.m, inst/gaoptimget.m, + inst/gaoptimset.m, inst/mutationsinglepoint.m, + inst/selectionroulette.m: translation and indentation fixes + +2008-05-07 07:39 slackydeb + + * DESCRIPTION: Depends on the right version of miscellaneous. + +2008-04-29 17:52 hauberg + + * DESCRIPTION: Updated release dates + 2008-03-24 13:54 hauberg * inst/gaoptimget.m: Fix texinfo error diff -u -r octave-ga-0.1.1/DESCRIPTION ga-0.9.1~svn20080817/DESCRIPTION --- octave-ga-0.1.1/DESCRIPTION 2008-04-29 19:38:13.000000000 +0200 +++ ga-0.9.1~svn20080817/DESCRIPTION 2008-08-17 13:29:09.000000000 +0200 @@ -1,12 +1,12 @@ Name: ga -Version: 0.1.1 -Date: 2008-04-29 +Version: 0.9.2 +Date: 2008-08-16 Author: Luca Favatella <[EMAIL PROTECTED]> Maintainer: Luca Favatella <[EMAIL PROTECTED]> Title: Genetic Algorithm and Direct Search Description: Genetic optimization code Categories: Optimization -Depends: octave (>= 2.9.7), miscellaneous (>= 1.0.5) +Depends: octave (>= 2.9.7), communications (>= 1.0.0) Autoload: yes License: GPL version 2 or later Url: http://octave.sf.net diff -u -r octave-ga-0.1.1/INDEX ga-0.9.1~svn20080817/INDEX --- octave-ga-0.1.1/INDEX 2008-04-28 19:08:31.000000000 +0200 +++ ga-0.9.1~svn20080817/INDEX 2008-08-17 13:29:09.000000000 +0200 @@ -1,12 +1,22 @@ ga >> Genetic Algorithm Genetic Algorithm ga - gaoptimget gaoptimset -Utility - crossoverscattered - crossoversinglepoint +Creation gacreationuniform - mutationsinglepoint - selectionroulette + +Fitness Scaling + fitscalingrank + +Selection + selectionstochunif + +Crossover + crossoverscattered + +Mutation + mutationgaussian + +Utility + rastriginsfcn \ No newline at end of file Only in octave-ga-0.1.1/: debian diff -u -r octave-ga-0.1.1/doc/todo.txt ga-0.9.1~svn20080817/doc/todo.txt --- octave-ga-0.1.1/doc/todo.txt 2008-04-28 19:08:30.000000000 +0200 +++ ga-0.9.1~svn20080817/doc/todo.txt 2008-08-17 13:29:09.000000000 +0200 @@ -1,28 +1,5 @@ ##### -fare gacreationuniform come matlab, ma non fare generalizzazione in gaoptimset e get perché octave non sa passare handle di funzione a funzione caricata con handle - -ricontrollare -##### - -##### gaoptimset: -StallGenLimit? -StallTimeLimit? -TimeLimit? //tic toc utile ma non nested - -NO InitialPopulation? //no, consentire solo intervallo -NO PopulationType? //no, solo vettori di double -NO PlotFcns? //no, plot non sono priorita' -NO PlotInterval? //no, solo alla fine -##### - - -##### -eventuale uscita con x,fval oltre che solo x? -##### - - +TimeLimit? //tic toc useful but not nested? ##### -forse matlab fissa pure la frazione di crossover e mutazione, cioè non sceglie l'operatore con probabilità -##### \ No newline at end of file Only in octave-ga-0.1.1/inst: __bin2hex__.m Only in octave-ga-0.1.1/inst: __bin2num__.m Only in octave-ga-0.1.1/inst: __ga_calcola_img_fitnessfcn__.m Only in octave-ga-0.1.1/inst: __ga_concatenated_bitstring2doubles__.m Only in ga-0.9.1~svn20080817/inst: __ga_crossoverfcn__.m Only in octave-ga-0.1.1/inst: __ga_doubles2concatenated_bitstring__.m Only in ga-0.9.1~svn20080817/inst: __ga_initial_population__.m Only in ga-0.9.1~svn20080817/inst: __ga_mutationfcn__.m Only in ga-0.9.1~svn20080817/inst: __ga_popinitrange__.m diff -u -r octave-ga-0.1.1/inst/__ga_problem__.m ga-0.9.1~svn20080817/inst/__ga_problem__.m --- octave-ga-0.1.1/inst/__ga_problem__.m 2008-04-28 19:08:31.000000000 +0200 +++ ga-0.9.1~svn20080817/inst/__ga_problem__.m 2008-08-17 13:29:09.000000000 +0200 @@ -1,67 +1,102 @@ ## Copyright (C) 2008 Luca Favatella <[EMAIL PROTECTED]> ## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. ## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <[EMAIL PROTECTED]> -## Version: 3.1 - -function x = __ga_problem__ (problem) - - %statistica degli individui migliori - individui_migliori = []; +## Version: 5.9 - popolazione = (gaoptimget (problem.options, 'CreationFcn')) (problem.nvars, problem.fitnessfcn, problem.options); +function [x fval exitflag output population scores] = __ga_problem__ (problem) - %dentro questo while la generazione e' fissata - generazione = 1; - individui_migliori(generazione, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :); - while (! __ga_stop__ (problem, popolazione, generazione)) - - %faccio questa inizializzazione qui per rendere la variabile popolazione_futura visibile alla fine del prossimo while - popolazione_futura = zeros (gaoptimget (problem.options, 'PopulationSize'), problem.nvars); - - %elitismo - for i = 1:(gaoptimget (problem.options, 'EliteCount')) - popolazione_futura(i, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(i, :); - endfor - - %dentro questo while l'individuo della nuova generazione e' fissato - for i = (1 + (gaoptimget (problem.options, 'EliteCount'))):(gaoptimget (problem.options, 'PopulationSize')) - - %scelgo l'operatore genetico da applicare in modo probabilistico - aux_operatore = rand (); - - %cross_over - if (aux_operatore < gaoptimget (problem.options, 'CrossoverFraction')) - index_parents = (gaoptimget (problem.options, 'SelectionFcn')) (problem.fitnessfcn, popolazione); - parents = [popolazione(index_parents(1), :); popolazione(index_parents(2), :)]; - popolazione_futura(i, :) = gaoptimget (problem.options, 'CrossoverFcn') (parents); - - %mutazione - else - index_parent = (gaoptimget (problem.options, 'SelectionFcn')) (problem.fitnessfcn, popolazione); - popolazione_futura(i, :) = (gaoptimget (problem.options, 'MutationFcn')) (popolazione(index_parent(1), :)); - endif - endfor - - popolazione = popolazione_futura; - generazione++; - individui_migliori(generazione, :) = (__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :); - endwhile + ## first instruction + state.StartTime = time (); - x = individui_migliori(generazione, :); -endfunction \ No newline at end of file + ## second instruction + output = struct ("randstate", rand ("state"), + "randnstate", randn ("state")); + + ## instructions not to be executed at each generation + state.Population(1:problem.options.PopulationSize, 1:problem.nvars) = \ + __ga_initial_population__ (problem.nvars, + problem.fitnessfcn, + problem.options); + state.Generation = 0; + private_state = __ga_problem_private_state__ (problem.options); + state.Selection = __ga_problem_state_selection__ (private_state, + problem.options); + + ## instructions to be executed at each generation + state = __ga_problem_update_state_at_each_generation__ (state, problem, + private_state); + + NextPopulation = zeros (problem.options.PopulationSize, problem.nvars); + while (! __ga_stop__ (problem, state)) ## fix a generation + + ## elite + if (private_state.ReproductionCount.elite > 0) + [trash IndexSortedScores] = sort (state.Score); + NextPopulation(state.Selection.elite, 1:problem.nvars) = \ + state.Population \ + (IndexSortedScores(1:private_state.ReproductionCount.elite, 1), + 1:problem.nvars); + endif + + ## selection for crossover and mutation + parents(1, 1:private_state.nParents) = __ga_selectionfcn__ \ + (state.Expectation, private_state.nParents, problem.options); + + ## crossover + if (private_state.ReproductionCount.crossover > 0) + NextPopulation(state.Selection.crossover, 1:problem.nvars) = \ + __ga_crossoverfcn__ \ + (parents(1, private_state.parentsSelection.crossover), + problem.options, problem.nvars, problem.fitnessfcn, + false, ## unused + state.Population); + endif + + ## mutation + if (private_state.ReproductionCount.mutation > 0) + NextPopulation(state.Selection.mutation, 1:problem.nvars) = \ + __ga_mutationfcn__ \ + (parents(1, private_state.parentsSelection.mutation), + problem.options, problem.nvars, problem.fitnessfcn, + state, state.Score, + state.Population); + endif + + ## update state structure + state.Population(1:problem.options.PopulationSize, + 1:problem.nvars) = NextPopulation; + state.Generation++; + state = __ga_problem_update_state_at_each_generation__ (state, problem, + private_state); + endwhile + + [x fval exitflag output population scores] = \ + __ga_problem_return_variables__ (state, problem); +endfunction + + #state structure fields + #DONE state.Population + #DONE state.Score + #DONE state.Generation + #DONE state.StartTime + #state.StopFlag + #DONE state.Selection + #DONE state.Expectation + #DONE state.Best + #state.LastImprovement + #state.LastImprovementTime + #state.NonlinIneq + #state.NonlinEq \ No newline at end of file Only in ga-0.9.1~svn20080817/inst: __ga_problem_private_state__.m Only in ga-0.9.1~svn20080817/inst: __ga_problem_return_variables__.m Only in ga-0.9.1~svn20080817/inst: __ga_problem_state_selection__.m Only in ga-0.9.1~svn20080817/inst: __ga_problem_update_state_at_each_generation__.m Only in ga-0.9.1~svn20080817/inst: __ga_scores__.m Only in ga-0.9.1~svn20080817/inst: __ga_selectionfcn__.m Only in octave-ga-0.1.1/inst: __ga_sort_ascend_population__.m diff -u -r octave-ga-0.1.1/inst/__ga_stop__.m ga-0.9.1~svn20080817/inst/__ga_stop__.m --- octave-ga-0.1.1/inst/__ga_stop__.m 2008-04-28 19:08:31.000000000 +0200 +++ ga-0.9.1~svn20080817/inst/__ga_stop__.m 2008-08-17 13:29:09.000000000 +0200 @@ -1,30 +1,39 @@ ## Copyright (C) 2008 Luca Favatella <[EMAIL PROTECTED]> ## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. ## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. +## along with this program; If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn{Function File} [EMAIL PROTECTED] =} __ga_stop__ (@var{problem}, @var{state}) +## Determine whether the genetic algorithm should stop. +## +## @seealso{__ga_problem__} +## @end deftypefn ## Author: Luca Favatella <[EMAIL PROTECTED]> -## Version: 3.1 +## Version: 5.1 + +function stop = __ga_stop__ (problem, state) + Generations = \ + (state.Generation >= problem.options.Generations); -%ritorna true se è stata raggiunta la condizione di stop, false altrimenti -function retval = __ga_stop__ (problem, popolazione, generazione) - __ga_stop_aux1__ = (generazione >= gaoptimget (problem.options, 'Generations')); + TimeLimit = \ + ((time () - state.StartTime) >= problem.options.TimeLimit); - %in doc matlab e' previsto <= e non < - __ga_stop_aux2__ = (problem.fitnessfcn ((__ga_sort_ascend_population__ (problem.fitnessfcn, popolazione))(1, :)) <= gaoptimget (problem.options, 'FitnessLimit')); + FitnessLimit = \ + (state.Best(state.Generation + 1, 1) <= problem.options.FitnessLimit); - retval = (__ga_stop_aux1__ || __ga_stop_aux2__); + stop = (Generations || + TimeLimit || + FitnessLimit); endfunction \ No newline at end of file Only in ga-0.9.1~svn20080817/inst: __gaoptimset_default_options__.m Only in octave-ga-0.1.1/inst: __hex2bin__.m Only in octave-ga-0.1.1/inst: __num2bin__.m diff -u -r octave-ga-0.1.1/inst/crossoverscattered.m ga-0.9.1~svn20080817/inst/crossoverscattered.m --- octave-ga-0.1.1/inst/crossoverscattered.m 2008-04-28 19:08:31.000000000 +0200 +++ ga-0.9.1~svn20080817/inst/crossoverscattered.m 2008-08-17 13:29:09.000000000 +0200 @@ -1,43 +1,37 @@ ## Copyright (C) 2008 Luca Favatella <[EMAIL PROTECTED]> ## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. ## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. - -## -*- texinfo -*- -## @deftypefn{Function File} [EMAIL PROTECTED] =} crossoverscattered (@var{parents}) -## Combine two individuals, or parents, to form a crossover child. -## -## @seealso{ga, gaoptimset} -## @end deftypefn +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <[EMAIL PROTECTED]> -## Version: 3.1 - -%signature diversa da matlab per problema handle funzioni (comunque se piu' tempo da riprovare) -function xoverKids = crossoverscattered (parents) - concatenated_parents = [(__ga_doubles2concatenated_bitstring__ (parents(1, :))); (__ga_doubles2concatenated_bitstring__ (parents(2, :)))]; +## Version: 6.3.1 - %crossover scattered - tmp = concatenated_parents(1, :); - for i = 1:length (tmp) - if (rand () < 0.5) - tmp(1, i) = concatenated_parents(2, i); - endif - endfor - concatenated_xoverKids = tmp; +function xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, + unused, + thisPopulation) - xoverKids = __ga_concatenated_bitstring2doubles__ (concatenated_xoverKids); + ## simplified example (nvars == 4) + ## p1 = [varA varB varC varD] + ## p2 = [var1 var2 var3 var4] + ## b = [1 1 0 1] + ## child1 = [varA varB var3 varD] + nc_parents = columns (parents); + n_children = nc_parents / 2; + p1(1:n_children, 1:nvars) = \ + thisPopulation(parents(1, 1:n_children), 1:nvars); + p2(1:n_children, 1:nvars) = \ + thisPopulation(parents(1, n_children + (1:n_children)), 1:nvars); + b(1:n_children, 1:nvars) = randint (n_children, nvars); + xoverKids(1:n_children, 1:nvars) = \ + b .* p1 + (ones (n_children, nvars) - b) .* p2; endfunction \ No newline at end of file Only in octave-ga-0.1.1/inst: crossoversinglepoint.m Only in ga-0.9.1~svn20080817/inst: fitscalingrank.m diff -u -r octave-ga-0.1.1/inst/ga.m ga-0.9.1~svn20080817/inst/ga.m --- octave-ga-0.1.1/inst/ga.m 2008-04-28 19:08:31.000000000 +0200 +++ ga-0.9.1~svn20080817/inst/ga.m 2008-08-17 13:29:09.000000000 +0200 @@ -1,98 +1,146 @@ ## Copyright (C) 2008 Luca Favatella <[EMAIL PROTECTED]> ## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn{Function File} [EMAIL PROTECTED] =} ga (@var{fitnessfcn}, @var{nvars}) -## @deftypefnx{Function File} [EMAIL PROTECTED] =} ga (@var{fitnessfcn}, @var{nvars}, @var{options}) +## @deftypefnx{Function File} [EMAIL PROTECTED] =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}) +## @deftypefnx{Function File} [EMAIL PROTECTED] =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}, @var{Aeq}, @var{beq}) +## @deftypefnx{Function File} [EMAIL PROTECTED] =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}, @var{Aeq}, @var{beq}, @var{LB}, @var{UB}) +## @deftypefnx{Function File} [EMAIL PROTECTED] =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}, @var{Aeq}, @var{beq}, @var{LB}, @var{UB}, @var{nonlcon}) +## @deftypefnx{Function File} [EMAIL PROTECTED] =} ga (@var{fitnessfcn}, @var{nvars}, @var{A}, @var{b}, @var{Aeq}, @var{beq}, @var{LB}, @var{UB}, @var{nonlcon}, @var{options}) ## @deftypefnx{Function File} [EMAIL PROTECTED] =} ga (@var{problem}) +## @deftypefnx{Function File} [EMAIL PROTECTED], @var{fval}] =} ga (@dots{}) +## @deftypefnx{Function File} [EMAIL PROTECTED], @var{fval}, @var{exitflag}] =} ga (@dots{}) +## @deftypefnx{Function File} [EMAIL PROTECTED], @var{fval}, @var{exitflag}, @var{output}] =} ga (@dots{}) +## @deftypefnx{Function File} [EMAIL PROTECTED], @var{fval}, @var{exitflag}, @var{output}, @var{population}] =} ga (@dots{}) +## @deftypefnx{Function File} [EMAIL PROTECTED], @var{fval}, @var{exitflag}, @var{output}, @var{population}, @var{scores}] =} ga (@dots{}) ## Find minimum of function using genetic algorithm. ## ## @strong{Inputs} ## @table @var ## @item fitnessfcn -## The objective function to minimize. It accepts a vector @var{x} of size [EMAIL PROTECTED], and returns a scalar evaluated at @var{x}. +## The objective function to minimize. It accepts a vector @var{x} of +## size [EMAIL PROTECTED], and returns a scalar evaluated at @var{x}. ## @item nvars -## The number of variables of @var{fitnessfcn}. +## The dimension (number of design variables) of @var{fitnessfcn}. ## @item options -## The structure of the optimization parameters; can be created with using the @code{gaoptimset} function. If not specified, @code{ga} minimizes with the default optimization parameters. +## The structure of the optimization parameters; can be created using +## the @code{gaoptimset} function. If not specified, @code{ga} minimizes +## with the default optimization parameters. ## @item problem -## A structure containing the following fields: @var{fitnessfcn}, @var{nvars} and @var{options}. +## A structure containing the following fields: +## @itemize @bullet +## @item @code{fitnessfcn} +## @item @code{nvars} +## @item @code{Aineq} +## @item @code{Bineq} +## @item @code{Aeq} +## @item @code{Beq} +## @item @code{lb} +## @item @code{ub} +## @item @code{nonlcon} +## @item @code{randstate} +## @item @code{randnstate} +## @item @code{solver} +## @item @code{options} +## @end itemize ## @end table ## ## @strong{Outputs} ## @table @var ## @item x -## The local unconstrained found minimum to the objective function. +## The local unconstrained found minimum to the objective function, +## @var{fitnessfcn}. +## @item fval +## The value of the fitness function at @var{x}. ## @end table ## ## @seealso{gaoptimset} ## @end deftypefn ## Author: Luca Favatella <[EMAIL PROTECTED]> -## Version: 3.1 - -function x = ga (varargin) - if ((nargout > 1) || (length (varargin) <1) || (length (varargin) > 3)) - 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 +## Version: 5.19.2 - x = __ga_problem__ (problem); - endif +function [x fval exitflag output population scores] = \ + ga (fitnessfcn_or_problem, + nvars, + A = [], b = [], + Aeq = [], beq = [], + LB = [], UB = [], + nonlcon = [], + options = gaoptimset ()) + if ((nargout > 6) || + (nargin < 1) || + (nargin == 3) || + (nargin == 5) || + (nargin == 7) || + (nargin > 10)) + print_usage (); + else + + ## retrieve the problem structure + if (nargin == 1) + problem = fitnessfcn_or_problem; + else + problem.fitnessfcn = fitnessfcn_or_problem; + problem.nvars = nvars; + problem.Aineq = A; + problem.Bineq = b; + problem.Aeq = Aeq; + problem.Beq = beq; + problem.lb = LB; + problem.ub = UB; + problem.nonlcon = nonlcon; + problem.randstate = rand ("state"); + problem.randnstate = randn ("state"); + problem.solver = "ga"; + problem.options = options; + endif + + ## call the function that manages the problem structure + [x fval exitflag output population scores] = __ga_problem__ (problem); + endif endfunction -%!function retval = test_4_variabili (x) -%! retval = 0; -%! retval += 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); -%! retval += (x(3) ** 2) - (cos (2 * pi * x(3))) + 1; -%! retval += x(4) ** 2; +%!# nvars == 2 +%!# min != zeros (1, nvars) + +%!xtest +%! min = [-1, 2]; +%! assert (ga (struct ("fitnessfcn", @(x) rastriginsfcn (x - min), "nvars", 2, "options", gaoptimset ("FitnessLimit", 1e-7, "Generations", 1000, "PopInitRange", [-5; 5], "PopulationSize", 200))), min, 1e-6) + + +%!# nvars == 1 +%!# min == zeros (1, nvars) + +%!test assert (ga (@(x) x ** 2, 1), 0, 1e-3) -%!assert (ga (@test_4_variabili, 4, gaoptimset ('FitnessLimit', 0.001, 'PopInitRange', [-1; 1])), [0, 0, 0, 0], sqrt(0.001)) +%!test assert (ga (@(x) (x ** 2) - (cos (2 * pi * x)) + 1, 1), 0, 1e-3) -%!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)) +%!# nvars == 2 +%!# min == zeros (1, nvars) -%!function retval = test_rastriginsfcn (x) -%! retval = 20 + (x(1) ** 2) + (x(2) ** 2) - 10 * (cos (2 * pi * x(1)) + cos (2 * pi * x(2))); +%!xtest assert (ga (@rastriginsfcn, 2), [0, 0], 1e-3) -%!assert (ga (@test_rastriginsfcn, 2), [0, 0], 1e-6) +%!xtest assert (ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("FitnessLimit", 1e-7, "Generations", 1000))), zeros (1, 2), 1e-6) -%!function retval = test_f_con_inf_minimi_locali (x) -%! retval = (x ** 2) - (cos (2 * pi * x)) + 1; +%!xtest assert (ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("FitnessLimit", 1e-7, "PopulationSize", 200))), zeros (1, 2), 1e-6) -%!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; +%!# nvars == 4 +%!# min == zeros (1, nvars) -%!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 +%!xtest assert (ga (struct ("fitnessfcn", @(x) rastriginsfcn (x(1:2)) + ((x(3) ** 2) - (cos (2 * pi * x(3))) + 1) + (x(4) ** 2), "nvars", 4, "options", gaoptimset ("EliteCount", 5, "FitnessLimit", 1e-7, "PopInitRange", [-2; 2], "PopulationSize", 200))), zeros (1, 4), 1e-6) \ No newline at end of file diff -u -r octave-ga-0.1.1/inst/gacreationuniform.m ga-0.9.1~svn20080817/inst/gacreationuniform.m --- octave-ga-0.1.1/inst/gacreationuniform.m 2008-04-28 19:08:31.000000000 +0200 +++ ga-0.9.1~svn20080817/inst/gacreationuniform.m 2008-08-17 13:29:09.000000000 +0200 @@ -1,20 +1,17 @@ ## Copyright (C) 2008 Luca Favatella <[EMAIL PROTECTED]> ## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn{Function File} [EMAIL PROTECTED] =} gacreationuniform (@var{GenomeLength}, @var{FitnessFcn}, @var{options}) @@ -40,15 +37,17 @@ ## @end deftypefn ## Author: Luca Favatella <[EMAIL PROTECTED]> -## Version: 3.0 +## Version: 4.9 function Population = gacreationuniform (GenomeLength, FitnessFcn, options) + [LB(1, 1:GenomeLength) UB(1, 1:GenomeLength)] = \ + __ga_popinitrange__ (options.PopInitRange, GenomeLength); - %variabili d'appoggio - tmp_aux = gaoptimget (options, 'PopInitRange'); - lb = min (tmp_aux(1, 1), tmp_aux(2, 1)); - ub = max (tmp_aux(1, 1), tmp_aux(2, 1)); - - n_rows_aux = gaoptimget (options, 'PopulationSize'); - Population = ((ub - lb) * rand (n_rows_aux, GenomeLength)) + (lb * ones (n_rows_aux, GenomeLength)); + ## pseudocode + ## + ## Population = Delta * RandomPopulationBetween0And1 + Offset + Population(1:options.PopulationSize, 1:GenomeLength) = \ + ((ones (options.PopulationSize, 1) * (UB - LB)) .* \ + rand (options.PopulationSize, GenomeLength)) + \ + (ones (options.PopulationSize, 1) * LB); endfunction \ No newline at end of file Only in octave-ga-0.1.1/inst: gaoptimget.m diff -u -r octave-ga-0.1.1/inst/gaoptimset.m ga-0.9.1~svn20080817/inst/gaoptimset.m --- octave-ga-0.1.1/inst/gaoptimset.m 2008-04-28 19:08:31.000000000 +0200 +++ ga-0.9.1~svn20080817/inst/gaoptimset.m 2008-08-17 13:29:09.000000000 +0200 @@ -1,24 +1,20 @@ ## Copyright (C) 2008 Luca Favatella <[EMAIL PROTECTED]> ## -## -## This program is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2, or (at your option) -## any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; see the file COPYING. If not, write to the Free -## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -## 02110-1301, USA. +## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn{Function File} gaoptimset -## @deftypefnx{Function File} [EMAIL PROTECTED] =} gaoptimset +## @deftypefn{Function File} [EMAIL PROTECTED] =} gaoptimset ## @deftypefnx{Function File} [EMAIL PROTECTED] =} gaoptimset ('@var{param1}', @var{value1}, '@var{param2}', @var{value2}, @dots{}) ## Create genetic algorithm options structure. ## @@ -33,7 +29,8 @@ ## @strong{Outputs} ## @table @var ## @item options -## The options structure. +## Structure that contains the options, or parameters, for the generic +## algorithm. ## @end table ## ## @strong{Options} @@ -43,100 +40,43 @@ ## @item CrossoverFraction ## @item EliteCount ## @item FitnessLimit +## @item FitnessScalingFcn ## @item Generations +## @item InitialPopulation +## @item InitialScores ## @item MutationFcn ## @item PopInitRange ## @item PopulationSize ## @item SelectionFcn +## @item TimeLimit ## @end table ## ## @seealso{ga, gaoptimget} ## @end deftypefn ## Author: Luca Favatella <[EMAIL PROTECTED]> -## Version: 3.0 +## Version: 4.4.1 function options = gaoptimset (varargin) - if (nargout == 0) - warning ("Dovrei mostrare una lista completa dei parametri con i loro argomenti."); - print_usage (); - elseif (nargout > 1) - print_usage (); - else - if (mod (length (varargin), 2) == 1) - print_usage (); - else - %definisco una struttura default_options con tutti i campi di default - default_options.CreationFcn = @gacreationuniform; - default_options.CrossoverFcn = @crossoverscattered; - default_options.CrossoverFraction = 0.8; - default_options.EliteCount = 2; - default_options.FitnessLimit = -Inf; - default_options.Generations = 100; - default_options.MutationFcn = @mutationsinglepoint; - default_options.PopInitRange = [0; 1]; - default_options.PopulationSize = 20; - default_options.SelectionFcn = @selectionroulette; - - %setto nella variabile di ritorno options i parametri specificati in ingresso alla funzione - i = 1; - while (length (varargin) >= (i + 1)) - switch (varargin{i}) - case 'CreationFcn' - options.CreationFcn = varargin{i + 1}; - case 'CrossoverFcn' - options.CrossoverFcn = varargin{i + 1}; - case 'CrossoverFraction' - options.CrossoverFraction = varargin{i + 1}; - case 'EliteCount' - options.EliteCount = varargin{i + 1}; - case 'FitnessLimit' - options.FitnessLimit = varargin{i + 1}; - case 'Generations' - options.Generations = varargin{i + 1}; - case 'MutationFcn' - options.MutationFcn = varargin{i + 1}; - case 'PopInitRange' - options.PopInitRange = varargin{i + 1}; - case 'PopulationSize' - options.PopulationSize = varargin{i + 1}; - case 'SelectionFcn' - options.SelectionFcn = varargin{i + 1}; - endswitch - i = i + 2; - endwhile - - %setto con i valori di default i parametri non settati - if ((! exist ('options', 'var')) || (! isfield (options, 'CreationFcn'))) - options.CreationFcn = default_options.CreationFcn; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'CrossoverFcn'))) - options.CrossoverFcn = default_options.CrossoverFcn; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'CrossoverFraction'))) - options.CrossoverFraction = default_options.CrossoverFraction; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'EliteCount'))) - options.EliteCount = default_options.EliteCount; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'FitnessLimit'))) - options.FitnessLimit = default_options.FitnessLimit; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'Generations'))) - options.Generations = default_options.Generations; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'MutationFcn'))) - options.MutationFcn = default_options.MutationFcn; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'PopInitRange'))) - options.PopInitRange = default_options.PopInitRange; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'PopulationSize'))) - options.PopulationSize = default_options.PopulationSize; - endif - if ((! exist ('options', 'var')) || (! isfield (options, 'SelectionFcn'))) - options.SelectionFcn = default_options.SelectionFcn; - endif - endif - endif + if ((nargout != 1) || + (mod (length (varargin), 2) == 1)) + print_usage (); + else + + ## initialize the return variable to a structure with all parameters + ## set to their default value + options = __gaoptimset_default_options__ (); + + ## set custom options + for i = 1:2:length (varargin) + param = varargin{i}; + value = varargin{i + 1}; + if (! isfield (options, param)) + error ("wrong parameter"); + else + options = setfield (options, param, value); + endif + i = i + 2; + endfor + endif endfunction \ No newline at end of file Only in ga-0.9.1~svn20080817/inst: mutationgaussian.m Only in octave-ga-0.1.1/inst: mutationsinglepoint.m Only in ga-0.9.1~svn20080817/inst: rastriginsfcn.m Only in octave-ga-0.1.1/inst: selectionroulette.m Only in ga-0.9.1~svn20080817/inst: selectionstochunif.m

