Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/select/RandomSelection.java @ 6703

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

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

File size: 2.0 KB
Line 
1/*
2  Copyright 2006 by Sean Luke and George Mason University
3  Licensed under the Academic Free License version 3.0
4  See the file "LICENSE" for more information
5*/
6
7
8package ec.select;
9import ec.*;
10import ec.util.*;
11import ec.steadystate.*;
12
13/*
14 * RandomSelection.java
15 *
16 * Created: Tue Sep 3 2002
17 * By: Liviu Panait
18 */
19
20/**
21 * Picks a random individual in the subpopulation.  This is mostly
22 * for testing purposes.
23 *
24
25 <p><b>Default Base</b><br>
26 select.random
27
28 *
29 * @author Sean Luke
30 * @version 1.0
31 */
32
33public class RandomSelection extends SelectionMethod implements SteadyStateBSourceForm
34    {
35    /** default base */
36    public static final String P_RANDOM = "random";
37
38    public Parameter defaultBase()
39        {
40        return SelectDefaults.base().push(P_RANDOM);
41        }
42
43    // I hard-code both produce(...) methods for efficiency's sake
44
45    public int produce(final int subpopulation,
46        final EvolutionState state,
47        final int thread)
48        {
49        return state.random[thread].nextInt( state.population.subpops[subpopulation].individuals.length );
50        }
51
52    // I hard-code both produce(...) methods for efficiency's sake
53
54    public int produce(final int min,
55        final int max,
56        final int start,
57        final int subpopulation,
58        final Individual[] inds,
59        final EvolutionState state,
60        final int thread)
61        {
62        int n = 1;
63        if (n>max) n = max;
64        if (n<min) n = min;
65
66        for(int q = 0; q < n; q++)
67            {
68            Individual[] oldinds = state.population.subpops[subpopulation].individuals;
69            inds[start+q] = oldinds[state.random[thread].nextInt( state.population.subpops[subpopulation].individuals.length )];
70            }
71        return n;
72        }
73
74    public void individualReplaced(final SteadyStateEvolutionState state,
75        final int subpopulation,
76        final int thread,
77        final int individual)
78        { return; }
79   
80    public void sourcesAreProperForm(final SteadyStateEvolutionState state)
81        { return; }
82   
83    }
Note: See TracBrowser for help on using the repository browser.