A graph is a block graph if it can be constructed from an undirected tree by replacing each edge with a clique. My method of generating "random" block graphs is as follows. The parameters are the number of blocks and the maximum size of any clique.
RandomBlockGraph[b_, max_] :=
Module[{g = Graph[{}], L = Table[i, {i, 1, b*max}]},
For[i = 1, i <= b, ++i,
r = RandomInteger[{2, max}];
h = IndexGraph[CompleteGraph[r], First[L]];
L = Drop[L, r - 1];
g = GraphUnion[g, h];
];
Return[g];
];
The function "glues" together cliques. The weakness is that right now, a vertex is joining at most 2 cliques. Here's a few examples of what the function spits out with RandomBlockGraph[3, 5]
:
It would be nice if my function could say take a tree, and then actually replace every edge with a clique. This would make it possible to get as an output say a star graph on $n$ vertices, where every edge was replaced with a clique. The current function can't do this, since every vertex joins at most 2 cliques.
How can I modify (or write a better function) for generating block graphs such that a vertex can join more than just 2 cliques?
u <-> v
in the tree, createmax - 2
fresh vertices and attach them all to each other and tou
andv
? $\endgroup$