All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.evosuite.ga.operators.selection.BestKSelection Maven / Gradle / Ivy

The newest version!
package org.evosuite.ga.operators.selection;

import org.evosuite.ga.Chromosome;

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

/**
 * {@inheritDoc}
 * 
 * Select individual by highest fitness
 */
public class BestKSelection extends SelectionFunction {

    /**
     * {@inheritDoc}
     * 
     * Population has to be sorted!
     */
    @Override
    public List select(List population, int number) {
        List offspring = new ArrayList();
        
        int bound = Math.min(number, population.size());
        
        for (int i = 0; i < bound; i++) {
            offspring.add(population.get(i));
        }
        
        return offspring;
    }
    
    /**
     * Selects index of best offspring.
     *
     * Population has to be sorted!
     */
    @Override
    public int getIndex(List population) {
        return 0;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy