source: java/ecj/cecj/interaction/IntraPopulationInteractionScheme.java @ 1114

Last change on this file since 1114 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: 1.4 KB
Line 
1package cecj.interaction;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import cecj.problems.SymmetricCompetitionProblem;
7
8import ec.EvolutionState;
9import ec.Individual;
10import ec.util.Parameter;
11
12/**
13 *
14 *
15 * @author Marcin Szubert
16 *
17 */
18public class IntraPopulationInteractionScheme implements InteractionScheme {
19
20        private SymmetricCompetitionProblem problem;
21
22        public void setup(EvolutionState state, Parameter base) {
23                if (!(state.evaluator.p_problem instanceof SymmetricCompetitionProblem)) {
24                        state.output.fatal("Intrapopulation interactions need symmetric problem definition\n");
25                } else {
26                        problem = (SymmetricCompetitionProblem) state.evaluator.p_problem;
27                }
28        }
29
30        public List<List<InteractionResult>> performInteractions(EvolutionState state, int subpop,
31                        List<List<Individual>> opponents) {
32
33                List<List<InteractionResult>> subpopulationResults = new ArrayList<List<InteractionResult>>();
34                Individual[] competitors = state.population.subpops[subpop].individuals;
35                List<Individual> curOpponents = opponents.get(subpop);
36
37                for (Individual competitor : competitors) {
38                        List<InteractionResult> results = new ArrayList<InteractionResult>();
39                        for (Individual opponent : curOpponents) {
40                                results.add(problem.compete(state, competitor, opponent).first);
41                                results.add(problem.compete(state, opponent, competitor).second);
42                        }
43                        subpopulationResults.add(results);
44                }
45
46                return subpopulationResults;
47        }
48}
Note: See TracBrowser for help on using the repository browser.