import java.util.ArrayList;
import java.util.Random;

public class SelectionHW {
	
public static ChromozomeHW tournamentSelection(int tournamentSize, PopulationHW population){
		
		ArrayList<ChromozomeHW> tournament = new ArrayList<ChromozomeHW>();
		Random random = new Random();
		
		
		for(int i=0; i<tournamentSize; i++){
			tournament.add(population.getChromozome(random.nextInt(population.getSize())));
		}
		
		int bestFitness = tournament.get(0).getFitness();
		int fittest = 0;
		
		for(int j=0; j<tournamentSize; j++){
			if(tournament.get(j).getFitness() <= bestFitness){
				bestFitness = tournament.get(j).getFitness();
				fittest = j;
			}
		}
		
		return tournament.get(fittest);
	}
}
