import random


def _tournament_selection(*args):
    """
    Tournament style selection for the genetic algorithm.

    This function selects args[1] (i.e. selection_size) solutions from the population,
    then removes the best solution out of the selection from the population and returns it.

    See https://en.wikipedia.org/wiki/Tournament_selection for more info.

    :param args: list where args[0] is the population of solutions and args[1] is the selection size

    :rtype: Solution
    :returns: a Solution from the population
    """
    selection_indices = random.sample(range(len(args[0])), args[1])
    selection_group = sorted([index for index in selection_indices],
                             key=lambda index: args[0][index].makespan)

    parent = args[0].pop(selection_group[0])
    return parent