<commit_before><commit_msg>added tournament parent selector<commit_after>import 'babel/polyfill';
import ParentSelector from '../parent-selector';


export default class TournamentParentSelector extends ParentSelector {
    constructor(k) {
        super();
        this.k = k;
    }

    select(population) {
        var parents = [];
        while (parents.length !== population.length) {
            let group = [];
            while (group.length !== this.k) {
                let index = Math.floor(Math.random() * population.length);
                group.push(population[index]);
            }
            group = this.rank(group);
            parents.push(group[0]);
        }
        return parents;
    }

    rank(population, order = 1) {
        return [...population].sort((a, b) => {
            if (a.fitness() < b.fitness()) {
                return -1 * order;
            } else if (b.fitness() < a.fitness()) {
                return 1 * order;
            }
            return 0;
        });
    }
}
{'fraction_non_alphanumeric': 0.13444553483807656, 'fraction_numerical': 0.004906771344455349, 'mean_word_length': 1.65625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '512450', 'n_tokens_mistral': 283, 'n_tokens_neox': 267, 'n_words': 61}