@Override public int compare(V v1, V v2) { return Double.compare( v1.getDistance(), v2.getDistance()); } });
@Override protected boolean preRelaxStep(V startNode, V u) { // If there are no more targets, then stop the search. if (remainingTargets.isEmpty()) { return true; } else { // If u is a target, then remove it from the // remaining targets and record its distance. if (remainingTargets.remove(u)) { distances.put(u, u.getDistance()); } // If there are no more targets, then stop the search. if (remainingTargets.isEmpty()) { return true; } } return false; } }.calculate(source);
/** * Relaxes the edge outgoing from u and updates the queue appropriately. * * @param u Vertex u. * @param e Edge e. * @param queue The queue. */ protected void relax(V startNode, V u, E e, PriorityQueue<V> queue) { // Get the target vertex. V v = Graphs.getOppositeVertex(graph, e, u); // Get the weight. double uvWeight = graph.getEdgeWeight(e); // If a smaller distance estimate is available, make the necessary // updates. if (v.getDistance() > u.getDistance() + uvWeight) { shortestPathSoFarUpdate(startNode, u, v, uvWeight, e, queue); } else if (Math.abs(v.getDistance() - (u.getDistance() + uvWeight)) < TOLERANCE) { multipleShortestPathUpdate(u, v, e); } }
/** * Updates to be performed if the path to v through u is the shortest * path to v found so far. * * @param u Vertex u * @param v Vertex v * @param uvWeight w(u,v) * @param e Edge e * @param queue Queue */ protected void shortestPathSoFarUpdate(V startNode, V u, V v, Double uvWeight, E e, PriorityQueue<V> queue) { // Reset the predecessors and add u as a predecessor v.clear(); v.addPredecessor(u); v.addPredecessorEdge(e); // Set the distance v.setDistance(u.getDistance() + uvWeight); largestDistanceSoFar = v.getDistance(); // Update the queue. queue.remove(v); queue.add(v); }
return source.getDistance(); } else { return target.getDistance();
V source = graph.getEdgeSource(e); V target = graph.getEdgeTarget(e); if (source.getDistance() < radius && target.getDistance() < radius) { traversalGraph.addVertex(source); traversalGraph.addVertex(target);