1 | package cecj.archive; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import ec.EvolutionState; |
---|
7 | import ec.Individual; |
---|
8 | |
---|
9 | public class IPCArchive extends ParetoCoevolutionArchive { |
---|
10 | |
---|
11 | @Override |
---|
12 | protected void submit(EvolutionState state, List<Individual> candidates, |
---|
13 | List<Individual> cArchive, List<Individual> tests, List<Individual> tArchive) { |
---|
14 | List<Individual> testsCopy = new ArrayList<Individual>(tests); |
---|
15 | List<Individual> usefulTests; |
---|
16 | |
---|
17 | /* |
---|
18 | * Is is a right sequence of operations? Dominated candidates are eliminated before new |
---|
19 | * tests are added to the test archive. New tests can make yet another candidate dominated.. |
---|
20 | */ |
---|
21 | for (Individual candidate : candidates) { |
---|
22 | if (isUseful(state, candidate, cArchive, tArchive, testsCopy)) { |
---|
23 | usefulTests = findUsefulTests(state, candidate, cArchive, tArchive, testsCopy); |
---|
24 | eliminateDominatedCandidates(state, candidate, cArchive, tArchive); |
---|
25 | |
---|
26 | cArchive.add(candidate); |
---|
27 | tArchive.addAll(usefulTests); |
---|
28 | testsCopy.removeAll(usefulTests); |
---|
29 | } |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | private void eliminateDominatedCandidates(EvolutionState state, Individual candidate, |
---|
34 | List<Individual> candidateArchive, List<Individual> testArchive) { |
---|
35 | for (int c = candidateArchive.size() - 1; c >= 0; c--) { |
---|
36 | if (dominates(state, candidate, candidateArchive.get(c), testArchive)) { |
---|
37 | candidateArchive.remove(c); |
---|
38 | } |
---|
39 | } |
---|
40 | } |
---|
41 | } |
---|