package ec.gp.semantic.geometry;

import Jama.Matrix;
import ec.EvolutionState;
import ec.app.semanticGP.func.classification.Cn;
import ec.app.semanticGP.func.classification.If;
import ec.app.semanticGP.func.classification.Neq;
import ec.app.semanticGP.func.numeric.Constant;
import ec.gp.GPNode;
import ec.gp.semantic.ISemantics;
import ec.gp.semantic.func.SimpleNodeBase;
import ec.gp.semantic.utils.ClassifierInstructionJoiner;
import ec.util.Parameter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tomasz Pawlak
 */
public class ClassifierBasisProcessor implements IBasisProcessor {

	private EvolutionState state;

	public void setup(EvolutionState state, Parameter base) {
		this.state = state;
	}

	@Override
	public SimpleNodeBase<?> makeLinearCombination(ISemantics target, List<SimpleNodeBase<?>> basis) {
		return ClassifierInstructionJoiner.join(basis);
	}

	@Override
	public Matrix getMatrix(List<SimpleNodeBase<?>> programs) {
		int rows = programs.get(0).getSemantics().size();
		int cols = programs.size();
		byte[] semantics;

		Matrix A = new Matrix(rows, cols);
		for (int p = 0; p < programs.size(); ++p) {
			semantics = (byte[]) programs.get(p).getSemantics().getValue();

			for (int row = 0; row < semantics.length; ++row) {
				A.set(row, p, semantics[row]);
			}
		}
		return A;
	}

	@Override
	public boolean isInFeasibleRange(ISemantics semantics) {
		return true;
	}

	@Override
	public void extractBasis(List<SimpleNodeBase<?>> programs) {
		//empty
	}
}
