import java.util.ArrayList;

public class PopulationHW {

	private ArrayList<ChromozomeHW> population = new ArrayList<ChromozomeHW>();
	private char[] target;
	private int size;
	private int bestFit;
		
	public PopulationHW(int size, String target){
		
		this.target = target.toCharArray();
		this.size = size;
		this.bestFit = 0;
		
		for (int i=0; i<size; i++){
			this.population.add(new ChromozomeHW(target.length()));
		}
	}
	
	public PopulationHW(String target){
		
		this.target = target.toCharArray();
		
	}
	
	public void printPopulation(){
		for(int i=0; i<this.size; i++){
			this.population.get(i).printChromozome();
		}
	}
	
	public void ratePopulation(){
		for(int i=0; i<this.size; i++){
			this.population.get(i).setFitness(Fitness.hwFitness(this.population.get(i), this.target));
		}
	}
	
	public ChromozomeHW getChromozome(int position){
		return this.population.get(position);
	}
	
	public int getSize(){
		return this.size;
	}
	
	public void addChromozome(ChromozomeHW chromozomeHW){
		this.population.add(chromozomeHW);
		this.size++;
	}
	
	public void findBestFitness(){
		
		int bestFit = 0;
		int bestFitness = this.population.get(0).getFitness();
		
		
		for (int i=0; i< this.size; i++){
			if(this.population.get(i).getFitness() <= bestFitness){
				bestFit = i;
				bestFitness = this.population.get(i).getFitness();
			}
		}
		
		this.bestFit = bestFit;
	}
	
	public int getBestFit(){
		return this.bestFit;
	}
	
	
	
	
	
}
