source: java/ecj/cecj/archive/CoevolutionaryArchive.java @ 288

Last change on this file since 288 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.6 KB
RevLine 
[44]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.eval.TDLImprovingEvaluator;
12
13import ec.EvolutionState;
14import ec.Individual;
15import ec.Setup;
16import ec.util.Parameter;
17
18/**
19 * The abstract class representing any archive used with coevolutionary algorithm. Archive
20 * mechanisms play 3 important roles during the course of evolution:
21 *
22 * <ul>
23 * <li>
24 * provide genetic material for future generations - archival individual can be chosen as parents of
25 * future generations; this feature is implemented by coevolutionary breeding pipelines</li>
26 * <li>
27 * improve fitness evaluation of individuals in the population - they can interact with individuals
28 * sampled from the archive; this feature is implemented in <code>ArchivingEvaluator</code></li>
29 * <li>
30 * approximate desired solution concept - while population performs exploration of solution space,
31 * archive is aimed at storing the most promising individuals with respect to implemented solution
32 * concept; this feature is implemented by this class and its subclasses.</li>
33 * </ul>
34 *
35 * Archives are incorporated into <code>ArchivingSubpopulation</code> objects and there are stored
36 * archival individuals of the same species as the original population. In subclasses of
37 * <code>CoevolutionaryArchive</code> only the method specifying how archives should be updated is
38 * defined.
39 *
40 * @author Marcin Szubert
41 *
42 */
43public abstract class CoevolutionaryArchive implements Setup {
44
45        private static final String P_POP = "pop";
46        private static final String P_SIZE = "subpops";
47
48        /**
49         * Number of coevolving populations.
50         */
51        protected int numSubpopulations;
52
53        /**
54         * Checks if <code>ArchivingCoevolutionaryEvaluator</code> is used and reads the number of
55         * populations from the configuration.
56         */
57        public void setup(EvolutionState state, Parameter base) {
58                if (!(state.evaluator instanceof ArchivingCoevolutionaryEvaluator)
59                                && !(state.evaluator instanceof TDLImprovingEvaluator)) {
60                        state.output.fatal("This archive can be used only with ArchivingEvaluator.\n");
61                }
62
63                Parameter popSizeParameter = new Parameter(P_POP).push(P_SIZE);
64                numSubpopulations = state.parameters.getInt(popSizeParameter, null, 0);
65        }
66
67        /**
68         * Gets the list of archival individuals from given subpopulation.
69         *
70         * @param state
71         *            the current evolution state
72         * @param subpop
73         *            the index of subpopulation
74         * @return the list of archival individuals of the subpopulation
75         */
76        protected List<Individual> getArchive(EvolutionState state, int subpop) {
77                ArchivingSubpopulation subpopulation = (ArchivingSubpopulation) state.population.subpops[subpop];
78                return subpopulation.getArchivalIndividuals();
79        }
80
81        /**
82         * Gets the list of individuals from given subpopulation.
83         *
84         * @param state
85         *            the current evolution state
86         * @param subpop
87         *            the index of subpopulation
88         * @return the list of current individuals in the subpopulation
89         */
90        protected List<Individual> getIndividuals(EvolutionState state, int subpop) {
91                ArchivingSubpopulation subpopulation = (ArchivingSubpopulation) state.population.subpops[subpop];
92                return subpopulation.getIndividuals();
93        }
94
95        /**
96         * The main method of this class which is responsible by updating individuals in all archives
97         * basing on the current evolution state, specifically on new individuals in populations
98         * generated by coevolution process.
99         *
100         * @param state
101         *            the current evolution state
102         */
103        public abstract void submit(EvolutionState state);
104}
Note: See TracBrowser for help on using the repository browser.