Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/es/MuPlusLambdaBreeder.java @ 12912

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

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

File size: 2.3 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.es;
9import ec.*;
10
11/*
12 * MuPlusLambdaBreeder.java
13 *
14 * Created: Thu Sep  7 18:49:42 2000
15 * By: Sean Luke
16 */
17
18/**
19 * MuPlusLambdaBreeder is a subclass of MuCommaLambdaBreeder which, together with
20 * ESSelection, implements the (mu + lambda) breeding strategy and gathers
21 * the comparison data you can use to implement a 1/5-rule mutation mechanism.
22 * Note that MuPlusLambdaBreeder increases subpopulation sizes by their mu
23 * values in the second generation and keep them at that size thereafter.
24 * See MuCommaLambdaBreeder for information about how to set mu and lambda.
25 *
26 * @author Sean Luke
27 * @version 1.0
28 */
29
30public class MuPlusLambdaBreeder extends MuCommaLambdaBreeder
31    {
32    /** Sets all subpopulations in pop to the expected mu+lambda size.  Does not fill new slots with individuals. */
33    public Population setToMuPlusLambda(Population pop, EvolutionState state)
34        {
35        for(int x=0;x<pop.subpops.length;x++)
36            {
37            int s = mu[x]+lambda[x];
38           
39            // check to see if the array's big enough
40            if (pop.subpops[x].individuals.length != s)
41                // need to increase
42                {
43                Individual[] newinds = new Individual[s];
44                System.arraycopy(pop.subpops[x].individuals,0,newinds,0,
45                    s < pop.subpops[x].individuals.length ?
46                    s : pop.subpops[x].individuals.length);
47                pop.subpops[x].individuals = newinds;
48                }
49            }
50        return pop;
51        }
52
53    public Population postProcess(Population newpop, Population oldpop, EvolutionState state)
54        {
55        // first we need to expand newpop to mu+lambda in size
56        newpop = setToMuPlusLambda(newpop,state);
57       
58        // now we need to dump the old population into the high end of the new population
59         
60        for(int x=0;x<newpop.subpops.length;x++)
61            {
62            for(int y=0;y<mu[x];y++)
63                {
64                newpop.subpops[x].individuals[y+lambda[x]] =
65                    (Individual)(oldpop.subpops[x].individuals[y].clone());
66                }
67            }
68        return newpop;
69        }
70    }
Note: See TracBrowser for help on using the repository browser.