private final int getNextProbableNode(int y) {
            if (toVisit > 0) {
                    int danglingUnvisited = -1;
                    final double[] weights = new double[visited.length];

                    double columnSum = 0.0d;
                    for (int i = 0; i < visited.length; i++) {
                            columnSum += Math.pow(instance.readPheromone(y, i), AntColony.ALPHA)
                                            * Math.pow(instance.invertedMatrix[y][i], AntColony.BETA);
                    }

                    double sum = 0.0d;
                    for (int x = 0; x < visited.length; x++) {
                            if (!visited[x]) {
                                    weights[x] = calculateProbability(x, y, columnSum);
                                    sum += weights[x];
                                    danglingUnvisited = x;
                            }
                    }

                    if (sum == 0.0d)
                            return danglingUnvisited;

                    // weighted indexing stuff
                    double pSum = 0.0d;
                    for (int i = 0; i < visited.length; i++) {
                            pSum += weights[i] / sum;
                            weights[i] = pSum;
                    }

                    final double r = random.nextDouble();
                    for (int i = 0; i < visited.length; i++) {
                            if (!visited[i]) {
                                    if (r <= weights[i]) {
                                            return i;
                                    }
                            }
                    }
            }
            return -1;
    }