From: <sla...@us...> - 2008-08-07 08:36:33
|
Revision: 5226 http://octave.svn.sourceforge.net/octave/?rev=5226&view=rev Author: slackydeb Date: 2008-08-07 08:36:41 +0000 (Thu, 07 Aug 2008) Log Message: ----------- clean crossover functions; bumped version because of new dependency on communications package, to use the randint function Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/crossoverscattered.m trunk/octave-forge/main/ga/inst/crossoversinglepoint.m Added Paths: ----------- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m Removed Paths: ------------- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-08-07 08:36:41 UTC (rev 5226) @@ -1,12 +1,12 @@ Name: ga -Version: 0.4.9 +Version: 0.5.0 Date: 2008-08-07 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Title: Genetic Algorithm and Direct Search Description: Genetic optimization code Categories: Optimization -Depends: octave (>= 2.9.7), miscellaneous (>= 1.0.6) +Depends: octave (>= 2.9.7), miscellaneous (>= 1.0.6), communications (>= 1.0.0) Autoload: yes License: GPL version 2 or later Url: http://octave.sf.net Deleted: trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -1,39 +0,0 @@ -## Copyright (C) 2008 Luca Favatella <sla...@gm...> -## -## -## 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. -## -## 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. - -## Author: Luca Favatella <sla...@gm...> -## Version: 3.3 - -function doubles = __ga_concatenated_bitstring2doubles__ (concatenated_bitstring) - - %% constants - N_BIT_DOUBLE = 64; - - %% aux variable - nvars = length (concatenated_bitstring) / N_BIT_DOUBLE; - - %% obtaining the son of the bitstring - tmp1 = zeros (1, nvars); - for i = 1:nvars - tmp_aux = (i - 1) * N_BIT_DOUBLE; - tmp1(i) = __bin2num__ (concatenated_bitstring((tmp_aux + 1): - (tmp_aux + N_BIT_DOUBLE))); - endfor - - doubles = tmp1; -endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -0,0 +1,39 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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. +## +## 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. + +## Author: Luca Favatella <sla...@gm...> +## Version: 3.3 + +function doubles = __ga_concatenated_bitstring2doubles__ (concatenated_bitstring) + + %% constants + N_BIT_DOUBLE = 64; + + %% aux variable + nvars = length (concatenated_bitstring) / N_BIT_DOUBLE; + + %% obtaining the son of the bitstring + tmp1 = zeros (1, nvars); + for i = 1:nvars + tmp_aux = (i - 1) * N_BIT_DOUBLE; + tmp1(i) = __bin2num__ (concatenated_bitstring((tmp_aux + 1): + (tmp_aux + N_BIT_DOUBLE))); + endfor + + doubles = tmp1; +endfunction \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/inst/__ga_concatenated_bitstring2doubles__.m ___________________________________________________________________ Added: svn:mergeinfo + Deleted: trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -1,31 +0,0 @@ -## Copyright (C) 2008 Luca Favatella <sla...@gm...> -## -## -## 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. -## -## 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. - -## Author: Luca Favatella <sla...@gm...> -## Version: 3.3 - -function concatenated_bitstring = __ga_doubles2concatenated_bitstring__ (doubles) - - %% bitstring obtained concating the bitstrings of the single variables - tmp1 = __num2bin__ (doubles(1)); - for i = 2:length(doubles) %% 2:1 is an empty matrix - tmp1 = strcat (tmp1, __num2bin__ (doubles(i))); - endfor - - concatenated_bitstring = tmp1; -endfunction \ No newline at end of file Added: trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m (rev 0) +++ trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -0,0 +1,31 @@ +## Copyright (C) 2008 Luca Favatella <sla...@gm...> +## +## +## 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. +## +## 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. + +## Author: Luca Favatella <sla...@gm...> +## Version: 3.3 + +function concatenated_bitstring = __ga_doubles2concatenated_bitstring__ (doubles) + + %% bitstring obtained concating the bitstrings of the single variables + tmp1 = __num2bin__ (doubles(1)); + for i = 2:length(doubles) %% 2:1 is an empty matrix + tmp1 = strcat (tmp1, __num2bin__ (doubles(i))); + endfor + + concatenated_bitstring = tmp1; +endfunction \ No newline at end of file Property changes on: trunk/octave-forge/main/ga/inst/__ga_doubles2concatenated_bitstring__.m ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/octave-forge/main/ga/inst/crossoverscattered.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/inst/crossoverscattered.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -24,22 +24,21 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 5.0.1 +## Version: 5.1.1 function xoverKids = \ crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation) - ## example + ## example (nvars == 4) ## p1 = [varA varB varC varD] ## p2 = [var1 var2 var3 var4] ## b = [1 1 0 1] ## child1 = [varA varB var3 varD] - p1 = parents (1, 1:nvars); - p2 = parents (2, 1:nvars); - b = fix (rand (1, nvars) + - 0.5 * ones (1, nvars)); + p1 = parents(1, 1:nvars); + p2 = parents(2, 1:nvars); + b = randint (1, nvars); child1 = b .* p1 + (ones (1, nvars) - b) .* p2; xoverKids = child1; @@ -49,7 +48,7 @@ %! parents = [0 4.3 51 -6; 3 -34 5 64.212]; %! options = gaoptimset (); %! nvars = 4; -%! FitnessFcn = @rastriginsfcn; +%! FitnessFcn = false; ## this parameter is unused in the current implementation %! unused = false; %! thisPopulation = false; ## this parameter is unused in the current implementation %! xoverKids = crossoverscattered (parents, options, nvars, FitnessFcn, unused, thisPopulation); Modified: trunk/octave-forge/main/ga/inst/crossoversinglepoint.m =================================================================== --- trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-07 07:39:10 UTC (rev 5225) +++ trunk/octave-forge/main/ga/inst/crossoversinglepoint.m 2008-08-07 08:36:41 UTC (rev 5226) @@ -24,32 +24,33 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 4.0.2 +## Version: 5.1.1 function xoverKids = \ crossoversinglepoint (parents, options, nvars, FitnessFcn, unused, thisPopulation) - %% constants - N_BIT_DOUBLE = 64; + ## example (nvars == 4) + ## p1 = [varA varB varC varD] + ## p2 = [var1 var2 var3 var4] + ## n = 1 ## integer between 1 and nvars + ## child1 = [varA var2 var3 var4] + p1 = parents(1, 1:nvars); + p2 = parents(2, 1:nvars); + n = randint (1, 1, [1, nvars]); + child1 = horzcat (p1(1, 1:n), + p2(1, n+1:nvars)); - %% aux variable - nvars = columns (parents); + xoverKids = child1; +endfunction - concatenated_parents = [(__ga_doubles2concatenated_bitstring__ (parents(1, :))); - (__ga_doubles2concatenated_bitstring__ (parents(2, :)))]; - - %% n is the single point of the crossover - %% - %% n can be from 1 to ((N_BIT_DOUBLE * nvars) - 1) - n = double (uint64 ((((nvars * N_BIT_DOUBLE) - 2) * rand ()) + 1)); - - %% single point crossover - concatenated_xoverKids = strcat (substr (concatenated_parents (1, :), - 1, n), - substr (concatenated_parents (2, :), - (n + 1))); - - xoverKids = __ga_concatenated_bitstring2doubles__ (concatenated_xoverKids); -endfunction \ No newline at end of file +%!test +%! parents = [0 4.3 51 -6; 3 -34 5 64.212]; +%! options = gaoptimset (); +%! nvars = 4; +%! FitnessFcn = false; ## this parameter is unused in the current implementation +%! unused = false; +%! thisPopulation = false; ## this parameter is unused in the current implementation +%! xoverKids = crossoversinglepoint (parents, options, nvars, FitnessFcn, unused, thisPopulation); +%! assert (size (xoverKids), [1, nvars]); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |