Package networkx :: Module paths

[frames | no frames]

## Module networkx.paths

Shortest paths, diameter, radius, eccentricity, and related methods.

Function Summary
| ``center`(G, e)` Center of graph.
| ``diameter`(G, e)` Diameter of graph.
| ``dijkstra`(G, source, target)` Dijkstra's algorithm for shortest paths in a weighted graph.
| ``dijkstra_path`(G, source, target)` Returns the shortest path for a weighted graph using Dikjstra's algorithm.
| ``dijkstra_path_length`(G, source, target)` Returns the shortest path length for a weighted graph using Dikjstra's algorithm .
| ``eccentricity`(G, v, sp, **kwds)` Eccentricity of node v.
| ``is_directed_acyclic_graph`(G)` Test if a graph is a directed acyclic graph (DAG).
| ``periphery`(G, e)` Periphery of graph.
| ``radius`(G, e)` Radius of graph Minimum of all pairs shortest path.
| ``shortest_path`(G, source, target, cutoff)` Returns list of nodes in a shortest path between source and target (there might be more than one).
| ``shortest_path_length`(G, source, target)` Shortest path length from source to target.
| ``topological_sort`(G)` Return a list of nodes of the graph G in topological sort order.
| ``topological_sort_recursive`(G)` Return a list of nodes of the graph G in topological sort order.

Variable Summary
`str` | `__author__` = `'Aric Hagberg (hagberg@lanl.gov)\nDan Schul...`
`str` | `__credits__` = `''`
`str` | `__date__` = `'$Date: 2005-06-16 14:29:18 -0600 (Thu, 16 Ju...`
`str` | `__revision__` = `'$Revision: 1046 $'`

Function Details

### center(G, e=None)

Center of graph. Nodes with eccentricity equal to radius.

### diameter(G, e=None)

Diameter of graph. Maximum of all pairs shortest path.

### dijkstra(G, source, target=None)

Dijkstra's algorithm for shortest paths in a weighted graph.

See

dijkstra_path() - shortest path list of nodes dijkstra_path_length() - shortest path length

Returns a tuple of two dictionaries keyed by node. The first stores distance from the source. The second stores the path from the source to that node.

Distances are calculated as sums of weighted edges traversed. Edges must hold numerical values for XGraph and XDiGraphs. The weights are 1 for Graphs and DiGraphs.

Optional target argument stops the search when target is found.

Based on python cookbook recipe (119466) at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/119466

This algorithm is not guaranteed to work if edge weights are negative or are floating point numbers ( overflows and roundoff erros can cause problems).

### dijkstra_path(G, source, target=None)

Returns the shortest path for a weighted graph using Dikjstra's algorithm.

The path is computed from the source to an optional target. If a target is specified the path is returned as a list of nodes. If the target is not specified a dictionary of path lists keyed by target node is returned.

Edge data must be numerical values for XGraph and XDiGraphs. The weights are assigned to be 1 for Graphs and DiGraphs.

See also "dijkstra" for more information about the algorithm.

### dijkstra_path_length(G, source, target=None)

Returns the shortest path length for a weighted graph using Dikjstra's algorithm .

The path length is computed from the source to an optional target. If a target is specified the length is returned as an integer. If the target is not specified a dictionary of path lengths keyed by target node is returned.

Edge data must be numerical values for XGraph and XDiGraphs. The weights are assigned to be 1 for Graphs and DiGraphs.

See also "dijkstra" for more information about the algorithm.

### eccentricity(G, v=None, sp=None, **kwds)

Eccentricity of node v. Maximum of shortest paths to all other nodes.

If kwds with_labels=True return dict of eccentricities keyed by vertex.

### is_directed_acyclic_graph(G)

Test if a graph is a directed acyclic graph (DAG).

Return True if G is a DAG. False if not.

### periphery(G, e=None)

Periphery of graph. Nodes with eccentricity equal to diameter.

### radius(G, e=None)

Radius of graph Minimum of all pairs shortest path.

### shortest_path(G, source, target=None, cutoff=None)

Returns list of nodes in a shortest path between source and target (there might be more than one). If no target is specified, returns dict of lists of paths from source to all nodes. Cutoff is a limit on the number of hops traversed.

### shortest_path_length(G, source, target=None)

Shortest path length from source to target.

### topological_sort(G)

Return a list of nodes of the graph G in topological sort order.

A topological sort is a nonunique permutation of the nodes such that an edge from u to v implies that u appears before v in the topological sort order.

If G is not a directed acyclic graph no topological sort exists and the Python keyword None is returned.

This algorithm is based on a description and proof at http://www2.toki.or.id/book/AlgDesignManual/book/book2/node70.htm

See also is_directed_acyclic_graph()

### topological_sort_recursive(G)

Return a list of nodes of the graph G in topological sort order.

This is a recursive version of topological sort.

Variable Details

### __author__

  Type:
    `str`
  Value:

        '''Aric Hagberg (hagberg@lanl.gov)
        Dan Schult(dschult@colgate.edu)'''

### __credits__

  Type:
    `str`
  Value:

        ''

### __date__

  Type:
    `str`
  Value:

        '$Date: 2005-06-16 14:29:18 -0600 (Thu, 16 Jun 2005) $'

### __revision__

  Type:
    `str`
  Value:

        '$Revision: 1046 $'

Generated by Epydoc 2.1 on Sun Aug 21 08:06:58 2005 | http://epydoc.sf.net