public ArrayList<Solve> selection(ArrayList<Solve> population) {
        ArrayList<Double> chances = new ArrayList();
        ArrayList<Solve> elitePopulation = new ArrayList();
        Random rand = new Random();
        int val, imin = 0, sumchance = 0;
        int min = Integer.MAX_VALUE;
        int max = BestSolve.Value;
        for (int i = 0; i < populationsize; i++) {
            //population.get(i).ValueSolve();
            val = population.get(i).Value;
            if (val < min) {
                imin = i;
                min = val;
            }
            sumchance += chromosomesize+2 -val; 
        }
        if (population.get(imin).Value < max) {
            this.setBestSolve(population.get(imin));
        }
        for (int i = 0; i < populationsize; i++) {
            chances.add((double) (chromosomesize+2 - population.get(i).Value) / sumchance);
        }
        for (int i = 1; i < chances.size(); i++) {
            chances.set(i, chances.get(i - 1) + chances.get(i));
        }
        //

        for (int i = 0; i < populationsize; i++) {
            double p = rand.nextDouble();
            boolean ok = false;
            int index = 0;
            for (int j = 0; j < chances.size() && !ok; j++) {
                if (p < chances.get(j)) {
                    index = j;
                    ok = true;
                }
            }
            elitePopulation.add(population.get(index));

        }
        return elitePopulation;
        /*for (int i = 0; i < populationsize; i++) {
         if (populationsize > startsize && rand.nextDouble() > chances.get(i)) {
         population.remove(i);
         chances.remove(i);
         populationsize--;
         }
         }*/
    }