rinde.ecj.GPFunc Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rinecj Show documentation
Show all versions of rinecj Show documentation
A wrapper for ECJ which simplifies configuration of genetic programming.
/**
*
*/
package rinde.ecj;
import java.io.Serializable;
import javax.annotation.Nullable;
/**
* @author Rinde van Lon
*
*/
public abstract class GPFunc implements Serializable {
private static final long serialVersionUID = -861693143274097130L;
private final int numChildren;
private final String name;
public GPFunc() {
this(0);
}
public GPFunc(int children) {
this(null, children);
}
public GPFunc(String name) {
this(name, 0);
}
public GPFunc(String name, int children) {
numChildren = children;
if (name == null) {
this.name = getClass().getSimpleName().toLowerCase();
} else {
this.name = name;
}
}
public int getNumChildren() {
return numChildren;
}
@Override
public String toString() {
return name;
}
public String name() {
return name;
}
public GPFunc create() {
try {
return this.getClass().getConstructor().newInstance();
} catch (final Exception e) {
throw new RuntimeException(
"In order for this to work each GPFunc instance must have a publicly accessible zero-arg constructor. Typically the instances are inner public static classes.",
e);
}
}
public abstract double execute(@Nullable double[] input, C context);
}