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

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

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

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

add a comment

1

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
```

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

Asked: **
2013-04-22 01:05:23 -0500
**

Seen: **218 times**

Last updated: **Apr 22 '13**

optimizing graph coloring for small chromatic number

How do I get the external face of a planar embedded graph?

How to create curved, directed, and labelled edges of a graph

How to list all the connected graphs with 9 vertices?

Find linear combinations that meet certain criteria

Dictating the roots to RootSystem

How to slice an unknown length iterator

Newton's cubic Fractal help. Plotting

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.