source: java/ecj/cecj/eval/CoevolutionaryEvaluator.java @ 339

Last change on this file since 339 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.5 KB
Line 
1/*
2  Copyright 2009 by Marcin Szubert
3  Licensed under the Academic Free License version 3.0
4 */
5
6package cecj.eval;
7
8import cecj.problems.CoevolutionaryProblem;
9import cecj.problems.TestBasedProblem;
10import ec.Evaluator;
11import ec.EvolutionState;
12import ec.util.Parameter;
13
14/**
15 * The base class for all coevolutionary evaluators.
16 *
17 * This class is responsible for verifying if problem and population are consistent with the idea of
18 * coevolution.
19 *
20 * @author Marcin Szubert
21 *
22 */
23public abstract class CoevolutionaryEvaluator extends Evaluator {
24
25        private static final String P_POP = "pop";
26        private static final String P_SIZE = "subpops";
27
28        /**
29         * Number of subpopulations.
30         */
31        protected int numSubpopulations;
32
33        @Override
34        public void setup(final EvolutionState state, final Parameter base) {
35                super.setup(state, base);
36
37                if (!(p_problem instanceof CoevolutionaryProblem)) {
38                        state.output
39                                        .fatal("Coevolutionary evaluator is dedicated to coevolutionary problems\n");
40                }
41
42                Parameter popSizeParameter = new Parameter(P_POP).push(P_SIZE);
43                numSubpopulations = state.parameters.getInt(popSizeParameter, null, 0);
44                if (numSubpopulations <= 0) {
45                        state.output.fatal("Population size must be > 0.\n", popSizeParameter);
46                }
47        }
48
49        @Override
50        public boolean runComplete(EvolutionState state) {
51                return false;
52        }
53
54        /**
55         * Returns a problem that forms a base of evaluation of the individuals.
56         *
57         * @return the instance of test-based problem used by this evaluator
58         */
59        public TestBasedProblem getProblem() {
60                return (TestBasedProblem) p_problem;
61        }
62}
Note: See TracBrowser for help on using the repository browser.