]> Creatis software - CreaPhase.git/blob - octave_packages/ga-0.10.0/__ga_scores__.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / ga-0.10.0 / __ga_scores__.m
1 ## Copyright (C) 2008, 2010 Luca Favatella <slackydeb@gmail.com>
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
16 ## Author: Luca Favatella <slackydeb@gmail.com>
17 ## Version: 5.7
18
19 function Scores = __ga_scores__ (problem, Population)
20   [nrP ncP] = size (Population);
21   switch problem.options.Vectorized
22     case "on" ## using vectorized evaluation
23       switch problem.options.UseParallel
24         case "always"
25           warning ("'Vectorized' option is 'on': ignoring 'UseParallel' option, even if it is 'always'");
26         case "never"
27           ## Nothing.
28         otherwise
29           warning ("'Vectorized' option is 'on': ignoring invalid 'UseParallel' option value (it should be 'always' or 'never')");
30       endswitch
31       Scores = (problem.fitnessfcn (Population))(1:nrP, 1);
32     case "off" ## not using vectorized evaluation
33       switch problem.options.UseParallel
34         case "always" ## using parallel evaluation
35           error ("TODO: implement parallel evaluation of objective function");
36         case "never" ## using serial evaluation (i.e. loop)
37           tmp = zeros (nrP, 1);
38           for index = 1:nrP
39             tmp(index, 1) = problem.fitnessfcn (Population(index, 1:ncP));
40           endfor
41           Scores = tmp(1:nrP, 1);
42         otherwise
43           error ("'UseParallel' option must be 'always' or 'never'");
44       endswitch
45     otherwise
46       error ("'Vectorized' option must be 'on' or 'off'");
47   endswitch
48 endfunction