1 :mod:`altgraph.GraphUtil` --- Utility functions 2 ================================================ 3 4 .. module:: altgraph.GraphUtil 5 :synopsis: Utility functions 6 7 The module :mod:`altgraph.GraphUtil` performs a number of more 8 or less useful utility functions. 9 10 .. function:: generate_random_graph(node_num, edge_num[, self_loops[, multi_edges]) 11 12 Generates and returns a :class:`Graph <altgraph.Graph.Graph>` instance 13 with *node_num* nodes randomly connected by *edge_num* edges. 14 15 When *self_loops* is present and True there can be edges that point from 16 a node to itself. 17 18 When *multi_edge* is present and True there can be duplicate edges. 19 20 This method raises :class:`GraphError <altgraph.GraphError` when 21 a graph with the requested configuration cannot be created. 22 23 .. function:: generate_scale_free_graph(steps, growth_num[, self_loops[, multi_edges]]) 24 25 Generates and returns a :py:class:`~altgraph.Graph.Graph` instance that 26 will have *steps*growth_n um* nodes and a scale free (powerlaw) 27 connectivity. 28 29 Starting with a fully connected graph with *growth_num* nodes 30 at every step *growth_num* nodes are added to the graph and are connected 31 to existing nodes with a probability proportional to the degree of these 32 existing nodes. 33 34 .. warning:: The current implementation is basically untested, although 35 code inspection seems to indicate an implementation that is consistent 36 with the description at 37 `Wolfram MathWorld <http://mathworld.wolfram.com/Scale-FreeNetwork.html>`_ 38 39 .. function:: filter_stack(graph, head, filters) 40 41 Perform a depth-first oder walk of the graph starting at *head* and 42 apply all filter functions in *filters* on the node data of the nodes 43 found. 44 45 Returns (*visited*, *removes*, *orphans*), where 46 47 * *visited*: the set of visited nodes 48 49 * *removes*: the list of nodes where the node data doesn't match 50 all *filters*. 51 52 * *orphans*: list of tuples (*last_good*, *node*), where 53 node is not in *removes* and one of the nodes that is connected 54 by an incoming edge is in *removes*. *Last_good* is the 55 closest upstream node that is not in *removes*. 56