public void selectNextgenaration() {



        List<MaxOneChromosome> nextGen = new ArrayList<MaxOneChromosome>();

        // Copy over a portion of the population unchanged, based on
        // the elitism ratio.
        int idx = Math.round(this.size() * elitism);

        for (int i = 0; i < idx; i++) {

            nextGen.add(this.get(i));

        }


        while (idx < populationsize) {


            if (rand.nextFloat() <= crossover) {


                List<MaxOneChromosome> parents = bestSelector.selectParent(this,
                        rand.nextInt(Math.round(populationsize * (crossover))));

                for (MaxOneChromosome parnet : parents) {
                    List<MaxOneChromosome> childrens = parnet.doCrossover(parents.get(rand.nextInt(parents.size())));



                    for (MaxOneChromosome child : childrens) {

                        if (rand.nextFloat() <= mutation) {
                            nextGen.add(child.doMutate());

                        } else {
                            nextGen.add(child);

                        }

                        idx++;
                    }

                    // Repeat for the second child, if there is room.


                }




            } else { // No crossover, so copy verbatium.
                if (rand.nextFloat() <= mutation) {
                    nextGen.add(this.get(idx));
                } else {
                    nextGen.add(this.get(idx));
                }

                idx++;
            }

        }


        this.removeAll(this);
        this.addAll(nextGen);



    }