Home | Trees | Index | Help |
|
---|
Package CedarBackup2 :: Module util :: Class DirectedGraph |
|
object
--+
|
DirectedGraph
Represents a directed graph.
A graph G=(V,E) consists of a set of vertices V together
with a set E of vertex pairs or edges. In a directed graph, each
edge also has an associated direction (from vertext v1 to vertex
v2). A DirectedGraph
object provides a way to
construct a directed graph and execute a depth- first search.
This data structure was designed based on the graphing chapter in The Algorithm Design Manual, by Steven S. Skiena.
This class is intended to be used by Cedar Backup for dependency ordering. Because of this, it's not quite general-purpose. Unlike a "general" graph, every vertex in this graph has at least one edge pointing to it, from a special "start" vertex. This is so no vertices get "lost" either because they have no dependencies or because nothing depends on them.Method Summary | |
---|---|
Directed graph constructor. | |
Definition of equals operator for this class. | |
Official string representation for class instance. | |
Informal string representation for class instance. | |
Adds an edge with an associated direction, from start
vertex to finish vertex. | |
Creates a named vertex. | |
Implements a topological sort of the graph. | |
Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__setattr__('name', value) <==> x.name = value |
Property Summary | |
---|---|
name : Name of the graph. |
Method Details |
---|
__init__(self,
name)
Directed graph constructor.
|
__cmp__(self,
other)
Definition of equals operator for this class.
|
__repr__(self)
Official string representation for class instance.
|
__str__(self)
Informal string representation for class instance.
|
createEdge(self, start, finish)Adds an edge with an associated direction, fromstart
vertex to finish vertex.
|
createVertex(self, name)Creates a named vertex.
|
topologicalSort(self)Implements a topological sort of the graph. This method also enforces that the graph is a directed acyclic graph, which is a requirement of a topological sort. A directed acyclic graph (or "DAG") is a directed graph with no directed cycles. A topological sort of a DAG is an ordering on the vertices such that all edges go from left to right. Only an acyclic graph can have a topological sort, but any DAG has at least one topological sort. Since a topological sort only makes sense for an acyclic graph, this method throws an exception if a cycle is found. A depth-first search only makes sense if the graph is acyclic. If the graph contains any cycles, it is not possible to determine a consistent ordering for the vertices.
|
Property Details |
---|
nameName of the graph. |
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Thu Mar 29 20:58:27 2007 | http://epydoc.sf.net |