source: java/ecj/framsticks/FramsticksIndividual.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1package framsticks;
2
3import java.io.DataInput;
4import java.io.DataOutput;
5import java.io.IOException;
6
7import ec.EvolutionState;
8import ec.Individual;
9import ec.util.Parameter;
10
11public class FramsticksIndividual extends Individual {
12
13        private static final String P_FRAMSTICKS_INDIVIDUAL = "framsticks-ind";
14        private static final String P_INIT_TYPE = "init-type";
15
16        public String genotype;
17
18        @Override
19        public boolean equals(Object ind) {
20                if (!this.getClass().equals(ind.getClass())) {
21                        return false;
22                }
23
24                FramsticksIndividual framsticksIndividual = (FramsticksIndividual) ind;
25                return genotype.equals(framsticksIndividual.genotype);
26        }
27
28        @Override
29        public int hashCode() {
30                int hash = this.getClass().hashCode();
31                hash = (hash << 1 | hash >>> 31) ^ genotype.hashCode();
32                return hash;
33        }
34
35        public Parameter defaultBase() {
36                return FramsticksDefaults.base().push(P_FRAMSTICKS_INDIVIDUAL);
37        }
38
39        @Override
40        public void setup(final EvolutionState state, final Parameter base) {
41                super.setup(state, base);
42               
43                Parameter initTypeParam = base.push(P_INIT_TYPE);
44                int initializationType = state.parameters.getIntWithDefault(initTypeParam, null, 0);
45                genotype = FramsticksUtils.getInstance(state).getNewGenotype(initializationType);
46        }
47
48        @Override
49        public Object clone() {
50                FramsticksIndividual clone = (FramsticksIndividual) (super.clone());
51                clone.genotype = genotype;
52                return clone;
53        }
54
55        public void mutate(final EvolutionState state) {
56                genotype = FramsticksUtils.getInstance(state).mutateGenotype(genotype);
57        }
58
59        public void crossover(final EvolutionState state, FramsticksIndividual other) {
60                genotype = FramsticksUtils.getInstance(state).crossoverGenotypes(genotype, other.genotype);
61        }
62
63        @Override
64        public String genotypeToStringForHumans() {
65                return genotype;
66        }
67
68        @Override
69        public void writeGenotype(EvolutionState state, DataOutput dataOutput) throws IOException {
70                dataOutput.writeUTF(genotype);
71        }
72
73        @Override
74        public void readGenotype(EvolutionState state, DataInput dataInput) throws IOException {
75                genotype = dataInput.readUTF();
76        }
77}
Note: See TracBrowser for help on using the repository browser.