Package pygraph

Package pygraph


A library for working with graphs in Python.

Version: 1.8.2

Data structure classes are located at pygraph.classes.

Exception classes are located at pygraph.classes.exceptions.

Search filters are located at pygraph.algorithms.filters.

Heuristics for the A* algorithm are exposed in pygraph.algorithms.heuristics.

A quick introductory example:

>>> # Import the module and instantiate a graph object
>>> from pygraph.classes.graph import graph
>>> from pygraph.algorithms.searching import depth_first_search
>>> gr = graph()
>>> # Add nodes
>>> gr.add_nodes(['X','Y','Z'])
>>> gr.add_nodes(['A','B','C'])
>>> # Add edges
>>> gr.add_edge(('X','Y'))
>>> gr.add_edge(('X','Z'))
>>> gr.add_edge(('A','B'))
>>> gr.add_edge(('A','C'))
>>> gr.add_edge(('Y','B'))
>>> # Depth first search rooted on node X
>>> st, pre, post = depth_first_search(gr, root='X')
>>> # Print the spanning tree
>>> print st
{'A': 'B', 'C': 'A', 'B': 'Y', 'Y': 'X', 'X': None, 'Z': 'X'}


  __package__ = None