easygraph.functions.path.diameter module#

easygraph.functions.path.diameter.diameter(G, e=None)[source]#

Returns the diameter of the graph G.

The diameter is the maximum eccentricity.

Parameters:
  • G (EasyGraph graph) – A graph

  • e (eccentricity dictionary, optional) – A precomputed dictionary of eccentricities.

Returns:

d – Diameter of graph

Return type:

integer

Examples

>>> G = eg.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> eg.diameter(G)
3

See also

eccentricity

easygraph.functions.path.diameter.eccentricity(G, v=None, sp=None)[source]#

Returns the eccentricity of nodes in G.

The eccentricity of a node v is the maximum distance from v to all other nodes in G.

Parameters:
  • G (EasyGraph graph) – A graph

  • v (node, optional) – Return value of specified node

  • sp (dict of dicts, optional) – All pairs shortest path lengths as a dictionary of dictionaries

Returns:

ecc – A dictionary of eccentricity values keyed by node.

Return type:

dictionary

Examples

>>> G = eg.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> dict(eg.eccentricity(G))
{1: 2, 2: 3, 3: 2, 4: 2, 5: 3}
>>> dict(eg.eccentricity(G, v=[1, 5]))  # This returns the eccentrity of node 1 & 5
{1: 2, 5: 3}