Graph union with gvpr

How do I use gvpr to create a union of the graphs specified on the command line and assign a different colour to the vertices and edges of each input graph?

Thanks,
Shaun

There are a lot of choices

There are a lot of choices you have left unspecified, such as what should happen if two input graphs have nodes with the same name and how much subgraph structure you want. But here is a simple version to get you started:

BEGIN {
  graph_t G = graph("union", "D");
  string color0, colors[int];
  colors[0] = "red";
  colors[1] = "green";
  colors[2] = "blue";
  colors[3] = "yellow";
  int idx;
  edge_t e;
}
BEG_G {
  color0 = colors[idx++];
}
E {
  e = clone(G,$);
  e.color = color0;
  e.head.color = color0;
  e.tail.color = color0;
}
END {
  write(G);
}

 

Thanks

That's great! Thanks, @erg!

Recent comments