source: java/ecj/cecj/statistics/AverageSubjectiveFitnessChartStatistics.java @ 1326

Last change on this file since 1326 was 193, checked in by Maciej Komosinski, 11 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 1.3 KB
RevLine 
[44]1package cecj.statistics;
2
3import ec.EvolutionState;
4import ec.display.chart.XYSeriesChartStatistics;
5import ec.util.Parameter;
6
7public class AverageSubjectiveFitnessChartStatistics extends XYSeriesChartStatistics {
8
9        private static final String P_POP = "pop";
10        private static final String P_SIZE = "subpops";
11
12        private int numSubpopulations;
13        private int[] seriesID;
14
15        @Override
16        public void setup(EvolutionState state, Parameter base) {
17                super.setup(state, base);
18
19                Parameter popSizeParameter = new Parameter(P_POP).push(P_SIZE);
20                numSubpopulations = state.parameters.getInt(popSizeParameter, null, 0);
21                seriesID = new int[numSubpopulations];
22
23                for (int i = 0; i < numSubpopulations; ++i) {
24                        seriesID[i] = addSeries("SubPop " + i);
25                }
26        }
27
28        @Override
29        public void postEvaluationStatistics(EvolutionState state) {
30                super.postEvaluationStatistics(state);
31
32                for (int subPop = 0; subPop < numSubpopulations; ++subPop) {
33                        double averageFitness = 0;
34                        for (int i = 0; i < state.population.subpops[subPop].individuals.length; ++i) {
35                                averageFitness += state.population.subpops[subPop].individuals[i].fitness.fitness();
36                        }
37                        averageFitness /= state.population.subpops[subPop].individuals.length;
38
39                        addDataPoint(seriesID[subPop], state.generation, averageFitness);
40                }
41        }
42}
Note: See TracBrowser for help on using the repository browser.