1 | package de.uka.ipd.sdq.dsexplore.opt4j.representation; |
2 | |
3 | import static org.opt4j.core.Individual.State.EMPTY; |
4 | |
5 | import org.opt4j.core.Individual; |
6 | import org.opt4j.core.IndividualBuilder; |
7 | import org.opt4j.operator.mutate.AdaptiveMutationRate; |
8 | import org.opt4j.start.Constant; |
9 | |
10 | /** |
11 | * The {@link AdaptiveMutationRate} always uses a mutation rate of 1 / (genome length). In this |
12 | * class, the ratio can be configured by a factor mutationIntensity, so that the |
13 | * final mutation rate is min(1, 1 / (genome length) * mutationIntensity). The higher the mutation intensity, |
14 | * the closer the mutation rate comes to 1. If the mutation intensity is larger than the genome length, then |
15 | * the mutation rate is capped to 1. |
16 | * |
17 | * A mutation intensity smaller than 1 leads to less mutation that in the {@link AdaptiveMutationRate}. |
18 | * A mutation intensity larger than 1 leads to more mutation than in the {@link AdaptiveMutationRate}. |
19 | * |
20 | * @author martens |
21 | * |
22 | */ |
23 | public class ConfigurableAdaptiveMutationRate extends AdaptiveMutationRate { |
24 | |
25 | private double mutationIntensity = 1; |
26 | |
27 | public ConfigurableAdaptiveMutationRate(IndividualBuilder individualBuilder, |
28 | @Constant(value = "intensity", namespace = ConfigurableAdaptiveMutationRate.class) double intensity) { |
29 | super(individualBuilder); |
30 | this.mutationIntensity = intensity; |
31 | } |
32 | |
33 | |
34 | /* |
35 | * (non-Javadoc) |
36 | * |
37 | * @see |
38 | * org.opt4j.core.IndividualStateListener#inidividualStateChanged(org.opt4j |
39 | * .core.Individual) |
40 | */ |
41 | public synchronized void inidividualStateChanged(Individual individual) { |
42 | if (!isInit && individual.getState() != EMPTY) { |
43 | final int size = individual.getGenotype().size(); |
44 | if (size > 0) { |
45 | set(Math.min(1.0, 1.0 / individual.getGenotype().size() * mutationIntensity)); |
46 | } |
47 | individualBuilder.removeIndividualStateListener(this); |
48 | isInit = true; |
49 | } |
50 | } |
51 | |
52 | |
53 | public void setMutationIntensity(double mutationIntensity) { |
54 | this.mutationIntensity = mutationIntensity; |
55 | } |
56 | |
57 | |
58 | public double getMutationIntensity() { |
59 | return mutationIntensity; |
60 | } |
61 | |
62 | } |