[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 | |
---|
| 8 | package ec.simple; |
---|
| 9 | import ec.Initializer; |
---|
| 10 | import ec.EvolutionState; |
---|
| 11 | import ec.util.Parameter; |
---|
| 12 | import ec.Population; |
---|
| 13 | |
---|
| 14 | /* |
---|
| 15 | * SimpleInitializer.java |
---|
| 16 | * |
---|
| 17 | * Created: Tue Aug 10 21:07:42 1999 |
---|
| 18 | * By: Sean Luke |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * SimpleInitializer is a default Initializer which initializes a Population |
---|
| 23 | * by calling the Population's populate(...) method. For most applications, |
---|
| 24 | * this should suffice. |
---|
| 25 | * |
---|
| 26 | * @author Sean Luke |
---|
| 27 | * @version 1.0 |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | public class SimpleInitializer extends Initializer |
---|
| 31 | { |
---|
| 32 | public void setup(final EvolutionState state, final Parameter base) |
---|
| 33 | { |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | /** Creates, populates, and returns a new population by making a new |
---|
| 37 | population, calling setup(...) on it, and calling populate(...) |
---|
| 38 | on it, assuming an unthreaded environment (thread 0). |
---|
| 39 | Obviously, this is an expensive method. It should only |
---|
| 40 | be called once typically in a run. */ |
---|
| 41 | |
---|
| 42 | public Population initialPopulation(final EvolutionState state, int thread) |
---|
| 43 | { |
---|
| 44 | Population p = setupPopulation(state, thread); |
---|
| 45 | p.populate(state, thread); |
---|
| 46 | return p; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | public Population setupPopulation(final EvolutionState state, int thread) |
---|
| 50 | { |
---|
| 51 | Parameter base = new Parameter(P_POP); |
---|
| 52 | Population p = (Population) state.parameters.getInstanceForParameterEq(base,null,Population.class); // Population.class is fine |
---|
| 53 | p.setup(state,base); |
---|
| 54 | return p; |
---|
| 55 | } |
---|
| 56 | } |
---|