Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/de/DEEvaluator.java @ 13229

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

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

File size: 2.6 KB
Line 
1package ec.de;
2
3import ec.*;
4import ec.simple.*;
5
6/*
7 * DEEvaluator.java
8 *
9 * Created: Fri Aug 13 11:20:54 EDT 2010
10 * By: Sean Luke
11 */
12
13/**
14 * DEEvaluator is a simple subclass of SimpleEvaluator which first evaluates the population, then
15 * compares each population member against the parent which had created it in Differential Evolution.
16 * The parents are stored in DEBreeder.previousPopulation.  If the parent is superior to the child,
17 * then the parent replaces the child in the population and the child is discarded.  This does not
18 * happen in the first generation, as there are of course no parents yet.
19 *
20 * <p>This code could have been moved into the Breeder of course.  But then the better of the parents
21 * and children would not appear in standard Statistics objects.  So we've broken it out here.
22 *
23 * <p>The full description of Differential Evolution may be found in the book
24 * "Differential Evolution: A Practical Approach to Global Optimization"
25 * by Kenneth Price, Rainer Storn, and Jouni Lampinen.
26 *
27 * @author Sean Luke
28 * @version 1.0
29 */
30
31public class DEEvaluator extends SimpleEvaluator
32    {
33    public void evaluatePopulation(EvolutionState state)
34        {
35        super.evaluatePopulation(state);
36
37        if( state.breeder instanceof DEBreeder )
38            {
39            Population previousPopulation = ((DEBreeder)(state.breeder)).previousPopulation; // for faster access
40            if( previousPopulation != null )
41                {
42                if( previousPopulation.subpops.length != state.population.subpops.length )
43                    state.output.fatal( "DEEvaluator requires that the population have the same number of subpopulations every generation.");
44                for( int i = 0 ; i < previousPopulation.subpops.length ; i++ )
45                    {
46                    if( state.population.subpops[i].individuals.length != previousPopulation.subpops[i].individuals.length )
47                        state.output.fatal( "DEEvaluator requires that subpopulation " + i + " should have the same number of individuals in all generations." );
48                    for( int j = 0 ; j < state.population.subpops[i].individuals.length ; j++ )
49                        if( previousPopulation.subpops[i].individuals[j].fitness.betterThan( state.population.subpops[i].individuals[j].fitness ) )
50                            state.population.subpops[i].individuals[j] = previousPopulation.subpops[i].individuals[j];
51                    }
52                }
53            }
54        else state.output.fatal("DEEvaluator requires DEBreeder to be the breeder.");
55        }
56    }
Note: See TracBrowser for help on using the repository browser.