delmulti 397 B

12345678910111213141516171819202122
  1. /* create a copy of the input graph with no multiedges */
  2. BEG_G {
  3. graph_t g = graph ("merge", "S");
  4. }
  5. E {
  6. int wt;
  7. node_t h = node(g,$.head.name);
  8. node_t t = node(g,$.tail.name);
  9. edge_t e = isEdge(t,h,"");
  10. wt = $.weight;
  11. if (wt <= 0) wt = 1;
  12. if (e) {
  13. e.weight = e.weight + wt;
  14. }
  15. else if (h != t) {
  16. e = edge(t,h,"");
  17. e.weight = wt;
  18. }
  19. }
  20. END_G {
  21. fwriteG(g,1);
  22. }