All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rinde.ecj.GPFunc Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
/**
 * 
 */
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);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy