Package visgraph :: Module graphcore :: Class Graph
[hide private]
[frames] | no frames]

Class Graph

source code

Known Subclasses:


The base Graph object implements a simple nodes and edges graph.

Nodes -
    Nodes consist of a dicionary of properties about that node and
    a unique id which identifies the node in the current graph.  From
    API perspective a node is a tuple of (nodeid, nodeprops).

Edges -
    Edges are directional sets of a from node-id and to node-id and
    a piece of arbitrary edge information.

Instance Methods [hide private]
 
__init__(self) source code
 
setMeta(self, mprop, mval) source code
 
getMeta(self, mprop, default=None) source code
 
wipeGraph(self)
Re-initialize the graph structures and start clean again.
source code
 
getEdges(self)
Get the list of edges in the graph.
source code
 
getEdge(self, eid)
Get the (eid, fromid, toid, einfo) tuple for the specified edge.
source code
 
getEdgeInfo(self, eid, key, default=None)
Get a property about an edge specified by from/to id.
source code
 
setEdgeInfo(self, eid, key, value)
Set a key/value pair about a given edge by it's from/to id.
source code
 
setNodeInfo(self, nodeid, key, value)
Store a piece of information (by key:value) about a given node.
source code
 
getNodeInfo(self, nodeid, key, default=None)
Retrieve a piece of information about a given node by key.
source code
 
getNodeProps(self, nodeid)
Get the node info dictionary for the specified node.
source code
 
addNode(self, nodeid=None, ninfo=None, **kwargs)
Add a Node object to the graph.
source code
 
delNode(self, nid) source code
 
getNode(self, nodeid)
Return the dictionary of properties for the specified node id.
source code
 
getNodes(self)
Return a list of (nodeid, nodeinfo) tuples.
source code
 
hasNode(self, nodeid)
Check if a given node is present within the graph.
source code
 
addEdge(self, fromid, toid, eid=None, einfo=None, **kwargs)
Add an edge to the graph.
source code
 
delEdge(self, eid)
Delete an edge from the graph (by eid).
source code
 
getRefsFrom(self, nodeid)
Return a list of edges which originate with us.
source code
 
getRefsTo(self, nodeid)
Return a list of edges which terminate at us.
source code
 
getClusterGraphs(self)
Return a list of the subgraph clusters (as graphs) contained within this graph.
source code
 
pathSearchOne(self, *args, **kwargs) source code
 
pathSearch(self, fromid, toid=None, edgecb=None, tocb=None)
Search for the shortest path from one node to another with the option to filter based on edges using edgecb.
source code
 
pathSearchFrom(self, fromid, nodecb, edgecb=None)
Search from the specified node (breadth first) until you find a node where nodecb(graph, nid) == True.
source code
Method Details [hide private]

getEdges(self)

source code 

Get the list of edges in the graph. Edges are defined as (eid, fromid, toid, einfo) tuples.

Example: for eid, fromid, toid, einfo in g.getEdges():

getEdge(self, eid)

source code 

Get the (eid, fromid, toid, einfo) tuple for the specified edge.

Example: e = g.getEdge(eid)

getEdgeInfo(self, eid, key, default=None)

source code 

Get a property about an edge specified by from/to id.

Example: n = g.getEdgeInfo(eid 'name', 'Default Name')

setEdgeInfo(self, eid, key, value)

source code 

Set a key/value pair about a given edge by it's from/to id.

Example: g.setEdgeInfo(eid, 'awesomeness', 99)

setNodeInfo(self, nodeid, key, value)

source code 

Store a piece of information (by key:value) about a given node.

Example g.setNodeInfo(nid, 'Description', 'My Node Is Awesome!')

getNodeInfo(self, nodeid, key, default=None)

source code 

Retrieve a piece of information about a given node by key.

Example: descr = g.getNodeInfo(nid, 'Description', default='OH HAI')

getNodeProps(self, nodeid)

source code 

Get the node info dictionary for the specified node.

Example: d = g.getNodeProps(nid)

addNode(self, nodeid=None, ninfo=None, **kwargs)

source code 

Add a Node object to the graph.  Returns the nodeid.

Example: nid = g.addNode()
         g.addNode('woot', {'height':20, 'width':20})

NOTE: If nodeid is unspecified, it is considered an 'anonymous'
      node and will have an ID automagically assigned.

hasNode(self, nodeid)

source code 

Check if a given node is present within the graph.

Example: if g.hasNode('yermom'): print 'woot'

addEdge(self, fromid, toid, eid=None, einfo=None, **kwargs)

source code 

Add an edge to the graph. Edges are directional.

Example: g.addEdge(node_1, node_2, einfo={'name':'Woot Edge'})

delEdge(self, eid)

source code 

Delete an edge from the graph (by eid).

Example: g.delEdge(eid)

getRefsFrom(self, nodeid)

source code 

Return a list of edges which originate with us.

Example: for eid, fromid, toid, einfo in g.getRefsFrom(id)

getRefsTo(self, nodeid)

source code 

Return a list of edges which terminate at us.

Example: for eid, fromid, toid, einfo in g.getRefsFrom(id)

getClusterGraphs(self)

source code 

Return a list of the subgraph clusters (as graphs) contained within this graph. A subgraph "cluster" is defined as a group of interconnected nodes. This can be used to split out grouped subgraphs from within a larger graph.

pathSearch(self, fromid, toid=None, edgecb=None, tocb=None)

source code 

Search for the shortest path from one node to another with the option to filter based on edges using edgecb. edgecb should be a function:

def myedgecb(graph, eid, fromid, toid, depth)

which returns True if it's OK to traverse this node in the search.

Additionally, toid may be None and the caller may specify tocb with a function such as:

def mytocb(graph, nid)

which must return True on finding the target node

Returns a list of edge ids...

pathSearchFrom(self, fromid, nodecb, edgecb=None)

source code 

Search from the specified node (breadth first) until you find a node where nodecb(graph, nid) == True. See pathSearchFromTo for docs on edgecb...