diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jcgp/backend/modules/mutator/PercentPointMutator.java | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/jcgp/backend/modules/mutator/PercentPointMutator.java b/src/jcgp/backend/modules/mutator/PercentPointMutator.java index 015edf4..ed36f30 100644 --- a/src/jcgp/backend/modules/mutator/PercentPointMutator.java +++ b/src/jcgp/backend/modules/mutator/PercentPointMutator.java @@ -33,7 +33,11 @@ public class PercentPointMutator extends PointMutator { mutationRate = new DoubleParameter(10, "Percent mutation", false, false) { @Override public void validate(Number newValue) { - genesMutated.set((int) ((newValue.intValue()) * (((((double) resources.nodes() + resources.outputs()))) / 100))); + + int totalGenes = (resources.nodes() * (resources.arity() + 1)) + resources.outputs(); + int mutations = (int) (newValue.doubleValue() * (double) (totalGenes / 100.0)); + genesMutated.set(mutations); + if (newValue.doubleValue() <= 0 || newValue.doubleValue() > 100) { status = ParameterStatus.INVALID; status.setDetails("Mutation rate must be > 0 and <= 100"); |