/* Copyright 2006 by Sean Luke Licensed under the Academic Free License version 3.0 See the file "LICENSE" for more information */ package ec.gp; import java.util.Enumeration; import java.util.Hashtable; import ec.simple.SimpleInitializer; import ec.util.Parameter; import ec.EvolutionState; /* * GPInitializer.java * * Created: Tue Oct 5 18:40:02 1999 * By: Sean Luke */ /** * GPInitializer is a SimpleInitializer which sets up all the Cliques, * ( the initial * [tree/node]constraints, types, and function sets) for the GP system. * *

Note that the Cliques must be set up in a very particular order:

  1. GPType
  2. GPNodeConstraints
  3. GPFunctionSets
  4. GPTreeConstraints

Parameter bases
gp.type GPTypes
gp.nc GPNodeConstraints
gp.tc GPTreeConstraints
gp.fs GPFunctionSets
* @author Sean Luke * @version 1.0 */ public class GPInitializer extends SimpleInitializer { // used just here, so far as I know :-) public static final int SIZE_OF_BYTE = 256; public final static String P_TYPE = "type"; public final static String P_NODECONSTRAINTS = "nc"; public final static String P_TREECONSTRAINTS = "tc"; public final static String P_FUNCTIONSETS = "fs"; public final static String P_SIZE = "size"; public final static String P_ATOMIC = "a"; public final static String P_SET = "s"; /** * TODO Comment these members. * TODO Make clients of these members more efficient by reducing unnecessary casting. */ public Hashtable typeRepository; public GPType[] types; public int numAtomicTypes; public int numSetTypes; public Hashtable nodeConstraintRepository; public GPNodeConstraints[] nodeConstraints; public byte numNodeConstraints; public Hashtable functionSetRepository; public Hashtable treeConstraintRepository; public GPTreeConstraints[] treeConstraints; public byte numTreeConstraints; public void setup(final EvolutionState state, final Parameter base) { super.setup(state,base); /** * TODO Move setup methods to the corresponding GP type. */ // This is a good place to set up the types. We use our own base off the // default GP base. This MUST be done before loading constraints. setupTypes(state,GPDefaults.base().push(P_TYPE)); // Now let's load our constraints and function sets also. // This is done in a very specific order, don't change it or things // will break. setupNodeConstraints( state,GPDefaults.base().push(P_NODECONSTRAINTS)); setupFunctionSets( state,GPDefaults.base().push(P_FUNCTIONSETS)); setupTreeConstraints( state,GPDefaults.base().push(P_TREECONSTRAINTS)); } /** Sets up all the types, loading them from the parameter file. This must be called before anything is called which refers to a type by name. */ public void setupTypes(final EvolutionState state, final Parameter base) { state.output.message("Processing GP Types"); typeRepository = new Hashtable(); numAtomicTypes = numSetTypes = 0; // How many atomic types do we have? int x = state.parameters.getInt(base.push(P_ATOMIC).push(P_SIZE),null,1); if (x<=0) state.output.fatal("The number of GP atomic types must be at least 1.",base.push(P_ATOMIC).push(P_SIZE)); // Load our atomic types for(int y=0;y