[44] | 1 | /* |
---|
| 2 | Copyright 2009 by Marcin Szubert |
---|
| 3 | Licensed under the Academic Free License version 3.0 |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | package cecj.archive; |
---|
| 7 | |
---|
| 8 | import java.util.ArrayList; |
---|
| 9 | import java.util.List; |
---|
| 10 | |
---|
| 11 | import ec.EvolutionState; |
---|
| 12 | import ec.Individual; |
---|
| 13 | |
---|
| 14 | /** |
---|
| 15 | * Incremental Pareto-Coevolution Archive. |
---|
| 16 | * |
---|
| 17 | * For each of the submitted candidates it is checked if any useful test exists in the archive or |
---|
| 18 | * currently submitted population, that proves the candidate is non-dominated. If such test is |
---|
| 19 | * found, the considered individual is added to the archive while all individuals that it dominates |
---|
| 20 | * are removed. |
---|
| 21 | * |
---|
| 22 | * The implementation relies heavily on the methods provided by the superclass Ð |
---|
| 23 | * <code>PareroCoevolutionArchive</code>. |
---|
| 24 | * |
---|
| 25 | * @author Marcin Szubert |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | public class IPCArchive extends ParetoCoevolutionArchive { |
---|
| 29 | |
---|
| 30 | @Override |
---|
| 31 | protected void submit(EvolutionState state, List<Individual> candidates, |
---|
| 32 | List<Individual> cArchive, List<Individual> tests, List<Individual> tArchive) { |
---|
| 33 | List<Individual> testsCopy = new ArrayList<Individual>(tests); |
---|
| 34 | List<Individual> usefulTests; |
---|
| 35 | |
---|
| 36 | /* |
---|
| 37 | * Is is a right sequence of operations? Dominated candidates are eliminated before new |
---|
| 38 | * tests are added to the test archive. New tests can make yet another candidate dominated.. |
---|
| 39 | */ |
---|
| 40 | for (Individual candidate : candidates) { |
---|
| 41 | if (isUseful(state, candidate, cArchive, tArchive, testsCopy)) { |
---|
| 42 | usefulTests = findUsefulTests(state, candidate, cArchive, tArchive, testsCopy); |
---|
| 43 | eliminateDominatedCandidates(state, candidate, cArchive, tArchive); |
---|
| 44 | |
---|
| 45 | cArchive.add(candidate); |
---|
| 46 | tArchive.addAll(usefulTests); |
---|
| 47 | testsCopy.removeAll(usefulTests); |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | private void eliminateDominatedCandidates(EvolutionState state, Individual candidate, |
---|
| 53 | List<Individual> candidateArchive, List<Individual> testArchive) { |
---|
| 54 | for (int c = candidateArchive.size() - 1; c >= 0; c--) { |
---|
| 55 | if (dominates(state, candidate, candidateArchive.get(c), testArchive)) { |
---|
| 56 | candidateArchive.remove(c); |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | } |
---|