On Sun, May 05, 2013 at 12:08:24PM -0700, Alex Roper wrote:
>
https://github.com/calmofthestorm/networkx/blob/master/networkx/algorithms/lowest_common_ancestor.py
Wow, thanks; I will study it and see how we can get it done.
>I still need to update the documentation and write tests, so any
>feedback you have is appreciated, especially on the api.
Couple of comments:
1. the indentation with two-spaces will bring you pain, better stick
to 4-spaces and PEP8
2. pass a pylint and you will see a couple of potential errors and
problems (such as non-initialized variables)
3. This �depths� is really root_distance, is not it?
depths = nx.shortest_path_length(G, source=root)
feasible = ancestors1.intersection(ancestors2)
if feasible:
return max(feasible, key=depths.get)
4. I would probably add a:
def lca(G, node1, node2, root=None):
if not root:
roots = [n for n in G.nodes() if G.predecessors(n) == 0]