-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOurMutatorPipeline.java
More file actions
56 lines (45 loc) · 1.98 KB
/
OurMutatorPipeline.java
File metadata and controls
56 lines (45 loc) · 1.98 KB
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
50
51
52
53
54
55
56
import ec.BreedingPipeline;
import ec.EvolutionState;
import ec.Individual;
import ec.util.Parameter;
import ec.vector.IntegerVectorIndividual;
import ec.vector.IntegerVectorSpecies;
import ec.vector.VectorDefaults;
import java.util.ArrayList;
import java.util.HashMap;
public class OurMutatorPipeline extends BreedingPipeline
{
public static final String P_OURMUTATION = "our-mutation";
public Parameter defaultBase() { return VectorDefaults.base().push(P_OURMUTATION); }
public static final int NUM_SOURCES = 1;
// Return: we only use one source
public int numSources() { return NUM_SOURCES; }
public int produce(final int min,
final int max,
final int subpopulation,
final ArrayList<Individual> individual,
final EvolutionState state,
final int thread, HashMap<String, Object> map)
{
int start = individual.size();
int n = sources[0].produce(min, max, subpopulation, individual, state, thread, map);
if (!state.random[thread].nextBoolean(likelihood))
{
return n;
}
if (!(individual.get(start) instanceof IntegerVectorIndividual))
state.output.fatal("OurMutatorPipeline didn't get an IntegerVectorIndividual." +
"The offending individual is in subpopulation " + subpopulation + " and it's:" + individual.get(start));
IntegerVectorSpecies species = (IntegerVectorSpecies)(individual.get(start).species);
for(int q = start; q < n + start; q++)
{
IntegerVectorIndividual i = (IntegerVectorIndividual)individual.get(q);
for(int x = 0; x < i.genome.length; x++)
if (state.random[thread].nextBoolean(species.mutationProbability(x)))
i.genome[x] = -i.genome[x];
// it's a "new" individual, so it's no longer been evaluated
i.evaluated = false;
}
return n;
}
}