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