From: <sla...@us...> - 2012-03-24 16:32:59
|
Revision: 10027 http://octave.svn.sourceforge.net/octave/?rev=10027&view=rev Author: slackydeb Date: 2012-03-24 16:32:50 +0000 (Sat, 24 Mar 2012) Log Message: ----------- ga: restructure __ga_scores__ for better error handling Modified Paths: -------------- trunk/octave-forge/main/ga/inst/__ga_scores__.m Modified: trunk/octave-forge/main/ga/inst/__ga_scores__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__ga_scores__.m 2012-03-24 16:32:37 UTC (rev 10026) +++ trunk/octave-forge/main/ga/inst/__ga_scores__.m 2012-03-24 16:32:50 UTC (rev 10027) @@ -14,30 +14,35 @@ ## along with this program; If not, see <http://www.gnu.org/licenses/>. ## Author: Luca Favatella <sla...@gm...> -## 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |