Package entropy :: Module graph :: Class Graph

Class Graph

source code


This class represents a Graph object. Elements can be added using the add() method and sorted using solve(). This class can also return an adjacency map representing the currently stored elements in graph. A topological sorting algorithm (using Tarjan's) is used to by solve().

Instance Methods
 
__init__(self)
Graph representation constructor.
source code
 
destroy(self)
Cleanup any reference.
source code
entropy.graph.GraphNode
get_node(self, item)
Return GraphNode instance for added item (through add())
source code
 
add(self, item, dependency_items)
Add arbitrary object to Graph, specifying its dependencies.
source code
dict
get_adjacency_map(self)
Return an adjacency map given the current items in Graph.
source code
dict
solve_nodes(self)
This method is equal to solve() but doesn't do any item back-translation and just returns the relation between GraphNode objects that can be manipulated directly by the caller.
source code
dict
solve(self)
Thanks to "R.
source code
list
raw(self)
Return all items stored in the graph in raw form (list) without sorting them.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

source code 

Graph representation constructor.

Overrides: object.__init__

get_node(self, item)

source code 

Return GraphNode instance for added item (through add())

Parameters:
  • item (Python object) - Python object to be added to the graph
Returns: entropy.graph.GraphNode
GraphNode instance bound to item
Raises:
  • KeyError - if item is not in Graph

add(self, item, dependency_items)

source code 

Add arbitrary object to Graph, specifying its dependencies.

Parameters:
  • item (Python object) - Python object to be added to the graph
  • dependency_items (set) - list of items which are dependencies of the given item object

get_adjacency_map(self)

source code 

Return an adjacency map given the current items in Graph.

Returns: dict
adjacency map

solve_nodes(self)

source code 

This method is equal to solve() but doesn't do any item back-translation and just returns the relation between GraphNode objects that can be manipulated directly by the caller.

Returns: dict
sorted graph representation (returning GraphNode objects)

solve(self)

source code 

Thanks to "R. E. Tarjan" (1972) for the help ;-) Serialize the graph and spit out a dependency order. Data is returned in map form, where key represents the dependency level and value a list of items at that dependency level.

Returns: dict
sorted graph representation

raw(self)

source code 

Return all items stored in the graph in raw form (list) without sorting them.

Returns: list
list of items added to Graph