changeset 9847:d0a89bfd8417 octave-forge

ga: fix failing unit test A non-vectorized objective function must not work when vectorization is required.
author slackydeb
date Sat, 24 Mar 2012 16:34:10 +0000
parents 6b76ad220e06
children 3c079f238951
files main/ga/inst/__ga_scores__.m
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/main/ga/inst/__ga_scores__.m	Sat Mar 24 16:33:56 2012 +0000
+++ b/main/ga/inst/__ga_scores__.m	Sat Mar 24 16:34:10 2012 +0000
@@ -14,9 +14,10 @@
 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
 
 ## Author: Luca Favatella <slackydeb@gmail.com>
-## Version: 5.6
+## Version: 5.7
 
 function Scores = __ga_scores__ (problem, Population)
+  [nrP ncP] = size (Population);
   switch problem.options.Vectorized
     case "on" ## using vectorized evaluation
       switch problem.options.UseParallel
@@ -27,13 +28,12 @@
         otherwise
           warning ("'Vectorized' option is 'on': ignoring invalid 'UseParallel' option value (it should be 'always' or 'never')");
       endswitch
-      Scores = problem.fitnessfcn (Population);
+      Scores = (problem.fitnessfcn (Population))(1:nrP, 1);
     case "off" ## not using vectorized evaluation
       switch problem.options.UseParallel
         case "always" ## using parallel evaluation
           error ("TODO: implement parallel evaluation of objective function");
         case "never" ## using serial evaluation (i.e. loop)
-          [nrP ncP] = size (Population);
           tmp = zeros (nrP, 1);
           for index = 1:nrP
             tmp(index, 1) = problem.fitnessfcn (Population(index, 1:ncP));