graphutil.rst 2.1 KB

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