Python: module AIGO.go.Graph

AIGO.go.Graph | index /home/dpm/projects/AIGO-0.1.0/AIGO/go/Graph.py

`This module provides the classes used to model graphs:
- Graph, an undirected graph
- DiGraph, a directed graph.
In PyWeaver, all graph arguments are assumed to be either undirected graph-like or
directed graph-like, implementing all methods supported by the Graph and DiGraph classes.
The Graph is the base-class for all graphs. The DiGraph class extends Graph, redefining
methods where necessary in order to accomodate directed edges.`

Modules
`` |  |
AIGO.go.Constants | types |  |

Classes
`` |  | __builtin__.object Edge EdgeManager DirectedEdgeManager Graph DiGraph Node NodeManager DirectedNodeManager
class DiGraph(Graph)
`` | `A directed graph with support for multi-edges and self-loops. As in the undirected graph, every edge must have a unique decorator. If None is provided, then an edge is given a unique number decorator. Also as in the undirected graph, by default, nodes are indexed by their label field and edges are not indexed at all. All directed graphs should extend this class in order to ensure that they implement all methods expected of directed graphs. Accessing nodes and edges is done through the N and E fields. N is a NodeManager and E is an EdgeManager.`
| Method resolution order: DiGraph Graph __builtin__.object Methods defined here: __init__(self, graph=None, node_manager=None, edge_manager=None) `This method creates a new directed graph. A copy of another directed graph can be made by specifying the graph parameter.` indegree(self, node=None) `Return the in-degree of this graph. If a node is specified, then the in-degree of the node is returned. If a list of nodes are provided, then a list of in-degrees is returned, one for each node. If Constants.ALL is specified, then a list containing the in-degree of all the nodes in the graph is returned.` is_directed(self) neighbors(self, v, directed=True) `Return the neighbors of node v.` neighbors_iter(self, v, directed=True) `Return an iterator over the neighbors of node v.` outdegree(self, node=None) `Return the out-degree of this graph. If a node is specified, then the out-degree of the node is returned. If a list of nodes are provided, then a list of out-degrees is returned, one for each node. If Constants.ALL is specified, then a list containing the out-degree of all the nodes in the graph is returned.` source(self, e) `Return the source of the edge.` target(self, e) `Return the target of the edge.` Methods inherited from Graph: __getitem__(self, x) `Return the component with the primary index specified. If no component exists with the specified value for the primary index, then None is returned. If a slice colon is used, G.N[x:], then a list of components with the primary index specified is returned.` add_change_listener(self, listener) `#### # Listener methods` degree(self, node=None) `Return the degree of this graph. If a node is specified, then the degree of the node is returned. If a list of nodes are provided, then a list of degrees is returned, one for each node. If Constants.ALL is specified, then a list containing the degree of all the nodes in the graph is returned.` endpoint(self, e, u) `Returns the endpoint of edge e that is not u.` endpoints(self, e) `Return the endpoints of the edge. In a directed graph, the endpoints will be ordered such that the source is the first endpoint and the destination is the second endpoint.` remove_change_listener(self, listener) subgraph(self, nodes=None, edges=None) `Create a subgraph of this graph consisting of a subset of its nodes/edges. nodes and edges must be both iteratable objects. If only nodes are specified, then all edges connecting these nodes are included in the subgraph. If only edges are specified, then all nodes connected to these edges are included in the subgraph. If both nodes and edges are specified, then only these objects are included in the subgraph. Unless specified to the contrary, the subgraph constructed will be of the same type as the graph from which the subgraph is constructed. Once constructed, modifications to the subgraph are reflected in the parent of the subgraph` topology(self) `Returns a list of the edge topology which makes up the graph. Each entry in the list is a 2-tuple of (source,target) for an edge. If multi-edges exist in the graph then these edges will occur multiple times in the list.` Data descriptors inherited from Graph: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class DirectedEdgeManager(EdgeManager)
`` | `This class provides the E field in the directed graph. It behaves like a set of edges but also provides some additional utilities: selection and edge indexing.`
| Method resolution order: DirectedEdgeManager EdgeManager __builtin__.object Methods defined here: __call__(self, u=None, v=None, directed=True) `Return a list of the edges in this graph. The list is independent of the internal collection that is maintained by the Graph object. Thus, this list may be modified without affecting the graph from which it came. If only u is specified and directed is True, then only edges with u as their source are returned. If directed is False, then all edges adjacent to u are returned. If only v is specified and directed is True, then only edges with v as their target are returned. If directed is False, then all edges adjacent to v are returned. If u and v are specified then the list of edges connecting u to v are returned. If directed is False, then all edges connecting u and v are returned irrespective of the direction. If it is True, then an iterator is returned rather than a list.` __init__(self, graph) contains(self, u, v=None, directed=True) `If only u is specified, then this method returns True if the specified edge decorator is in this graph. If both u and v are specified, then this method returns True if there is an edge (u,v) in the graph. By default this method tests for directed edges. However, if directed is False, then the test for the edge is undirected.` get(self, u, v, directed=True) `Return the first edge found that connects the two nodes specified. This method does not guarantee that the same edge will be returned for different calls using the same endpoints. It is intended for use when it is known that no multi-edges exist between the two nodes. By default this method respects the direction indicated (from u to v). However, if directed is False, then this method finds any edge connecting u to v. The first one found is returned.` iter(self, u=None, v=None, directed=True) `Return an iterator over a subset of edges. If u or v is specified, then all edges leaving u or entering v are included. If u and v are specified then all the edges connecting u to v are included. By default, directionality is considered when determining what edges to return. However, if directed is False, then this method treats the graph like an undirected graph.` Methods inherited from EdgeManager: __clean_index_list__(self, el, iname, ival) `Check for stale (wrong) entries in the index list that need to be cleaned out. For convenience, this method returns a reference to the same list (el) that was passed in. At the end of this method, el will no longer contain any entries that do not have an attribute iname with value ival.` __contains__(self, e) `Returns True if e is an edge decorator in this graph.` __getitem__(self, x) `Return the edge with the primary index specified. If no edge exists with the specified value for the primary index, then None is returned. If a slice colon is used, G.N[x:], then a list of edges with the primary index specified is returned.` __iter__(self) `Return an iterator over the edges in the graph` __len__(self) `Return the number of edges in the graph.` add(self, u, v, e=None) `Add an edge to the graph. If either endpoint does not exist in the graph, it is added. Edges that do not have a decorator specified are assigned a unique integer decorator. The edge decorator is returned.` difference_update(self, edges) `Remove multiple edges from the graph.` discard(self, e) `Remove the edge e from the graph if it exists. Otherwise do nothing.` find(self, **args) `Return the first edge found with the index values specified.` find_all(self, **args) `Return a list of edges that have all the index values specified.` find_iter(self, **args) `Return an iterator over all the nodes that have all the index values specified.` index(self, *args) `Index the edge set using the field names specified. The first index name specified is the primary index.` reindex(self, e=None, index='ALL') `Reindex the edges specified for the indicies specified. e can either be one edge, a container of edges, or the ALL constant. By default, the edges are reindex for all indices (ALL). However if a string or a container of strings is specified, then the edges are reindexed only for those indices specified. This method needs to be called to notify the set when the value of an indexed field changes in an edge.` remove(self, e) `Remove the specified edge from the graph` select(x) `Return a list of edges for which x(e) evaluates True.` select_iter(x) `Return an iterator over the edges for which x(e) evaluates to True.` Data descriptors inherited from EdgeManager: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class DirectedNodeManager(NodeManager)
`` | `This class provides the N field in the directed graph. It behaves like a set of nodes but also provides some additional utilities: selection and node indexing.`
| Method resolution order: DirectedNodeManager NodeManager __builtin__.object Methods defined here: __init__(self, graph) Methods inherited from NodeManager: __call__(self) `Returns a list of nodes in the graph. This list is separate from any node lists used internally in the graph. Thus this list can be modified without affecting the graph from which it came.` __clean_index_list__(self, el, iname, ival) `Check for stale (wrong) entries in the index list that need to be cleaned out. For convenience, this method returns a reference to the same list (el) that was passed in. At the end of this method, el will no longer contain any entries that do not have an attribute iname with value ival.` __contains__(self, n) `Return True if the node n is in this graph.` __getitem__(self, x) `Return the node with the primary index specified. If no node exists with the specified value for the primary index, then None is returned. If a slice colon is used, G.N[x:], then a list of nodes with the primary index specified is returned.` __iter__(self) `Return an iterator over the nodes in the graph` __len__(self) `Returns the number of nodes in the graph.` add(self, n) `Add a node to the graph. The node must be unique otherwise a Exception will be raised.` difference_update(self, nodes) `Remove multiple nodes from the graph. All dependent edges are also removed from the graph.` discard(self, n) `Remove the node n from the graph if it exists. Otherwise do nothing.` find(self, **args) `Return the first node found with the index values specified.` find_all(self, **args) `Return a list of nodes that have all the index values specified.` find_iter(self, **args) `Return an iterator over all the nodes that have all the index values specified.` index(self, *args) `Index the node set using the field names specified. The first index name specified is the primary index.` reindex(self, n, index='ALL') `Reindex the nodes specified for the indicies specified. n can either be one node, a container of nodes, or the ALL constant. By default, the nodes are reindex for all indices (ALL). However if a string or a container of strings is specified, then the nodes are reindexed only for those indices specified. This method needs to be called to notify the set when the value of an indexed field changes in a node.` remove(self, n) `Remove a node from the graph. All dependent edges are also removed from the graph.` select(self, x) `Return a list of nodes for which x(n) evaluates True.` select_iter(self, x) `Return an iterator over the nodes for which x(n) evaluates to True.` update(self, nodes) `Add multiple nodes to the graph.` Data descriptors inherited from NodeManager: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class Edge(__builtin__.object)
`` | `This is a utility class that can be used rather than having to define one's own edge class. The Edge (or other user-defined) class is useful particularly when there is a need to define other fields - which system-defined types cannot manage. This class has exactly the behaviors of an object.`
| Methods defined here: __init__(self, **args) `This constructor initializes the edge with an arbitrary number of attributes. All parameters must have keywords specified. Each keyword-value pair is made an attribute (name is the keyword, attribute value is the value).` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class EdgeManager(__builtin__.object)
`` | `This class provides the E field in the graph. It behaves like a set of edges but also provides some additional utilities: selection and edge indexing.`
| Methods defined here: __call__(self, u=None, v=None) `Return a list of the edges in this graph. The list is independent of the internal collection that is maintained by the Graph object. Thus, this list may be modified without affecting the graph from which it came. If u or v is specified, then the list of edges adjacent to u or v are returned. If u and v are specified then the list of edges connecting u and v are returned.` __clean_index_list__(self, el, iname, ival) `Check for stale (wrong) entries in the index list that need to be cleaned out. For convenience, this method returns a reference to the same list (el) that was passed in. At the end of this method, el will no longer contain any entries that do not have an attribute iname with value ival.` __contains__(self, e) `Returns True if e is an edge decorator in this graph.` __getitem__(self, x) `Return the edge with the primary index specified. If no edge exists with the specified value for the primary index, then None is returned. If a slice colon is used, G.N[x:], then a list of edges with the primary index specified is returned.` __init__(self, graph) __iter__(self) `Return an iterator over the edges in the graph` __len__(self) `Return the number of edges in the graph.` add(self, u, v, e=None) `Add an edge to the graph. If either endpoint does not exist in the graph, it is added. Edges that do not have a decorator specified are assigned a unique integer decorator. The edge decorator is returned.` contains(self, u, v=None) `Return True if edge decorator u is in the edge set. If v is specified, then return True if there is an edge connecting nodes u and v.` difference_update(self, edges) `Remove multiple edges from the graph.` discard(self, e) `Remove the edge e from the graph if it exists. Otherwise do nothing.` find(self, **args) `Return the first edge found with the index values specified.` find_all(self, **args) `Return a list of edges that have all the index values specified.` find_iter(self, **args) `Return an iterator over all the nodes that have all the index values specified.` get(self, u, v) `Return the first edge found that connects the two nodes specified. If no edge is found, then None is returned. This method does not guarantee that the same edge will be returned for different calls using the same endpoints. It is intended for use when it is known that no multi-edges exist between the two nodes.` index(self, *args) `Index the edge set using the field names specified. The first index name specified is the primary index.` iter(self, u=None, v=None) `Return an iterator over a subset of edges. If u or v is specified, then all edges adjacent to u or v are included. If u and v are specified then all the edges connecting u and v are included.` reindex(self, e=None, index='ALL') `Reindex the edges specified for the indicies specified. e can either be one edge, a container of edges, or the ALL constant. By default, the edges are reindex for all indices (ALL). However if a string or a container of strings is specified, then the edges are reindexed only for those indices specified. This method needs to be called to notify the set when the value of an indexed field changes in an edge.` remove(self, e) `Remove the specified edge from the graph` select(x) `Return a list of edges for which x(e) evaluates True.` select_iter(x) `Return an iterator over the edges for which x(e) evaluates to True.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class Graph(__builtin__.object)
`` | `An undirected graph. Nodes can be any hashtable object. Edges can have any hashable decorator. The edge (u,v) is the same as the edge (v,u). Multi-edges and self-loops are supported in this graph. Every edge must have a unique decorator. If none is provided, then an edge is given a unique number decorator. Accessing nodes and edges is done through the N (or V) and E fields. N/V is a NodeManager and E is an EdgeManager. The V field may be preferred by those who are familiar with the formal definition of a graph as G = (V,E).`
| Methods defined here: __getitem__(self, x) `Return the component with the primary index specified. If no component exists with the specified value for the primary index, then None is returned. If a slice colon is used, G.N[x:], then a list of components with the primary index specified is returned.` __init__(self, graph=None, node_manager=None, edge_manager=None) `If no parameters are specified, then an empty graph is constructed. If the graph is specified, then a copy of that graph's topology is made. If the graph is directed, then an undirected version of that graph is made. By default, nodes are indexed by their label field and edges are not indexed at all. node_manager and edge_manager are input parameters that are for internal use only.` add_change_listener(self, listener) `#### # Listener methods` degree(self, node=None) `Return the degree of this graph. If a node is specified, then the degree of the node is returned. If a list of nodes are provided, then a list of degrees is returned, one for each node. If Constants.ALL is specified, then a list containing the degree of all the nodes in the graph is returned.` endpoint(self, e, u) `Returns the endpoint of edge e that is not u.` endpoints(self, e) `Return the endpoints of the edge. In a directed graph, the endpoints will be ordered such that the source is the first endpoint and the destination is the second endpoint.` is_directed(self) `Return whether this graph is directed. If the graph is directed, then it should extend DiGraph in order to implement the basic directed graph methods.` neighbors(self, v) `Return the neighbors of node v.` neighbors_iter(self, v) `Return an iterator over the neighbors of node v.` remove_change_listener(self, listener) subgraph(self, nodes=None, edges=None) `Create a subgraph of this graph consisting of a subset of its nodes/edges. nodes and edges must be both iteratable objects. If only nodes are specified, then all edges connecting these nodes are included in the subgraph. If only edges are specified, then all nodes connected to these edges are included in the subgraph. If both nodes and edges are specified, then only these objects are included in the subgraph. Unless specified to the contrary, the subgraph constructed will be of the same type as the graph from which the subgraph is constructed. Once constructed, modifications to the subgraph are reflected in the parent of the subgraph` topology(self) `Returns a list of the edge topology which makes up the graph. Each entry in the list is a 2-tuple of (source,target) for an edge. If multi-edges exist in the graph then these edges will occur multiple times in the list.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class Node(__builtin__.object)
`` | `This is a utility class that can be used rather than having to define one's own node class. The Node (or other user-defined) class is useful particularly when there is a need to define other fields - which system-defined types cannot manage. The Node constructor accepts arbitrary keyword-value arguments that will initialize the Node created to have a set of attributes. This class has all the behaviors of an object except in the way it renders itself as a string. If the self.label field is defined, then the value of this field is returned as the string representation of this node. Otherwise, the object string is returned.`
| Methods defined here: __init__(self, label=None, **args) `This constructor initializes the node with an arbitrary number of attributes. The first value specified is always the label for the Node. The label is set unless the value provided is None. All parameters that follow the label must have keywords specified. Each keyword-value pair is made an attribute (name is the keyword, attribute value is the value).` __str__(self) Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class NodeManager(__builtin__.object)
`` | `This class provides the V/N field in the graph. It behaves like a set of nodes but also provides some additional utilities: selection and node indexing.`
| Methods defined here: __call__(self) `Returns a list of nodes in the graph. This list is separate from any node lists used internally in the graph. Thus this list can be modified without affecting the graph from which it came.` __clean_index_list__(self, el, iname, ival) `Check for stale (wrong) entries in the index list that need to be cleaned out. For convenience, this method returns a reference to the same list (el) that was passed in. At the end of this method, el will no longer contain any entries that do not have an attribute iname with value ival.` __contains__(self, n) `Return True if the node n is in this graph.` __getitem__(self, x) `Return the node with the primary index specified. If no node exists with the specified value for the primary index, then None is returned. If a slice colon is used, G.N[x:], then a list of nodes with the primary index specified is returned.` __init__(self, graph) __iter__(self) `Return an iterator over the nodes in the graph` __len__(self) `Returns the number of nodes in the graph.` add(self, n) `Add a node to the graph. The node must be unique otherwise a Exception will be raised.` difference_update(self, nodes) `Remove multiple nodes from the graph. All dependent edges are also removed from the graph.` discard(self, n) `Remove the node n from the graph if it exists. Otherwise do nothing.` find(self, **args) `Return the first node found with the index values specified.` find_all(self, **args) `Return a list of nodes that have all the index values specified.` find_iter(self, **args) `Return an iterator over all the nodes that have all the index values specified.` index(self, *args) `Index the node set using the field names specified. The first index name specified is the primary index.` reindex(self, n, index='ALL') `Reindex the nodes specified for the indicies specified. n can either be one node, a container of nodes, or the ALL constant. By default, the nodes are reindex for all indices (ALL). However if a string or a container of strings is specified, then the nodes are reindexed only for those indices specified. This method needs to be called to notify the set when the value of an indexed field changes in a node.` remove(self, n) `Remove a node from the graph. All dependent edges are also removed from the graph.` select(self, x) `Return a list of nodes for which x(n) evaluates True.` select_iter(self, x) `Return an iterator over the nodes for which x(n) evaluates to True.` update(self, nodes) `Add multiple nodes to the graph.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`

Data
`` |  | __all__ = ['Graph', 'DiGraph', 'Node', 'Edge', 'NodeManager', 'EdgeManager', 'DirectedNodeManager', 'DirectedEdgeManager']