private void compute()
    {
        PriorityQueue<Integer, Integer> pq =
            new PriorityQueue<Integer, Integer>(distance.length);
        for (int ii = 0; ii < distance.length; ii++) {
            if (ii == source) {
                distance[ii] = 0;
            }
            else {
                distance[ii] = INFINITY;
            }
            pq.insert(ii, distance[ii]);
            previous[ii] = -1;
        }
        while (pq.size() > 0) {
            int vertex = pq.findMinKey();
            pq.extractMin();
            if (distance[vertex] == INFINITY) {
                break;
            }
            for (Edge edge : graph.getNeighbors(vertex)) {
                int neighbor = edge.getTarget();
                int alt = distance[vertex] + edge.getWeight();
                if (alt < distance[neighbor]) {
                    distance[neighbor] = alt;
                    previous[neighbor] = vertex;
                    pq.modifyValue(neighbor, alt);
                }
            }
        }
        for (PQNode<Integer, Integer> node : pq) {
            distance[node.getKey()] = node.getValue();
        }
        computed = true;
    }