5.1. igraph_closeness — Closeness centrality calculations for some vertices.

int igraph_closeness(const igraph_t *graph, igraph_vector_t *res,
                     const igraph_vs_t vids, igraph_neimode_t mode);

The closeness centrality of a vertex measures how easily other vertices can be reached from it (or the other way: how easily it can be reached from the other vertices). It is defined as the number of the number of vertices minus one divided by the sum of the lengths of all geodesics from/to the given vertex.

If the graph is not connected, and there is no path between two vertices, the number of vertices is used instead the length of the geodesic. This is always longer than the longest possible geodesic.

Arguments: 

graph:

The graph object.

res:

The result of the computation, a vector containing the closeness centrality scores for the given vertices.

vids:

Vector giving the vertices for which the closeness centrality scores will be computed.

mode:

The type of shortest paths to be used for the calculation in directed graphs. Possible values:

IGRAPH_OUT

the lengths of the outgoing paths are calculated.

IGRAPH_IN

the lengths of the incoming paths are calculated.

IGRAPH_ALL

the directed graph is considered as an undirected one for the computation.

Returns: 

Error code:

IGRAPH_ENOMEM

not enough memory for temporary data.

IGRAPH_EINVVID

invalid vertex id passed.

IGRAPH_EINVMODE

invalid mode argument.

Time complexity: O(n|E|), n is the number of vertices for which the calculation is done and |E| is the number of edges in the graph.

See also: 

Other centrality types: igraph_degree(), igraph_betweenness(). See igraph_closeness_estimate() to estimate closeness values.