* Bug #13425 fixed - optim_ga and optim moga needed optimization. 80/14580/5
Michael BAUDIN [Wed, 28 May 2014 08:42:37 +0000 (10:42 +0200)]
Change-Id: I02d6cf8f130d33459b8adc6ad3be384d18bd9314

scilab/CHANGES_5.5.X
scilab/modules/genetic_algorithms/macros/optim_ga.sci
scilab/modules/genetic_algorithms/macros/optim_moga.sci

index 6458ce5..e9ac823 100644 (file)
@@ -110,6 +110,8 @@ Scilab Bug Fixes
 * Bug #13409 fixed - permute(x, dims) failed when dims was greater than the dimensions of size(x)
                      now permute treats extra dimensions as 1.
 
+* Bug #13425 fixed - optim_ga and optim_moga needed optimization.
+
 * Bug #13435 fixed - Windows version crashes when calling xmlRemove on the first child.
 
 * Bug #13438 fixed - drawaxis did not return the handle of the created axis.
index abeea03..3f4fa1f 100644 (file)
@@ -1,5 +1,6 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - Yann COLLETTE <yann.collette@renault.com>
+// Copyright (C) 2014 - Michael Baudin <michael.baudin@contrib.scilab.org>
 //
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
@@ -91,19 +92,14 @@ function [pop_opt, fobj_pop_opt, pop_init, fobj_pop_init] = optim_ga(ga_f, pop_s
         Wheel = cumsum(Efficiency);
         for j=1:nb_couples
             // Selection of the first individual in the couple
-            Shoot = grand(1,1,"def")*Wheel($);
-            Index = 1;
-            while((Wheel(Index)<Shoot)&(Index<length(Wheel)))
-                Index = Index + 1;
-            end
+            Shoot = grand(1,1,"unf", 0, Wheel($));
+            Index = find(Shoot <= Wheel, 1);
             Indiv1(j)      = Pop(Index);
             FObj_Indiv1(j) = FObj_Pop(Index);
             // Selection of the second individual in the couple
-            Shoot = grand(1,1,"def")*Wheel($);
+            Shoot = grand(1,1,"unf", 0, Wheel($));
             Index = 1;
-            while((Wheel(Index)<Shoot)&(Index<length(Wheel)))
-                Index = Index + 1;
-            end
+            Index = find(Shoot <= Wheel, 1);
             Indiv2(j)      = Pop(Index);
             FObj_Indiv2(j) = FObj_Pop(Index);
         end
index 91f098b..fd0a36b 100644 (file)
@@ -1,5 +1,6 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - Yann COLLETTE <yann.collette@renault.com>
+// Copyright (C) 2014 - Michael Baudin <michael.baudin@contrib.scilab.org>
 //
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
@@ -101,19 +102,13 @@ function [pop_opt, fobj_pop_opt, pop_init, fobj_pop_init] = optim_moga(ga_f, pop
         Wheel = cumsum(Efficiency);
         for j=1:nb_couples
             // Selection of the first individual in the couple
-            Shoot = grand(1,1,"def")*Wheel($);
-            Index = 1;
-            while((Wheel(Index)<Shoot)&(Index<length(Wheel)))
-                Index = Index + 1;
-            end
+            Shoot = grand(1,1,"unf", 0, Wheel($));
+            Index = find(Shoot <= Wheel, 1);
             Indiv1(j)           = Pop(Index);
             MO_FObj_Indiv1(j,:) = MO_FObj_Pop(Index,:);
             // Selection of the second individual in the couple
-            Shoot = grand(1,1,"def")*Wheel($);
-            Index = 1;
-            while((Wheel(Index)<Shoot)&(Index<length(Wheel)))
-                Index = Index + 1;
-            end
+            Shoot = grand(1,1,"unf", 0, Wheel($));
+            Index = find(Shoot <= Wheel, 1);
             Indiv2(j)           = Pop(Index);
             MO_FObj_Indiv2(j,:) = MO_FObj_Pop(Index,:);
         end