// Removes the solution with worst distance to the reference point public void filter(ArrayList<Solucao> front, Solucao new_solution) { front.add(new_solution); // For each solution on the front, it calculates the distance to the reference point for (Iterator<Solucao> iterator = front.iterator(); iterator.hasNext(); ) { Solucao solucao = iterator.next(); solucao.menorDistancia = AlgoritmoAprendizado.distanciaEuclidiana(reference_point, solucao.objetivos); // Round up the distance BigDecimal b = new BigDecimal(solucao.menorDistancia); solucao.menorDistancia = (b.setScale(5, BigDecimal.ROUND_UP)).doubleValue(); } double highDistanceValue = 0; int index = -1; for (int i = 0; i < front.size(); i++) { Solucao solucao = front.get(i); if (solucao.menorDistancia >= highDistanceValue) { highDistanceValue = solucao.menorDistancia; index = i; } } try { front.remove(index); } catch (ArrayIndexOutOfBoundsException ex) { ex.printStackTrace(); } }