aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/backend/modules/mutator/FixedPointMutator.java
blob: 1efdd2f8bfec6fc45dbda7c292bc54d2d2215ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package jcgp.backend.modules.mutator;

import jcgp.backend.parameters.BooleanParameter;
import jcgp.backend.parameters.IntegerParameter;
import jcgp.backend.parameters.ParameterStatus;
import jcgp.backend.resources.Resources;

/**
 * Fixed point mutator
 * <br><br>
 * This operator uses the point mutator 
 * algorithm to mutate a user-defined fixed
 * number of genes.
 * 
 * 
 * @see PointMutator
 * @author Eduardo Pedroni
 *
 */
public class FixedPointMutator extends PointMutator {

	/**
	 * Creates a new instance of FixedPointMutator. 
	 * 
	 * @param resources a reference to the experiment's resources.
	 */
	public FixedPointMutator(final Resources resources) {
		super(resources);
		genesMutated = new IntegerParameter(5, "Genes mutated", false, false) {
			@Override
			public void validate(Number newValue) {
				if (newValue.intValue() <= 0) {
					status = ParameterStatus.INVALID;
					status.setDetails("At least 1 mutation must take place.");
				} else if (newValue.intValue() > (resources.nodes() * (resources.arity() + 1)) + resources.outputs()) {
					status = ParameterStatus.WARNING;
					status.setDetails("More genes are mutated than there are genes in the genotype.");
				} else {
					status = ParameterStatus.VALID;
				}
			}
		};
		
		report = new BooleanParameter(false, "Report");
		
		setName("Fixed point mutation");
		registerParameters(genesMutated, report);
	}
}