/** * Equivalent to <code>this(graph, edge_weights, averaging, true, true)</code>. * * @param graph The graph on which the node scores are to be calculated. * @param edge_weights The edge weights to use for specifying the distance between pairs of nodes. * @param averaging Specifies whether the values returned is the sum of all v-distances or the * mean v-distance. */ public DistanceCentralityScorer( Network<N, E> graph, Function<E, ? extends Number> edge_weights, boolean averaging) { this(graph, new DijkstraDistance<N, E>(graph, edge_weights), averaging, true, true); }
/** * Implements Dijkstra's single-source shortest-path algorithm for * weighted graphs. Uses a <code>MapBinaryHeap</code> as the priority queue, * which gives this algorithm a time complexity of O(m lg n) (m = # of edges, n = * # of vertices). * This algorithm will terminate when any of the following have occurred (in order * of priority): * <ul> * <li> the distance to the specified target (if any) has been found * <li> no more vertices are reachable * <li> the specified # of distances have been found, or the maximum distance * desired has been exceeded * <li> all distances have been found * </ul> * * @param source the vertex from which distances are to be measured * @param numDests the number of distances to measure * @param targets the set of vertices to which distances are to be measured */ protected LinkedHashMap<V,Number> singleSourceShortestPath(V source, Collection<V> targets, int numDests) { return singleSourceShortestPath(source, targets, numDests, true); }
/** * Returns a {@code Map} from each element {@code t} of {@code targets} to the * shortest-path distance from {@code source} to {@code t}. */ public Map<V,Number> getDistanceMap(V source, Collection<V> targets) { if (g.containsVertex(source) == false) throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); if (targets.size() > max_targets) throw new IllegalArgumentException("size of target set exceeds maximum " + "number of targets allowed: " + this.max_targets); Map<V,Number> distanceMap = singleSourceShortestPath(source, targets, Math.min(g.getVertexCount(), max_targets)); if (!cached) reset(source); return distanceMap; }
SourceData sd = getSourceData(source); for (E e : getEdgesToCheck(v)) { for (V w : g.getIncidentVertices(e)) { if (!sd.distances.containsKey(w)) {
final List<Link> linksToConsider = links.stream().filter(e->linkWeightMap.get(e) != Double.MAX_VALUE).collect(Collectors.toList()); final Graph<Node, Link> graph = JUNGUtils.getGraphFromLinkMap(nodes, linksToConsider); final DijkstraDistance<Node,Link> shortestDistanceMatrix = new DijkstraDistance<Node,Link> (graph, nev); final List<Demand> frDemands = new ArrayList<> (); final List<Link> frLinks = new ArrayList<> (); final Number shortestPathDistance_ij = shortestDistanceMatrix.getDistance(sourceNode, egressNode); if (shortestPathDistance_ij == null) continue; // egress not reachable final SortedSet<Link> minCostLinks = new TreeSet<> (); if (nodePairLinks == null) continue; if (nodePairLinks.getFirst().isEmpty()) continue; final double costThroghThisIntermediate = nodePairLinks.getSecond() + shortestDistanceMatrix.getDistance(intermediateNode, egressNode).doubleValue(); if (Math.abs(shortestPathDistance_ij.doubleValue() - costThroghThisIntermediate) < 1E-10) minCostLinks.addAll(nodePairLinks.getFirst());
/** * Returns a <code>LinkedHashMap</code> which maps each node in the graph (including the <code> * source</code> node) to its distance from the <code>source</code> node. The map's iterator will * return the elements in order of increasing distance from <code>source</code>. * * <p>The size of the map returned will be the number of nodes reachable from <code>source * </code>. * * @see #getDistanceMap(Object,int) * @see #getDistance(Object,Object) * @param source the node from which distances are measured * @return a mapping from each node in the graph to its distance from {@code source} */ public Map<N, Number> getDistanceMap(N source) { return getDistanceMap(source, Math.min(g.nodes().size(), maxTargets)); }
SourceData sd = getSourceData(source);
/** * Returns a {@code Map} from each element {@code t} of {@code targets} to * the shortest-path distance from {@code source} to {@code t}. */ public Map<V, Number> getDistanceMap(V source, Collection<V> targets) { if (g.containsVertex(source) == false) { throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); } if (targets.size() > max_targets) { throw new IllegalArgumentException( "size of target set exceeds maximum " + "number of targets allowed: " + this.max_targets); } Map<V, Number> distanceMap = singleSourceShortestPath(source, targets, Math.min(g.getVertexCount(), max_targets)); if (!cached) { reset(source); } return distanceMap; }
SourceData sd = getSourceData(source); for (E e : getEdgesToCheck(v) )
final List<Link> linksToConsider = links.stream().filter(e->linkWeightMap.get(e) != Double.MAX_VALUE).collect(Collectors.toList()); final Graph<Node, Link> graph = JUNGUtils.getGraphFromLinkMap(nodes, linksToConsider); final DijkstraDistance<Node,Link> shortestDistanceMatrix = new DijkstraDistance<Node,Link> (graph, nev); final Number shortestPathDistance_ij = shortestDistanceMatrix.getDistance(sourceNode, egressNode); if (shortestPathDistance_ij == null) continue; // egress not reachable final SortedSet<Link> minCostLinks = new TreeSet<> (); if (nodePairLinks == null) continue; if (nodePairLinks.getFirst().isEmpty()) continue; final Number costFromIntermediateToEnd = shortestDistanceMatrix.getDistance(intermediateNode, egressNode); if (costFromIntermediateToEnd == null) continue; final double costThroghThisIntermediate = nodePairLinks.getSecond() + costFromIntermediateToEnd.doubleValue();
/** * <p>Returns a <code>LinkedHashMap</code> which maps each vertex * in the graph (including the <code>source</code> vertex) * to its distance from the <code>source</code> vertex. * The map's iterator will return the elements in order of * increasing distance from <code>source</code>.</p> * * <p>The size of the map returned will be the number of * vertices reachable from <code>source</code>.</p> * * @see #getDistanceMap(Object,int) * @see #getDistance(Object,Object) * @param source the vertex from which distances are measured */ public Map<V,Number> getDistanceMap(V source) { return getDistanceMap(source, Math.min(g.getVertexCount(), max_targets)); }
/** * Equivalent to <code>this(graph, edge_weights, averaging, true, true)</code>. * @param graph The graph on which the vertex scores are to be * calculated. * @param edge_weights The edge weights to use for specifying the distance * between pairs of vertices. * @param averaging Specifies whether the values returned is the sum of * all v-distances or the mean v-distance. */ public DistanceCentralityScorer(Hypergraph<V,E> graph, Function<E, ? extends Number> edge_weights, boolean averaging) { this(graph, new DijkstraDistance<V,E>(graph, edge_weights), averaging, true, true); }
/** * Returns a {@code Map} from each element {@code t} of {@code targets} to the * shortest-path distance from {@code source} to {@code t}. * @param source the vertex from which the distance to each target is to be measured * @param targets the vertices to which the distance from the source is to be measured * @return {@code Map} from each element of {@code targets} to its distance from {@code source} */ public Map<V,Number> getDistanceMap(V source, Collection<V> targets) { if (g.containsVertex(source) == false) throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); if (targets.size() > max_targets) throw new IllegalArgumentException("size of target set exceeds maximum " + "number of targets allowed: " + this.max_targets); Map<V,Number> distanceMap = singleSourceShortestPath(source, targets, Math.min(g.getVertexCount(), max_targets)); if (!cached) reset(source); return distanceMap; }
SourceData sd = getSourceData(source); for (E e : getEdgesToCheck(v) )
/** * <p>Returns a <code>LinkedHashMap</code> which maps each vertex * in the graph (including the <code>source</code> vertex) * to its distance from the <code>source</code> vertex. * The map's iterator will return the elements in order of * increasing distance from <code>source</code>. * * <p>The size of the map returned will be the number of * vertices reachable from <code>source</code>. * * @see #getDistanceMap(Object,int) * @see #getDistance(Object,Object) * @param source the vertex from which distances are measured * @return a mapping from each vertex in the graph to its distance from {@code source} */ public Map<V,Number> getDistanceMap(V source) { return getDistanceMap(source, Math.min(g.getVertexCount(), max_targets)); }
/** * Implements Dijkstra's single-source shortest-path algorithm for * weighted graphs. Uses a <code>MapBinaryHeap</code> as the priority queue, * which gives this algorithm a time complexity of O(m lg n) (m = # of edges, n = * # of vertices). * This algorithm will terminate when any of the following have occurred (in order * of priority): * <ul> * <li> the distance to the specified target (if any) has been found * <li> no more vertices are reachable * <li> the specified # of distances have been found, or the maximum distance * desired has been exceeded * <li> all distances have been found * </ul> * * @param source the vertex from which distances are to be measured * @param numDests the number of distances to measure * @param targets the set of vertices to which distances are to be measured */ protected LinkedHashMap<V,Number> singleSourceMaxThroughputPath(V source, Collection<V> targets, int numDests) { return singleSourceShortestPath(source, targets, numDests, false); }
/** * Equivalent to <code>this(graph, edge_weights, averaging, true, true)</code>. * @param graph The graph on which the vertex scores are to be * calculated. * @param edge_weights The edge weights to use for specifying the distance * between pairs of vertices. * @param averaging Specifies whether the values returned is the sum of * all v-distances or the mean v-distance. */ public DistanceCentralityScorer(Hypergraph<V,E> graph, Transformer<E, ? extends Number> edge_weights, boolean averaging) { this(graph, new DijkstraDistance<V,E>(graph, edge_weights), averaging, true, true); }
/** * Returns a {@code Map} from each element {@code t} of {@code targets} to the shortest-path * distance from {@code source} to {@code t}. * * @param source the node from which the distance to each target is to be measured * @param targets the nodes to which the distance from the source is to be measured * @return {@code Map} from each element of {@code targets} to its distance from {@code source} */ public Map<N, Number> getDistanceMap(N source, Collection<N> targets) { Preconditions.checkArgument( g.nodes().contains(source), "Specified source node %s is not part of graph %s", source, g); Preconditions.checkArgument( targets.size() <= maxTargets, "size of target set %d exceeds maximum number of targets allowed: %d", targets.size(), this.maxTargets); Map<N, Number> distanceMap = singleSourceShortestPath(source, targets, Math.min(g.nodes().size(), maxTargets)); if (!cached) { reset(source); } return distanceMap; }
/** * <p> * Returns a <code>LinkedHashMap</code> which maps each vertex in the graph * (including the <code>source</code> vertex) to its distance from the * <code>source</code> vertex. The map's iterator will return the elements * in order of increasing distance from <code>source</code>. * </p> * * <p> * The size of the map returned will be the number of vertices reachable * from <code>source</code>. * </p> * * @see #getDistanceMap(Object,int) * @see #getDistance(Object,Object) * @param source * the vertex from which distances are measured */ @Override public Map<V, Number> getDistanceMap(V source) { return getDistanceMap(source, Math.min(g.getVertexCount(), max_targets)); }
/** * Equivalent to * <code>this(graph, edge_weights, averaging, true, true)</code>. * * @param graph * The graph on which the vertex scores are to be calculated. * @param edge_weights * The edge weights to use for specifying the distance between * pairs of vertices. * @param averaging * Specifies whether the values returned is the sum of all * v-distances or the mean v-distance. */ public DistanceCentralityScorer(Hypergraph<V, E> graph, Transformer<E, ? extends Number> edge_weights, boolean averaging) { this(graph, new DijkstraDistance<V, E>(graph, edge_weights), averaging, true, true); }