1 | package framsticks;
|
---|
2 |
|
---|
3 | import java.io.DataInput;
|
---|
4 | import java.io.DataOutput;
|
---|
5 | import java.io.IOException;
|
---|
6 |
|
---|
7 | import ec.EvolutionState;
|
---|
8 | import ec.Individual;
|
---|
9 | import ec.util.Parameter;
|
---|
10 |
|
---|
11 | public class FramsticksIndividual extends Individual {
|
---|
12 |
|
---|
13 | public static final String P_FRAMSTICKS_INDIVIDUAL = "framssticks-ind";
|
---|
14 |
|
---|
15 | public String genotype;
|
---|
16 |
|
---|
17 | @Override
|
---|
18 | public boolean equals(Object ind) {
|
---|
19 | if (!this.getClass().equals(ind.getClass())) {
|
---|
20 | return false;
|
---|
21 | }
|
---|
22 |
|
---|
23 | FramsticksIndividual framsticksIndividual = (FramsticksIndividual) ind;
|
---|
24 | return genotype.equals(framsticksIndividual.genotype);
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public int hashCode() {
|
---|
29 | int hash = this.getClass().hashCode();
|
---|
30 | hash = (hash << 1 | hash >>> 31) ^ genotype.hashCode();
|
---|
31 | return hash;
|
---|
32 | }
|
---|
33 |
|
---|
34 | public Parameter defaultBase() {
|
---|
35 | return FramsticksDefaults.base().push(P_FRAMSTICKS_INDIVIDUAL);
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public void setup(final EvolutionState state, final Parameter base) {
|
---|
40 | super.setup(state, base);
|
---|
41 | genotype = FramsticksUtils.getInstance(state).getNewGenotype();
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | public Object clone() {
|
---|
46 | FramsticksIndividual clone = (FramsticksIndividual) (super.clone());
|
---|
47 | clone.genotype = genotype;
|
---|
48 | return clone;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public void mutate(final EvolutionState state) {
|
---|
52 | genotype = FramsticksUtils.getInstance(state).mutateGenotype(genotype);
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void crossover(final EvolutionState state, FramsticksIndividual other) {
|
---|
56 | genotype = FramsticksUtils.getInstance(state).crossoverGenotypes(genotype, other.genotype);
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public String genotypeToStringForHumans() {
|
---|
61 | return genotype;
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public void writeGenotype(EvolutionState state, DataOutput dataOutput) throws IOException {
|
---|
66 | dataOutput.writeUTF(genotype);
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public void readGenotype(EvolutionState state, DataInput dataInput) throws IOException {
|
---|
71 | genotype = dataInput.readUTF();
|
---|
72 | }
|
---|
73 | }
|
---|