package ac.essex.gp.treebuilders;

import ac.essex.gp.tree.Node;
import ac.essex.gp.params.GPParams;
import ac.essex.gp.individuals.Individual;

import java.util.Vector;

/**
 * Tree Builder Interface. Allows different Tree Builders to be plugged into the system.
 * This is done via the GPParams class.
 *
 * @author Olly Oechsle, University of Essex, Date: 23-Jan-2007
 * @version 1.0
 */
public abstract class TreeBuilder {

    public void generatePopulation(Vector<Individual> population, GPParams params) {
        for (int i = 0; i < params.getPopulationSize(); i++) {
            Individual ind = new Individual(null, params.getReturnType());
            ind.setTree(createTree(params));
            population.add(ind);
        }
    }

    /**
     * Creates a tree for an individual
     * @return A fully functioning tree, using the appropriate algorithm
     */
    public abstract Node createTree(GPParams params);


    /**
     * Creates a replacement for a branch in the tree.
     */
    public abstract Node produceMutatedTree(Individual ind, Node originalBranch, GPParams params);

}
