clustg 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Create derived graph whose nodes are top-level clusters (any nodes not in top-level clusters are trivial top-level clusters),
  2. * and there is an edge between two nodes in the derived graph if there is an edge between the clusters in the original graph.
  3. * The new graph is directed if the original one is; it is strict. Edges within clusters are ignored.
  4. * Nodes and edges have a _cnt attribute indicating the number of node in a cluster and the number of equivalent edges, respectively.
  5. */
  6. BEGIN {
  7. graph_t dg;
  8. graph_t c[node_t];
  9. node_t nmap[node_t];
  10. node_t n, n0, dn, dn0;
  11. edge_t e;
  12. void proc (graph_t h, graph_t g)
  13. {
  14. if (h.name == "cluster*") {
  15. dn = node(dg, h.name);
  16. dn._cnt = (string)(h.n_nodes);
  17. for (n = fstnode(h); n; n = nxtnode_sg(h,n)) {
  18. n0 = nmap[n];
  19. if (n0) {
  20. printf(2,"node %s in %s and %s\n", n.name, h.name, n0.name);
  21. exit(1);
  22. }
  23. nmap[n] = dn;
  24. }
  25. return;
  26. }
  27. for (g = fstsubg(h); g; g = nxtsubg(g)) {
  28. proc(g,NULL);
  29. }
  30. }
  31. }
  32. BEG_G{
  33. dg = graph("clust"+name, isDirect($)?"DS":"US");
  34. setDflt(dg,"E","_cnt","0");
  35. setDflt(dg,"N","_cnt","0");
  36. proc($,NULL);
  37. $tvtype = TV_ne;
  38. }
  39. N[!nmap[$]]{
  40. dn = node(dg, name);
  41. nmap[$] = dn;
  42. }
  43. E{
  44. dn0 = nmap[$.tail];
  45. dn = nmap[$.head];
  46. if (dn != dn0) {
  47. e = edge(dn0,dn,"");
  48. e._cnt = (string)(1+(int)e._cnt);
  49. }
  50. }
  51. END_G {
  52. write(dg);
  53. }