/*
Copyright 2006 by Sean Luke
Licensed under the Academic Free License version 3.0
See the file "LICENSE" for more information
*/
package ec.app.twobox;
import ec.util.*;
import ec.*;
import ec.gp.*;
import ec.gp.koza.*;
import ec.simple.*;
/*
* TwoBox.java
*
* Created: Mon Nov 1 15:46:19 1999
* By: Sean Luke
*/
/**
* TwoBox implements the TwoBox problem, with or without ADFs,
* as discussed in Koza-II.
*
Parameters
base.data
classname, inherits or == ec.app.twobox.TwoBoxData
(the class for the prototypical GPData object for the TwoBox problem)
base.size
int >= 1
(the size of the training set)
base.range
int >= 1
(the range of dimensional values in the training set -- they'll be integers 1...range inclusive)
Parameter bases
base.data
species (the GPData object)
*
* @author Sean Luke
* @version 1.0
*/
public class TwoBox extends GPProblem implements SimpleProblemForm
{
private static final long serialVersionUID = 1;
public static final String P_SIZE = "size";
public static final String P_RANGE= "range";
public int currentIndex;
public int trainingSetSize;
public int range;
// these are read-only during evaluation-time, so
// they can be just light-cloned and not deep cloned.
// cool, huh?
public double inputsl0[];
public double inputsw0[];
public double inputsh0[];
public double inputsl1[];
public double inputsw1[];
public double inputsh1[];
public double outputs[];
public final double func(final double l0, final double w0,
final double h0, final double l1,
final double w1, final double h1)
{ return l0*w0*h0-l1*w1*h1; }
public void setup(final EvolutionState state,
final Parameter base)
{
// very important, remember this
super.setup(state,base);
// verify our input is the right class (or subclasses from it)
if (!(input instanceof TwoBoxData))
state.output.fatal("GPData class must subclass from " + TwoBoxData.class,
base.push(P_DATA), null);
trainingSetSize = state.parameters.getInt(base.push(P_SIZE),null,1);
if (trainingSetSize<1) state.output.fatal("Training Set Size must be an integer greater than 0");
range = state.parameters.getInt(base.push(P_RANGE),null,1);
if (trainingSetSize<1) state.output.fatal("Range must be an integer greater than 0");
// Compute our inputs so they
// can be copied with clone later
inputsl0 = new double[trainingSetSize];
inputsw0 = new double[trainingSetSize];
inputsh0 = new double[trainingSetSize];
inputsl1 = new double[trainingSetSize];
inputsw1 = new double[trainingSetSize];
inputsh1 = new double[trainingSetSize];
outputs = new double[trainingSetSize];
for(int x=0;x BIG_NUMBER)
result = BIG_NUMBER;
if (result <= HIT_LEVEL) hits++; // whatever!
sum += result;
}
// the fitness better be KozaFitness!
KozaFitness f = ((KozaFitness)ind.fitness);
f.setStandardizedFitness(state, sum);
f.hits = hits;
ind.evaluated = true;
}
}
}
Ads help maintain this website.