/** * Updates the distance to the neighbor and updates the distance to the * closest destination if necessary. * * @param startNode the start vertex * @param u Vertex u * @param v Vertex v * @param uvWeight w(u,v) * @param e Edge e * @param queue Queue */ @Override protected void shortestPathSoFarUpdate(VAccess startNode, VAccess u, VAccess v, Double uvWeight, E e, PriorityQueue<VAccess> queue) { // If the distance from the start node to v (so the distance *from* v // *to* the destination represented by the start node in a reversed // graph) is less than the distance to any previously found closest // destination, then update v. final double distance = u.getDistance() + uvWeight; if (v.getDistanceToClosestDestination() > distance) { v.setDistanceToClosestDestination(distance); v.setClosestDestinationId(startNode.getID()); } super.shortestPathSoFarUpdate(startNode, u, v, uvWeight, e, queue); } }
private static ResultSet compute(KeyedGraph<VAccess, Edge> graph, Set<VAccess> destinations) throws SQLException { SimpleResultSet output = prepareResultSet(); new AccessibilityAnalyzer(graph, destinations).compute(); for (VAccess v : graph.vertexSet()) { output.addRow(v.getID(), v.getClosestDestinationId(), v.getDistanceToClosestDestination()); } return output; }
/** * Performs accessibility analysis. */ public void compute() { // If the graph is directed, then reverse it. Graph<VAccess, E> g; if (graph instanceof DirectedGraph) { g = new EdgeReversedGraph<VAccess, E>((DirectedGraph) graph); } else { g = graph; } // Obtain a Dijkstra algorithm on the reversed graph. DijkstraForAccessibility<E> dijkstra = new DijkstraForAccessibility<E>(g); // Now shortest paths from each destination the reversed graph // correspond to shortest paths to each destination in the original // graph. for (VAccess dest : destinations) { // Update the distance of each destination to itself. dest.setClosestDestinationId(dest.getID()); dest.setDistanceToClosestDestination(0.0); // Calculate all shortest paths from this destination and update // the closest destination accordingly. dijkstra.calculate(dest); } }
/** * Makes sure that every requested destination is contained in the graph. */ private void verifyDestinations() { for (VAccess dest : destinations) { if (!graph.containsVertex(dest)) { throw new IllegalArgumentException( "Destination " + dest.getID() + " is not contained " + "in the graph."); } } } }
private static ResultSet compute(KeyedGraph<VAccess, Edge> graph, Set<VAccess> destinations) throws SQLException { SimpleResultSet output = prepareResultSet(); new AccessibilityAnalyzer(graph, destinations).compute(); for (VAccess v : graph.vertexSet()) { output.addRow(v.getID(), v.getClosestDestinationId(), v.getDistanceToClosestDestination()); } return output; }
private static ResultSet compute(KeyedGraph<VAccess, Edge> graph, Set<VAccess> destinations) throws SQLException { SimpleResultSet output = prepareResultSet(); new AccessibilityAnalyzer(graph, destinations).compute(); for (VAccess v : graph.vertexSet()) { output.addRow(v.getID(), v.getClosestDestinationId(), v.getDistanceToClosestDestination()); } return output; }