Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/de/Best1BinDEBreeder.java @ 12147

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

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

File size: 3.8 KB
Line 
1package ec.de;
2
3import ec.*;
4import ec.util.*;
5import ec.vector.*;
6
7/*
8 * Best1BinDEBreeder.java
9 *
10 * Created: Wed Apr 26 17:50:17 2006
11 * By: Liviu Panait
12 */
13
14/**
15 * Best1BinDEBreeder is a differential evolution breeding operator.
16 * The code is derived from a DE algorithm, known as DE/best/1/bin "with uniform jitter",
17 * found on page 140 of
18 * "Differential Evolution: A Practical Approach to Global Optimization"
19 * by Kenneth Price, Rainer Storn, and Jouni Lampinen.
20 *
21 * <p>Best1BinDEBreeder requires that all individuals be DoubleVectorIndividuals.
22 *
23 * <p>In short, the algorithm is as follows.  For each individual in the population, we produce a child
24 * by first selecting the best individual in the population, which we call r0.  We then
25 * select two more (different) individuals, none the original individual nor r0, called r1 and r2.
26 * We then create an individal c, defined as c = r0 + FJitter() * (r1 - r2), where FJitter() is
27 * a per-gene independent random number defined as F + F_NOISE * (random(0,1) - 0.5).  A common value for
28 * F_NOISE is 0.001.  Last, we cross over c with the
29 * original individual and produce a single child, using uniform crossover with gene-independent
30 * crossover probability "Cr".
31 *
32 * <p>This class should be used in conjunction with
33 * DEEvaluator, which allows the children to enter the population only if they're superior to their
34 * parents (the original individuals).  If so, they replace their parents.
35 *
36 * <p><b>Parameters</b><br>
37 * <table>
38 * <tr><td valign=top><i>base.</i><tt>f-noise</tt><br>
39 * <font size=-1>0.0 &lt;= double </font></td>
40 * <td valign=top>The "F_NOISE" jitter value</td></tr>
41 *
42 * </table>
43 *
44 * @author Liviu Panait and Sean Luke
45 * @version 2.0
46 */
47
48public class Best1BinDEBreeder extends DEBreeder
49    {
50    /** limits on uniform noise for F */
51    public double F_NOISE = 0.0;
52       
53    public static final String P_FNOISE = "f-noise";
54       
55    public void setup(final EvolutionState state, final Parameter base)
56        {
57        super.setup(state,base);
58
59        F_NOISE = state.parameters.getDouble(base.push(P_FNOISE), null, 0.0);
60        if ( F_NOISE < 0.0 )
61            state.output.fatal( "Parameter not found, or its value is below 0.0.", base.push(P_FNOISE), null );
62        }
63       
64
65    public DoubleVectorIndividual createIndividual( final EvolutionState state,
66        int subpop,
67        int index,
68        int thread)
69        {
70        Individual[] inds = state.population.subpops[subpop].individuals;
71               
72        DoubleVectorIndividual v = (DoubleVectorIndividual)(inds[index].clone());
73
74        do
75            {
76            // select three indexes different from each other and from that of the current parent
77            int r0, r1, r2;
78            // do
79                    {
80                    r0 = bestSoFarIndex[subpop];
81                    }
82            // while( r0 == index );
83            do
84                {
85                r1 = state.random[thread].nextInt(inds.length);
86                }
87            while( r1 == r0 || r1 == index );
88            do
89                {
90                r2 = state.random[thread].nextInt(inds.length);
91                }
92            while( r2 == r1 || r2 == r0 || r2 == index );
93
94            DoubleVectorIndividual g0 = (DoubleVectorIndividual)(inds[r0]);
95            DoubleVectorIndividual g1 = (DoubleVectorIndividual)(inds[r1]);
96            DoubleVectorIndividual g2 = (DoubleVectorIndividual)(inds[r2]);
97
98            for(int i = 0; i < v.genome.length; i++)
99                v.genome[i] = g0.genome[i] +
100                    (F + state.random[thread].nextDouble() * F_NOISE - (F_NOISE / 2.0)) *
101                    (g1.genome[i] - g2.genome[i]);
102            }
103        while(!valid(v));
104                                       
105        return crossover(state, (DoubleVectorIndividual)(inds[index]), v, thread);
106        }
107
108    }
Note: See TracBrowser for help on using the repository browser.