[44] | 1 | package framsticks;
|
---|
| 2 |
|
---|
| 3 | import ec.EvolutionState;
|
---|
| 4 | import ec.Individual;
|
---|
| 5 | import ec.Species;
|
---|
| 6 | import ec.util.Parameter;
|
---|
| 7 |
|
---|
| 8 | public class FramsticksSpecies extends Species {
|
---|
| 9 |
|
---|
| 10 | public static final String P_FRAMSTICKSSPECIES = "species";
|
---|
| 11 | public final static String P_MUTATIONPROB = "mutation-prob";
|
---|
| 12 | public final static String P_CROSSOVERPROB = "crossover-prob";
|
---|
| 13 |
|
---|
| 14 | public float mutationProbability;
|
---|
| 15 | public float crossoverProbability;
|
---|
| 16 |
|
---|
| 17 | public Parameter defaultBase() {
|
---|
| 18 | return FramsticksDefaults.base().push(P_FRAMSTICKSSPECIES);
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | @Override
|
---|
| 22 | public void setup(final EvolutionState state, final Parameter base) {
|
---|
| 23 | Parameter def = defaultBase();
|
---|
| 24 |
|
---|
| 25 | mutationProbability = state.parameters.getFloat(base.push(P_MUTATIONPROB), def
|
---|
| 26 | .push(P_MUTATIONPROB), 0.0, 1.0);
|
---|
| 27 | if (mutationProbability == -1.0)
|
---|
| 28 | state.output
|
---|
| 29 | .error(
|
---|
| 30 | "FramsticksSpecies must have a mutation probability between 0.0 and 1.0 inclusive",
|
---|
| 31 | base.push(P_MUTATIONPROB), def.push(P_MUTATIONPROB));
|
---|
| 32 |
|
---|
| 33 | crossoverProbability = state.parameters.getFloat(base.push(P_CROSSOVERPROB), def
|
---|
| 34 | .push(P_CROSSOVERPROB), 0.0, 1.0);
|
---|
| 35 | if (crossoverProbability == -1.0)
|
---|
| 36 | state.output
|
---|
| 37 | .error(
|
---|
| 38 | "FramsticksSpecies must have a crossover probability between 0.0 and 1.0 inclusive",
|
---|
| 39 | base.push(P_CROSSOVERPROB), def.push(P_CROSSOVERPROB));
|
---|
| 40 |
|
---|
| 41 | state.output.exitIfErrors();
|
---|
| 42 | super.setup(state, base);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | @Override
|
---|
| 46 | public Individual newIndividual(final EvolutionState state, int thread) {
|
---|
| 47 | FramsticksIndividual newind = (FramsticksIndividual) (super.newIndividual(state, thread));
|
---|
| 48 | newind.mutate(state);
|
---|
| 49 | return newind;
|
---|
| 50 | }
|
---|
| 51 | }
|
---|