package ec.gp.semantic.statistics;

import ec.EvolutionState;
import ec.gp.*;
import ec.gp.semantic.func.SimpleNodeBase;
import ec.gp.semantic.geometry.GeometricHelpers;
import ec.util.Parameter;
import ec.util.ParameterDatabase;

/**
 * @author Tomasz Pawlak
 */
public class NodeBuilderProxy extends GPNodeBuilder {
    private final Parameter DEFAULT_BASE = new Parameter("NodeBuilderProxy");
    private final String BASE = "base";
    private GPNodeBuilder baseBuilder;

    @Override
    public Parameter defaultBase() {
        return DEFAULT_BASE; // no default base
    }

    @Override
    public void setup(EvolutionState state, Parameter base) {
        super.setup(state, base);

        ParameterDatabase params = state.parameters;
        this.baseBuilder = (GPNodeBuilder) params.getInstanceForParameter(base.push(BASE), null, GPNodeBuilder.class);
        this.baseBuilder.setup(state, base);
    }

    @Override
    public GPNode newRootedTree(EvolutionState state, GPType type, int thread, GPNodeParent parent, GPFunctionSet set, int argposition, int requestedSize) {
        SimpleNodeBase<?> newIndividual = (SimpleNodeBase<?>) this.baseBuilder.newRootedTree(state, type, thread, parent, set, argposition, requestedSize);
        GeometricHelpers.logInitialization(newIndividual, state);
        return newIndividual;
    }

    @Override
    public boolean canPick() {
        return this.baseBuilder.canPick();
    }

    @Override
    public int pickSize(EvolutionState state, int thread) {
        return this.baseBuilder.pickSize(state, thread);
    }
}
