| 1 |
/* Given a bipartite graph, induce a non-bipartite graph. |
| 2 |
* argv[0]="name=value" This is used to identify the nodes used |
| 3 |
* to induce edges. If aget(n,name) == value, |
| 4 |
* if deg(n) == 1, delete |
| 5 |
* if deg(n) == 2, delete and connect to neighbor with edge |
| 6 |
* if deg(n) > 2, delete and add edge between all pairs of neighbors |
| 7 |
* Add weights to edge. |
| 8 |
*/ |
| 9 |
BEGIN{ |
| 10 |
int i, cnt; |
| 11 |
int wt[edge_t]; |
| 12 |
string values[int]; |
| 13 |
node_t nbrs[int]; |
| 14 |
edge_t e; |
| 15 |
tokens(ARGV[0],values,"="); |
| 16 |
string aname = values[0]; |
| 17 |
string value = values[1]; |
| 18 |
printf(2, "%s=%s\n", aname, value); |
| 19 |
} |
| 20 |
N[aget($,aname)==value] { |
| 21 |
if ($.degree > 1) { |
| 22 |
cnt = 0; |
| 23 |
for (e = fstedge($); e; e = nxtedge(e, $)) |
| 24 |
nbrs[cnt++] = opp(e,$); |
| 25 |
for (i = 0; i < cnt-1; i++) { |
| 26 |
if ((e = isEdge(nbrs[i],nbrs[i+1],"")) != NULL) { |
| 27 |
wt[e] += 1; |
| 28 |
} |
| 29 |
else if ($G.directed && (e = isEdge(nbrs[i+1],nbrs[i],""))) { |
| 30 |
wt[e] += 1; |
| 31 |
} |
| 32 |
else if (nbrs[i] != nbrs[i+1]) { // avoid loops |
| 33 |
e = edge(nbrs[i],nbrs[i+1],""); |
| 34 |
wt[e] = 1; |
| 35 |
} |
| 36 |
} |
| 37 |
unset(nbrs); |
| 38 |
} |
| 39 |
delete($G,$); |
| 40 |
} |
| 41 |
END_G{ |
| 42 |
for (wt[e]) { |
| 43 |
e.multiplicity = sprintf ("%d", wt[e]); |
| 44 |
} |
| 45 |
} |