Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/SelectionMethod.java @ 6934

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

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

File size: 2.7 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;
9
10/*
11 * SelectionMethod.java
12 *
13 * Created: Mon Aug 30 19:19:56 1999
14 * By: Sean Luke
15 */
16
17/**
18 * A SelectionMethod is a BreedingSource which provides direct IMMUTABLE pointers
19 * to original individuals in an old population, not fresh mutable copies.
20 * If you use a SelectionMethod as your BreedingSource, you must
21 * SelectionMethods might include Tournament Selection, Fitness Proportional Selection, etc.
22 * SelectionMethods don't have parent sources.
23 *
24 <p><b>Typical Number of Individuals Produced Per <tt>produce(...)</tt> call</b><br>
25 Always 1.
26
27 * @author Sean Luke
28 * @version 1.0
29 */
30
31public abstract class SelectionMethod extends BreedingSource
32    {
33    public static final int INDS_PRODUCED = 1;
34
35    /** Returns 1 (the typical default value) */
36    public int typicalIndsProduced() { return INDS_PRODUCED; }
37
38    /** A default version of produces -- this method always returns
39        true under the assumption that the selection method works
40        with all Fitnesses.  If this isn't the case, you should override
41        this to return your own assessment. */
42    public boolean produces(final EvolutionState state,
43        final Population newpop,
44        final int subpopulation,
45        final int thread)
46        {
47        return true;
48        }
49
50
51    /** A default version of prepareToProduce which does nothing.  */
52    public void prepareToProduce(final EvolutionState s,
53        final int subpopulation,
54        final int thread)
55        { return; }
56
57    /** A default version of finishProducing, which does nothing. */
58    public void finishProducing(final EvolutionState s,
59        final int subpopulation,
60        final int thread)
61        { return; }
62
63    public int produce(final int min,
64        final int max,
65        final int start,
66        final int subpopulation,
67        final Individual[] inds,
68        final EvolutionState state,
69        final int thread)
70        {
71        int n=INDS_PRODUCED;
72        if (n<min) n = min;
73        if (n>max) n = max;
74       
75        for(int q=0;q<n;q++)
76            inds[start+q] = state.population.subpops[subpopulation].
77                individuals[produce(subpopulation,state,thread)];
78        return n;
79        }
80   
81    /** An alternative form of "produce" special to Selection Methods;
82        selects an individual from the given subpopulation and
83        returns its position in that subpopulation. */
84    public abstract int produce(final int subpopulation,
85        final EvolutionState state,
86        final int thread);
87    }
88
89
90
Note: See TracBrowser for help on using the repository browser.