Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/es/ESSelection.java @ 10501

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

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

File size: 4.5 KB
RevLine 
[6152]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.*;
10import ec.util.*;
11
12/*
13 * ESSelection.java
14 *
15 * Created: Thu Sep  7 19:08:19 2000
16 * By: Sean Luke
17 */
18
19/**
20 * ESSelection is a special SelectionMethod designed to be used with
21 * evolutionary strategies-type breeders.
22 *
23 * <p>To do evolution strategies evolution, the
24 * breeding pipelines should contain at least one ESSelection selection method.
25 * While a child is being generated by the pipeline, the ESSelection object will return a parent
26 * from the pool of mu parents.  The particular parent is chosen round-robin, so all the parents
27 * will have an equal number of children.  It's perfectly fine to have more than one ESSelection
28 * object in the tree, or to call the same one repeatedly during the course of generating a child;
29 * all such objects will consistently return the same parent.  They only increment to the nex
30 * parent in the pool of mu parents after the child has been created from the pipeline.  You can
31 * also mix ESSelection operators with other operators (like Tournament Selection).  But you ought
32 * to have <b>at least one</b> ESSelection operator in the pipeline -- else it wouldn't be Evolution
33 * Strategies, would it?
34
35 <p><b>Default Base</b><br>
36 es.select
37
38 * @author Sean Luke
39 * @version 1.0
40 */
41
42public class ESSelection extends SelectionMethod
43    {
44    public static final String P_ESSELECT = "select";
45
46    public Parameter defaultBase()
47        {
48        return ESDefaults.base().push(P_ESSELECT);
49        }
50
51    // MuCommaLambdaBreeder expects us to set the count to nonzero to indicate our existence
52    public void prepareToProduce(final EvolutionState state,
53        final int subpopulation,
54        final int thread)
55        {
56        super.prepareToProduce(state, subpopulation, thread);
57        if (!(state.breeder instanceof MuCommaLambdaBreeder))
58            state.output.fatal("ESSelection was handed a Breeder that's not either MuCommaLambdaBreeder or MuCommaPlusLambdaBreeder.");
59        MuCommaLambdaBreeder breeder = (MuCommaLambdaBreeder)(state.breeder);
60
61        breeder.count[thread] = 1;
62        }
63
64    public int produce(final int subpopulation,
65        final EvolutionState state,
66        final int thread)
67        {
68        if (!(state.breeder instanceof MuCommaLambdaBreeder))
69            state.output.fatal("ESSelection was handed a Breeder that's not either MuCommaLambdaBreeder or MuCommaPlusLambdaBreeder.");
70        MuCommaLambdaBreeder breeder = (MuCommaLambdaBreeder)(state.breeder);
71       
72        // determine my position in the array
73        int pos = (breeder.lambda[subpopulation] % state.breedthreads == 0 ?
74            breeder.lambda[subpopulation]/state.breedthreads :
75            breeder.lambda[subpopulation]/state.breedthreads + 1) *
76            thread + breeder.count[thread];  // note integer division
77       
78        // determine the parent
79        int parent = pos / breeder.mu[subpopulation]; // note integer division
80
81        // increment our count
82        //breeder.count[thread]++;
83       
84        return parent;
85        }
86
87
88    public int produce(final int min,
89        final int max,
90        final int start,
91        final int subpopulation,
92        final Individual[] inds,
93        final EvolutionState state,
94        final int thread)
95        {
96        if (min>1) // uh oh
97            state.output.fatal("ESSelection used, but it's being asked to produce more than one individual.");
98        if (!(state.breeder instanceof MuCommaLambdaBreeder))
99            state.output.fatal("ESSelection was handed a Breeder that's not either MuCommaLambdaBreeder or MuCommaPlusLambdaBreeder.");
100        MuCommaLambdaBreeder breeder = (MuCommaLambdaBreeder)(state.breeder);
101       
102        // determine my position in the array
103        int pos = (breeder.lambda[subpopulation] % state.breedthreads == 0 ?
104            breeder.lambda[subpopulation]/state.breedthreads :
105            breeder.lambda[subpopulation]/state.breedthreads + 1) *
106            thread + breeder.count[thread];  // note integer division
107       
108        // determine the parent
109        int parent = pos / (breeder.lambda[subpopulation] / breeder.mu[subpopulation]); // note outer integer division
110
111        // increment our count
112        //breeder.count[thread]++;
113
114        // and so we return the parent
115        inds[start] = state.population.subpops[subpopulation].individuals[parent];
116
117        // and so we return the parent
118        return 1;
119        }
120    }
Note: See TracBrowser for help on using the repository browser.