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

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