changeset 9841:68a47b65f41b octave-forge

ga: restructure __ga_scores__ for better error handling
author slackydeb
date Sat, 24 Mar 2012 16:32:50 +0000
parents f21fb48bc6a0
children 2ceac224d860
files main/ga/inst/__ga_scores__.m
diffstat 1 files changed, 29 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/main/ga/inst/__ga_scores__.m	Sat Mar 24 16:32:37 2012 +0000
+++ b/main/ga/inst/__ga_scores__.m	Sat Mar 24 16:32:50 2012 +0000
@@ -14,30 +14,35 @@
 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
 
 ## Author: Luca Favatella <slackydeb@gmail.com>
-## Version: 5.5.2
+## Version: 5.6
 
 function Scores = __ga_scores__ (problem, Population)
-  if (strcmp (problem.options.Vectorized, "on")) ## using vectorized evaluation
-    if (strcmp (problem.options.UseParallel, "always"))
-      warning ("'Vectorized' option is 'on': ignoring 'UseParallel' option, even if it is 'always'");
-    endif
-    Scores = problem.fitnessfcn (Population);
-  else ## not using vectorized evaluation
-    if (! strcmp (problem.options.Vectorized, "off"))
+  switch problem.options.Vectorized
+    case "on" ## using vectorized evaluation
+      switch problem.options.UseParallel
+        case "always"
+          warning ("'Vectorized' option is 'on': ignoring 'UseParallel' option, even if it is 'always'");
+        case "never"
+          ## Nothing.
+        otherwise
+          warning ("'Vectorized' option is 'on': ignoring invalid 'UseParallel' option value (it should be 'always' or 'never')");
+      endswitch
+      Scores = problem.fitnessfcn (Population);
+    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));
+          endfor
+          Scores = tmp(1:nrP, 1);
+        otherwise
+          error ("'UseParallel' option must be 'always' or 'never'");
+      endswitch
+    otherwise
       error ("'Vectorized' option must be 'on' or 'off'");
-    endif
-    if (strcmp (problem.options.UseParallel, "always")) ## using parallel evaluation
-      error ("TODO: implement parallel evaluation of objective function");
-    else ## using serial evaluation (i.e. loop)
-      if (! strcmp (problem.options.UseParallel, "never"))
-        error ("'UseParallel' option must be 'always' or 'never'");
-      endif
-      [nrP ncP] = size (Population);
-      tmp = zeros (nrP, 1);
-      for index = 1:nrP
-        tmp(index, 1) = problem.fitnessfcn (Population(index, 1:ncP));
-      endfor
-      Scores = tmp(1:nrP, 1);
-    endif
-  endif
-endfunction
\ No newline at end of file
+  endswitch
+endfunction