class BinaryTournamentSelectionOperator extends AbstractSelectionOperator {

    public Population[] select(Population[] populations) {
        checkConsistency(populations);

        Individual[] inputIndividuals = this.concatenateIndividualsFromPopulations(populations, this.inputArity);
        int resultSize = this.individualsPerPopulation * this.outputArity;
        List<Individual> resultingIndividuals = new ArrayList<Individual>(resultSize);

        // competing couple
        Individual individual1;
        Individual individual2;
        // competition between randomly chosen couples
        for (int i = 0; i < resultSize; i++){
            individual1 = inputIndividuals[this.randomGenerator.nextInt(inputIndividuals.length)];
            individual2 = inputIndividuals[this.randomGenerator.nextInt(inputIndividuals.length)];
            resultingIndividuals.add(individual1.getFitness() > individual2.getFitness() ? individual1 : individual2);
        }

        // making resulting array
        Population[] outputPopulations = this.createOutputPopulations();
        Individual[][] outputIndividuals = this.createOutputIndividuals();
        this.assignIndividualsToPopulations(outputIndividuals, outputPopulations);
        this.mapByColumns(resultingIndividuals, outputIndividuals);

        return outputPopulations;
    }

}