Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/app/tutorial3/OddRosenbrock.java @ 7611

Last change on this file since 7611 was 6152, checked in by bfarka, 14 years ago

added ecj and custom statistics to communicate with the okb services #1441

File size: 1.6 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
8package ec.app.tutorial3;
9
10import ec.util.*;
11import ec.*;
12import ec.simple.*;
13import ec.vector.*;
14
15public class OddRosenbrock extends Problem implements SimpleProblemForm
16    {
17    public void setup(final EvolutionState state, final Parameter base) { }
18
19    public void evaluate(final EvolutionState state,
20        final Individual ind,
21        final int subpopulation,
22        final int threadnum)
23        {
24        if( !( ind instanceof DoubleVectorIndividual ) )
25            state.output.fatal( "The individuals for this problem should be DoubleVectorIndividuals." );
26
27        double[] genome = ((DoubleVectorIndividual)ind).genome;
28        int len = genome.length;
29        double value = 0;
30
31        // Compute the Rosenbrock function for our genome
32        for( int i = 1 ; i < len ; i++ )
33            value += 100*(genome[i-1]*genome[i-1]-genome[i])*
34                (genome[i-1]*genome[i-1]-genome[i]) +
35                (1-genome[i-1])*(1-genome[i-1]);
36
37        // Rosenbrock is a minimizing function which does not drop below 0.
38        // But SimpleFitness requires a maximizing function -- where 0 is worst
39        // and 1 is best.  To use SimpleFitness, we must convert the function.
40        // This is the Koza style of doing it:
41
42        value = 1.0 / ( 1.0 + value );
43        ((SimpleFitness)(ind.fitness)).setFitness( state, (float)value, value==1.0 );
44   
45        ind.evaluated = true;
46        }
47    }
Note: See TracBrowser for help on using the repository browser.