Last change
on this file since 10677 was
6152,
checked in by bfarka, 14 years ago
|
added ecj and custom statistics to communicate with the okb services #1441
|
File size:
1.2 KB
|
Line | |
---|
1 | /*
|
---|
2 | Copyright 2006 by Sean Luke
|
---|
3 | Licensed under the Academic Free License version 3.0
|
---|
4 | See the file "LICENSE" for more information
|
---|
5 | */
|
---|
6 |
|
---|
7 |
|
---|
8 | package ec.app.tutorial1;
|
---|
9 | import ec.*;
|
---|
10 | import ec.simple.*;
|
---|
11 | import ec.vector.*;
|
---|
12 |
|
---|
13 | public class MaxOnes extends Problem implements SimpleProblemForm
|
---|
14 | {
|
---|
15 | public void evaluate(final EvolutionState state,
|
---|
16 | final Individual ind,
|
---|
17 | final int subpopulation,
|
---|
18 | final int threadnum)
|
---|
19 | {
|
---|
20 | if (ind.evaluated) return;
|
---|
21 |
|
---|
22 | if (!(ind instanceof BitVectorIndividual))
|
---|
23 | state.output.fatal("Whoa! It's not a BitVectorIndividual!!!",null);
|
---|
24 |
|
---|
25 | int sum=0;
|
---|
26 | BitVectorIndividual ind2 = (BitVectorIndividual)ind;
|
---|
27 |
|
---|
28 | for(int x=0; x<ind2.genome.length; x++)
|
---|
29 | sum += (ind2.genome[x] ? 1 : 0);
|
---|
30 |
|
---|
31 | if (!(ind2.fitness instanceof SimpleFitness))
|
---|
32 | state.output.fatal("Whoa! It's not a SimpleFitness!!!",null);
|
---|
33 | ((SimpleFitness)ind2.fitness).setFitness(state,
|
---|
34 | /// ...the fitness...
|
---|
35 | (float)(((double)sum)/ind2.genome.length),
|
---|
36 | ///... is the individual ideal? Indicate here...
|
---|
37 | sum == ind2.genome.length);
|
---|
38 | ind2.evaluated = true;
|
---|
39 | }
|
---|
40 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.