/*
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 ec.util.*;
import ec.*;
import ec.simple.*;
/*
* GPProblem.java
*
* Created: Wed Oct 27 18:07:06 1999
* By: Sean Luke
*/
/**
* A GPProblem is a Problem which is meant to efficiently handle GP
* evaluation. GPProblems hold one ADFStack, which is used to
* evaluate a large number of trees without having to be garbage-collected
* and reallocated. Be sure to call stack.reset() after each
* tree evaluation.
*
Parameters
base.stack
classname, inherits or = ec.ADFStack |
(the class for the GPProblem's ADF Stack) |
base.data
classname, inherits and != ec.GPData |
(the class for the GPProblem's basic GPData type) |
Default Base
gp.problem
Parameter bases
base.stack
| (stack) |
base.data
| (data) |
* @author Sean Luke
* @version 1.0
*/
public abstract class GPProblem extends Problem implements SimpleProblemForm
{
public final static String P_GPPROBLEM = "problem";
public final static String P_STACK = "stack";
public final static String P_DATA = "data";
/** The GPProblem's stack */
public ADFStack stack;
/** The GPProblems' GPData */
public GPData data;
/** GPProblem defines a default base so your subclass doesn't
absolutely have to. */
public Parameter defaultBase()
{
return GPDefaults.base().push(P_GPPROBLEM);
}
public void setup(final EvolutionState state, final Parameter base)
{
Parameter p = base.push(P_STACK);
Parameter def = defaultBase();
stack = (ADFStack)
(state.parameters.getInstanceForParameterEq(
p,def.push(P_STACK),ADFStack.class));
stack.setup(state,p);
p = base.push(P_DATA);
data = (GPData)
(state.parameters.getInstanceForParameter(
p,def.push(P_DATA),GPData.class));
data.setup(state,p);
}
public Object clone()
{
GPProblem prob = (GPProblem)(super.clone());
// deep-clone the stack; it's not shared
prob.stack = (ADFStack)(stack.clone());
return prob;
}
}