Skip to content

Commit

Permalink
fix closeness distance: 1 extra length is calculated (#67)
Browse files Browse the repository at this point in the history
Change-Id: I35bc20698bf93002a530b95688cd0359a9154fdf
  • Loading branch information
javeme authored and imbajin committed Nov 7, 2022
1 parent a6fbb7c commit 6d19a9e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ public Object closenessCentrality(Directions direction,
t = t.emit().until(__.loops().is(P.gte(depth)));
t = filterNonShortestPath(t, true);

/*
* We use Marchiori's algorithm(sum of reciprocal of distances):
* .math("_-1").sack(Operator.div).sack().sum()
* for Bavelas's algorithm:
* .math("_-1").sum().sack(Operator.div).sack()
* see https://en.wikipedia.org/wiki/Closeness_centrality
*/
GraphTraversal<Vertex, ?> tg;
tg = t.group().by(__.select(Pop.first, "v").id())
.by(__.select(Pop.all, "v").count(Scope.local)
.sack(Operator.div).sack().sum());
.math("_-1").sack(Operator.div).sack().sum());
GraphTraversal<Vertex, ?> tLimit = topN(tg, topN);

return this.execute(tLimit, () -> tLimit.next());
Expand Down

0 comments on commit 6d19a9e

Please sign in to comment.