maxitg / SetReplace

C++/Wolfram Language package for exploring set and graph rewriting systems
MIT License
219 stars 45 forks source link

RandomHypergraph #510

Closed daneelsan closed 3 years ago

daneelsan commented 4 years ago

The problem

Implement the RandomHypergraph function.

Possible solution

A possible implementation and API is found in the WFR:

RandomHypergraph[{n_Integer, {e_Integer, a_Integer}}] := 
 RandomInteger[{1, n}, {e, a}]

RandomHypergraph[{n_Integer, sig : {{_Integer, _Integer} ..}}] := 
 Catenate[RandomInteger[{1, n}, #] & /@ sig]

image

In[]:= RandomHypergraph[{10, {5, 2}}]
Out[]= {{5, 4}, {7, 8}, {7, 6}, {7, 1}, {4, 9}}
In[]:= RandomHypergraph[{10, {{5, 2}, {4, 3}}}]
Out[]= {{1, 2}, {2, 9}, {6, 1}, {3, 3}, {10, 10}, {1, 8, 8}, {5, 7, 9}, {5, 
  7, 6}, {5, 3, 3}}
maxitg commented 4 years ago

I think another useful API would be just specifying the total number of hyperedge parts (essentially, the "complexity").

E.g., for {{1, 2, 3}, {3, 4}, {4, 5, 6}}, this number will be 8.

This way, one can generate any possible hypergraph by varying just one parameter. This will be even more useful for enumeration.

maxitg commented 4 years ago

It might also be useful to generate connected hypergraphs (maybe with an option).