Ask Your Question
0

code for tail and head of an edge in a bipartite graph

asked 2013-04-22 08:05:23 +0100

REKHA BISWAL gravatar image

updated 2015-01-14 12:19:15 +0100

FrédéricC gravatar image

how to write a code for finding tail and head of an edge in a bipartite graph?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2013-04-22 09:00:48 +0100

Jesustc gravatar image

updated 2013-04-22 10:05:01 +0100

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
edit flag offensive delete link more

Comments

i looked to that but could not find proper code which i wanted..

REKHA BISWAL gravatar imageREKHA BISWAL ( 2013-04-22 09:33:13 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-04-22 08:05:23 +0100

Seen: 498 times

Last updated: Apr 22 '13