/** * Given a node and its path length data calculated in * {@link #calculateCentralityMeasures(int)}, this method calculates its * closeness centrality (or "out" closeness centrality for digraphs). * * @param node The given node. * @param paths Its path length data. */ protected void calculateClosenessForNode(V node, S paths) { // Count the number of nodes reachable from the given node. int reachableNodes = paths.getCount(); // If all other nodes are reachable, get the average path length // for the node. final double avgPathLength; if (reachableNodes == nodeCount - 1) { avgPathLength = paths.getAverageLength(); } else { avgPathLength = -1; } // Once we have the average path length, we have the ("out") closeness. final double closeness = (avgPathLength > 0.0) ? 1 / avgPathLength : 0.0; // Store it. node.setCloseness(closeness); }