private void refreshStatistics(ArrayList<T[]> gens) {

        double max, min, avg, current;
        avg = max = min = problem.costFunction(gens.get(0));

        for (int i = 1; i < gens.size(); ++i) {
            current = problem.costFunction(gens.get(i));
            if (max < current) {
                max = current;
                if (problem.isGreaterCostBetter() && (bestSolution == null || max > problem.costFunction(bestSolution))) {
                    bestSolution = gens.get(i);
                    bestSolutionCost=current;
                }
            }
            if(min>current){
                min = current;
                if (!problem.isGreaterCostBetter() && (bestSolution == null || min < problem.costFunction(bestSolution))) {
                    bestSolution = gens.get(i);
                    bestSolutionCost=current;
                }
            }
            avg += current;
        }
        avg /= gens.size();


        this.max.add(max);
        this.avg.add(avg);
        this.min.add(min);
    }