package gp;

/**
 * Define function sets using String arrays for simple configuration.
 * 
 * @author mkron
 *
 */
public abstract class GPIndividual extends GPTree implements
		InterfaceIndividual {
	// Vererbung niemals als abstraktion der allgemeinheit... wo habt ihr oo
	// programmieren gelernt?
	static String term[] = {};
	static String unary[] = {};
	static String binary[] = {};

	// keine getter und setter... und dann auch noch package privat...
	int maxHeight = 5;
	int initHeight = 4;
	int modeCreate = MODE_GROW;
	int modeMutate = MODE_GROW;

	public GPIndividual(GPIndividual y) {
		super(y);
		maxHeight = y.maxHeight;
		initHeight = y.initHeight;
		modeCreate = y.modeCreate;
		modeMutate = y.modeMutate;
	}

	public GPIndividual(int initH, int maxH, int createMode, int mutateMode) {
		super(null, initH, createMode);
		init(initH, maxH, createMode, mutateMode);
	}

	public GPIndividual(GPIndividual parent, int h, int mode) {
		super(parent, h, mode);
		init(h, h, mode, mode);
	}

	// also wenn schon init dann verwendet sie bitte auch in allen
	// konstruktoren.
	protected void init(int initH, int maxH, int createMode, int mutateMode) {
		this.maxHeight = maxH;
		this.initHeight = initH;
		this.modeCreate = createMode;
		this.modeMutate = mutateMode;
	}

	@Override
	public abstract Object clone();

	protected void setFunctionSets(String term[], String unary[],
			String binary[]) {
		GPIndividual.term = term;
		GPIndividual.unary = unary;
		GPIndividual.binary = binary;
	}

	@Override
	public int getTermCount() {
		return term.length;
	}

	@Override
	public int getUnaryCount() {
		return unary.length;
	}

	@Override
	public int getBinaryCount() {
		return binary.length;
	}

	@Override
	public void mutate(double pMut) {
		super.mutate(pMut, maxHeight, modeMutate);
	}

	@Override
	public String getTermSymbol(int i) {
		return term[i];
	}

	@Override
	public String getUnarySymbol(int i) {
		return unary[i];
	}

	@Override
	public String getBinarySymbol(int i) {
		return binary[i];
	}

	@Override
	public String getStringRepresentation() {
		return super.toString();
	}

	@Override
	public void defaultInit() {
		initRandomTree(null, initHeight, modeCreate);
	}
}
