[193] | 1 | package framsticks; |
---|
| 2 | |
---|
| 3 | import ec.BreedingPipeline; |
---|
| 4 | import ec.EvolutionState; |
---|
| 5 | import ec.Individual; |
---|
| 6 | import ec.util.Parameter; |
---|
| 7 | |
---|
| 8 | public class FramsticksCrossoverPipeline extends BreedingPipeline { |
---|
| 9 | |
---|
| 10 | public static final String P_CROSSOVER = "xover"; |
---|
| 11 | public static final int NUM_SOURCES = 2; |
---|
| 12 | |
---|
| 13 | public boolean tossSecondParent; |
---|
| 14 | FramsticksIndividual parents[]; |
---|
| 15 | |
---|
| 16 | public FramsticksCrossoverPipeline() { |
---|
| 17 | parents = new FramsticksIndividual[2]; |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | @Override |
---|
| 21 | public int numSources() { |
---|
| 22 | return NUM_SOURCES; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | @Override |
---|
| 26 | public int produce(int min, int max, int start, int subpopulation, Individual[] inds, |
---|
| 27 | EvolutionState state, int thread) { |
---|
| 28 | int n = typicalIndsProduced(); |
---|
| 29 | n = Math.max(Math.min(n, max), min); |
---|
| 30 | |
---|
| 31 | for (int i = start; i < n + start; i++) { |
---|
| 32 | if (sources[0] == sources[1]) { |
---|
| 33 | sources[0].produce(2, 2, 0, subpopulation, parents, state, thread); |
---|
| 34 | if (!(sources[0] instanceof BreedingPipeline)) { |
---|
| 35 | parents[0] = (FramsticksIndividual) (parents[0].clone()); |
---|
| 36 | parents[1] = (FramsticksIndividual) (parents[1].clone()); |
---|
| 37 | } |
---|
| 38 | } else { |
---|
| 39 | sources[0].produce(1, 1, 0, subpopulation, parents, state, thread); |
---|
| 40 | sources[1].produce(1, 1, 1, subpopulation, parents, state, thread); |
---|
| 41 | if (!(sources[0] instanceof BreedingPipeline)) { |
---|
| 42 | parents[0] = (FramsticksIndividual) (parents[0].clone()); |
---|
| 43 | } |
---|
| 44 | if (!(sources[1] instanceof BreedingPipeline)) { |
---|
| 45 | parents[1] = (FramsticksIndividual) (parents[1].clone()); |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | parents[0].crossover(state, parents[1]); |
---|
| 50 | parents[0].evaluated = false; |
---|
| 51 | |
---|
| 52 | inds[i] = parents[0]; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | return n; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | public Parameter defaultBase() { |
---|
| 59 | return FramsticksDefaults.base().push(P_CROSSOVER); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | @Override |
---|
| 63 | public Object clone() { |
---|
| 64 | FramsticksCrossoverPipeline clone = (FramsticksCrossoverPipeline) (super.clone()); |
---|
| 65 | clone.parents = parents.clone(); |
---|
| 66 | return clone; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | } |
---|