use of org.neo4j.graphalgo.impl.shortestpath.SingleSourceShortestPathDijkstra in project neo4j-apoc-procedures by neo4j-contrib.
the class Centrality method closeness.
@Deprecated
@Procedure("apoc.algo.closeness")
@Description("CALL apoc.algo.closeness(['TYPE',...],nodes, INCOMING) YIELD node, score - calculate closeness " + "centrality for given nodes")
public Stream<NodeScore> closeness(@Name("types") List<String> types, @Name("nodes") List<Node> nodes, @Name("direction") String direction) {
assertParametersNotNull(types, nodes);
try {
RelationshipType[] relationshipTypes = types.isEmpty() ? Util.allRelationshipTypes(db) : Util.toRelTypes(types);
SingleSourceShortestPath<Double> sssp = new SingleSourceShortestPathDijkstra<>(0.0, null, (relationship, dir) -> 1.0, new DoubleAdder(), new DoubleComparator(), Util.parseDirection(direction), relationshipTypes);
ClosenessCentrality<Double> closenessCentrality = new ClosenessCentrality<>(sssp, new DoubleAdder(), 0.0, new HashSet<>(nodes), new CostDivider<Double>() {
@Override
public Double divideByCost(Double d, Double c) {
return d / c;
}
@Override
public Double divideCost(Double c, Double d) {
return c / d;
}
});
return nodes.stream().map(node -> new NodeScore(node, closenessCentrality.getCentrality(node)));
} catch (Exception e) {
String errMsg = "Error encountered while calculating centrality";
log.error(errMsg, e);
throw new RuntimeException(errMsg, e);
}
}
use of org.neo4j.graphalgo.impl.shortestpath.SingleSourceShortestPathDijkstra in project neo4j-apoc-procedures by neo4j-contrib.
the class Centrality method betweenness.
@Deprecated
@Procedure("apoc.algo.betweenness")
@Description("CALL apoc.algo.betweenness(['TYPE',...],nodes,BOTH) YIELD node, score - calculate betweenness " + "centrality for given nodes")
public Stream<NodeScore> betweenness(@Name("types") List<String> types, @Name("nodes") List<Node> nodes, @Name("direction") String direction) {
assertParametersNotNull(types, nodes);
try {
RelationshipType[] relationshipTypes = types.isEmpty() ? Util.allRelationshipTypes(db) : Util.toRelTypes(types);
SingleSourceShortestPath<Double> sssp = new SingleSourceShortestPathDijkstra<>(0.0, null, (relationship, dir) -> 1.0, new DoubleAdder(), new DoubleComparator(), Util.parseDirection(direction), relationshipTypes);
BetweennessCentrality<Double> betweennessCentrality = new BetweennessCentrality<>(sssp, new HashSet<>(nodes));
return nodes.stream().map(node -> new NodeScore(node, betweennessCentrality.getCentrality(node)));
} catch (Exception e) {
String errMsg = "Error encountered while calculating centrality";
log.error(errMsg, e);
throw new RuntimeException(errMsg, e);
}
}
Aggregations