# Distance

*Graphs.jl* includes several distance measurements.

## Index

## Full docs

`Graphs.DefaultDistance`

— Type`DefaultDistance`

An array-like structure that provides distance values of `1`

for any `src, dst`

combination.

`Graphs.center`

— Method```
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 Vector{Int64}:
1
julia> center(path_graph(5))
1-element Vector{Int64}:
3
```

`Graphs.diameter`

— Method```
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
```

`Graphs.eccentricity`

— Method```
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> using Graphs
julia> g = SimpleGraph([0 1 0; 1 0 1; 0 1 0]);
julia> eccentricity(g, 1)
2
julia> eccentricity(g, [1; 2])
2-element Vector{Int64}:
2
1
julia> eccentricity(g, [1; 2], [0 2 0; 0.5 0 0.5; 0 2 0])
2-element Vector{Float64}:
2.5
0.5
```

`Graphs.periphery`

— Method```
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 Vector{Int64}:
2
3
4
5
julia> periphery(path_graph(5))
2-element Vector{Int64}:
1
5
```

`Graphs.radius`

— Method```
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
julia> radius(star_graph(5))
1
julia> radius(path_graph(5))
2
```