Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You may want to take a look to this, and in particular this. Good luck!

You may want to take a look to this, and in particular this. Good luck!

UPDATE

Let $G$ be a bipartite graph that you have generated using one of the ways commented in the 2nd link above. Now you want to take an edge and get its head an tail. In order to do that, you can just identify the sets of tails and heads with the "bipartition" method of the graph, and check which of the vertices of an edge is in which set. It could be something like

tail_set, head_set = G.bipartition()
print "Set of tails: ",tail_set
print "Set of heads: ",head_set
for edge in G.edges():
    v1, v2 = edge[:2]
    tail = (v1 if v1 in tail_set else v2)
    head = (v1 if tail == v2 else v2)
    print "Edge: ",edge
    print "  Tail: ",tail,", Head: ",head