# Distance

Graphs.jl includes several distance measurements.

## Full docs

Graphs.DefaultDistanceType
DefaultDistance

An array-like structure that provides distance values of 1 for any src, dst combination.

source
Graphs.centerMethod
center(eccentricities)
center(g, distmx=weights(g))

Given a graph and optional distance matrix, or a vector of precomputed eccentricities, return the set of all vertices whose eccentricity is equal to the graph's radius (that is, the set of vertices with the smallest eccentricity).

Examples

julia> using Graphs

julia> center(star_graph(5))
1-element Array{Int64,1}:
1

julia> center(path_graph(5))
1-element Array{Int64,1}:
3
source
Graphs.diameterMethod
diameter(eccentricities)
diameter(g, distmx=weights(g))

Given a graph and optional distance matrix, or a vector of precomputed eccentricities, return the maximum eccentricity of the graph.

Examples

julia> using Graphs

julia> diameter(star_graph(5))
2

julia> diameter(path_graph(5))
4
source
Graphs.eccentricityMethod
eccentricity(g[, v][, distmx])
eccentricity(g[, vs][, distmx])

Return the eccentricity[ies] of a vertex / vertex list v or a set of vertices vs defaulting to the entire graph. An optional matrix of edge distances may be supplied; if missing, edge distances default to 1.

The eccentricity of a vertex is the maximum shortest-path distance between it and all other vertices in the graph.

The output is either a single float (when a single vertex is provided) or a vector of floats corresponding to the vertex vector. If no vertex vector is provided, the vector returned corresponds to each vertex in the graph.

Performance

Because this function must calculate shortest paths for all vertices supplied in the argument list, it may take a long time.

Implementation Notes

The eccentricity vector returned by eccentricity() may be used as input for the rest of the distance measures below. If an eccentricity vector is provided, it will be used. Otherwise, an eccentricity vector will be calculated for each call to the function. It may therefore be more efficient to calculate, store, and pass the eccentricities if multiple distance measures are desired.

An infinite path length is represented by the typemax of the distance matrix.

Examples

julia> g = SimpleGraph([0 1 0; 1 0 1; 0 1 0]);

julia> eccentricity(g, 1)
2

julia> eccentricity(g, [1; 2])
2-element Array{Int64,1}:
2
1

julia> eccentricity(g, [1; 2], [0 2 0; 0.5 0 0.5; 0 2 0])
2-element Array{Float64,1}:
2.5
0.5
source
Graphs.peripheryMethod
periphery(eccentricities)
periphery(g, distmx=weights(g))

Given a graph and optional distance matrix, or a vector of precomputed eccentricities, return the set of all vertices whose eccentricity is equal to the graph's diameter (that is, the set of vertices with the largest eccentricity).

Examples

julia> using Graphs

julia> periphery(star_graph(5))
4-element Array{Int64,1}:
2
3
4
5

julia> periphery(path_graph(5))
2-element Array{Int64,1}:
1
5
source
Graphs.radiusMethod
radius(eccentricities)
radius(g, distmx=weights(g))

Given a graph and optional distance matrix, or a vector of precomputed eccentricities, return the minimum eccentricity of the graph.

Examples

julia> using Graphs

2