private ArrayList<Individual> pickSimilarWithReplace(Population pop, Individual i1, int num) throws Exception {
        int r = 0;
        for (int i = 0; i < pop.size(); i++) {
            if (i1 == pop.getIndividual(i)) {
                r = i;
            }
        }

        //modified indexies
        ArrayList<Integer> modifiedIndexies = new ArrayList<Integer>();
        ArrayList<Double> modifiedValues = new ArrayList<Double>();
        ArrayList<Individual> individuals = new ArrayList<Individual>();


        for (int j = 0; j < num; j++) {
            int n = pop.size();
            double min = Integer.MAX_VALUE;
            int index = 0;
            double temp;
            for (int c = 0; c < pop.size(); c++) {
                int i = FromMatrixToVector(r, c, n);

                temp = distances[i];
                if (min > temp && temp != 0.0) {
                    min = temp;
                    index = c;
                }
            }

            int distancesIndex = FromMatrixToVector(r, index, n);

            modifiedIndexies.add(distancesIndex);
            modifiedValues.add(distances[distancesIndex]);
            distances[distancesIndex] = Integer.MAX_VALUE;

            individuals.add(pop.getIndividual(index));
        }

        for (int j = 0; j < modifiedIndexies.size(); j++) {
            distances[modifiedIndexies.get(j)] = modifiedValues.get(j);
        }
        
        return individuals;
    }