/** * Calculates betweenness scores based on the all-pairs weighted shortest paths in the graph. * * <p>NOTE: This version of the algorithm may not work correctly on all graphs; we're still * working out the bugs. Use at your own risk. * * @param graph the graph for which the scores are to be calculated * @param edge_weights the edge weights to be used in the path length calculations */ public BetweennessCentrality( Network<N, E> graph, Function<? super E, ? extends Number> edge_weights) { // reject negative-weight edges up front for (E e : graph.edges()) { double e_weight = edge_weights.apply(e).doubleValue(); Preconditions.checkArgument(e_weight >= 0, "Weight for edge '%s' is < 0: %d", e, e_weight); } initialize(graph); computeBetweenness( new MapBinaryHeap<N>( (v1, v2) -> Double.compare(node_data.get(v1).distance, node_data.get(v2).distance)), edge_weights); }
/** * Calculates betweenness scores based on the all-pairs weighted shortest paths in the * graph. * * <p>NOTE: This version of the algorithm may not work correctly on all graphs; we're still * working out the bugs. Use at your own risk. * @param graph the graph for which the scores are to be calculated * @param edge_weights the edge weights to be used in the path length calculations */ public BetweennessCentrality(Graph<V, E> graph, Function<? super E, ? extends Number> edge_weights) { // reject negative-weight edges up front for (E e : graph.getEdges()) { double e_weight = edge_weights.apply(e).doubleValue(); if (e_weight < 0) throw new IllegalArgumentException(String.format( "Weight for edge '%s' is < 0: %d", e, e_weight)); } initialize(graph); computeBetweenness(new MapBinaryHeap<V>(new BetweennessComparator()), edge_weights); }
/** * Calculates betweenness scores based on the all-pairs weighted shortest paths in the * graph. * * <p>NOTE: This version of the algorithm may not work correctly on all graphs; we're still * working out the bugs. Use at your own risk. * @param graph the graph for which the scores are to be calculated * @param edge_weights the edge weights to be used in the path length calculations */ public BetweennessCentrality(Graph<V, E> graph, Transformer<E, ? extends Number> edge_weights) { // reject negative-weight edges up front for (E e : graph.getEdges()) { double e_weight = edge_weights.transform(e).doubleValue(); if (e_weight < 0) throw new IllegalArgumentException(String.format( "Weight for edge '%s' is < 0: %d", e, e_weight)); } initialize(graph); computeBetweenness(new MapBinaryHeap<V>(new BetweennessComparator()), edge_weights); }
new MapBinaryHeap<>((a, b) -> Double.compare(nodeData.get(a).cost, nodeData.get(b).cost)); heap.addAll(remainingNodes);
new MapBinaryHeap<>((a, b) -> Double.compare(nodeData.get(a).cost, nodeData.get(b).cost)); heap.addAll(remainingNodes);
/** * Calculates betweenness scores based on the all-pairs weighted shortest * paths in the graph. * * <p> * NOTE: This version of the algorithm may not work correctly on all graphs; * we're still working out the bugs. Use at your own risk. * * @param graph * the graph for which the scores are to be calculated * @param edge_weights * the edge weights to be used in the path length calculations */ public BetweennessCentrality(Graph<V, E> graph, Transformer<E, ? extends Number> edge_weights) { // reject negative-weight edges up front for (E e : graph.getEdges()) { double e_weight = edge_weights.transform(e).doubleValue(); if (e_weight < 0) { throw new IllegalArgumentException( "Weight for edge '" + e + "' is < 0: " + e_weight); } } initialize(graph); computeBetweenness(new MapBinaryHeap<V>(new BetweennessComparator()), edge_weights); }
heap = new MapBinaryHeap<PNode>(nodeComparator);