source: java/ecj/cecj/archive/CandidateTestArchive.java @ 28

Last change on this file since 28 was 28, checked in by mszubert, 15 years ago

cecj - coEvolutionary Computation in Java with additional games package

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.0 KB
Line 
1package cecj.archive;
2
3import java.util.List;
4
5import cecj.eval.ArchivingCoevolutionaryEvaluator;
6import cecj.interaction.LearnerTeacherInteractionScheme;
7import cecj.interaction.LearnerTeacherInteractionScheme.Role;
8import cecj.problems.TestBasedProblem;
9
10import ec.EvolutionState;
11import ec.Individual;
12import ec.util.Parameter;
13
14/**
15 * Represents archive dedicated for learner-teacher coevolution, where two distinct roles can be
16 * distinguished. The first one (leaner) represents candidate solution to the problem and it is
17 * rewarded for performing well on tests which are representatives of the second role (teacher).
18 *
19 * It requires <code>LearnerTeacherInteractionScheme</code> and <code>TestBasedProblem</code>
20 * definition.
21 *
22 * @author Marcin Szubert
23 *
24 */
25public abstract class CandidateTestArchive extends CoevolutionaryArchive {
26
27        /**
28         * The interaction scheme between coevolving populations.
29         */
30        protected LearnerTeacherInteractionScheme interactionScheme;
31
32        /**
33         * Problem which determines the interaction form between candidates and tests.
34         */
35        protected TestBasedProblem problem;
36
37        @Override
38        public void setup(EvolutionState state, Parameter base) {
39                super.setup(state, base);
40
41                ArchivingCoevolutionaryEvaluator e = (ArchivingCoevolutionaryEvaluator) state.evaluator;
42                if (!(e.getInteractionScheme() instanceof LearnerTeacherInteractionScheme)) {
43                        state.output
44                                .fatal("This archive can be used only with learner-teacher interaction scheme.\n");
45                }
46                interactionScheme = (LearnerTeacherInteractionScheme) e.getInteractionScheme();
47                problem = e.getProblem();
48        }
49
50        @Override
51        public void submit(EvolutionState state) {
52                List<Integer> candidatePops = interactionScheme.getSubpopulationIndices(Role.LEARNER);
53                List<Integer> testPops = interactionScheme.getSubpopulationIndices(Role.TEACHER);
54                for (int candidatePop : candidatePops) {
55                        List<Individual> cArchive = getArchive(state, candidatePop);
56                        List<Individual> candidates = getIndividuals(state, candidatePop);
57                        for (int testPop : testPops) {
58                                List<Individual> tArchive = getArchive(state, testPop);
59                                List<Individual> tests = getIndividuals(state, testPop);
60                                submit(state, candidates, cArchive, tests, tArchive);
61                        }
62                }
63        }
64
65        /**
66         * Submits new candidates and tests to the archives. The role of the archive is to determine
67         * which individuals of both roles are useful and should be kept in the archive. It is possible
68         * also to remove some existing individual because new one is strictly better.
69         *
70         * @param state
71         *            the current evolution state
72         * @param candidates
73         *            the list of newly generated candidate soluions
74         * @param cArchive
75         *            the list of archival candidate solutions
76         * @param tests
77         *            the list of newly generated tests
78         * @param tArchive
79         *            the list of archival tests
80         */
81        protected abstract void submit(EvolutionState state, List<Individual> candidates,
82                        List<Individual> cArchive, List<Individual> tests, List<Individual> tArchive);
83}
Note: See TracBrowser for help on using the repository browser.