maxitg / SetReplace

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

Convert Graphs to Hypergraphs #310

Open freemin7 opened 4 years ago

freemin7 commented 4 years ago

The problem

Mathematica comes with a set of pre-defined Graph Types such as GridGraph, CompleteGraph, ... and also GraphData. Having access to those in Hyper Graph land would be great.

Possible solution

Write conversion function from Graphs to Hyper Graphs.

Alternative solutions

Rewrite the entire Graph eco system to run on Hyper Graphs

Additional context

More information about the types of Graphs are available here: GraphConstructionAndRepresentation

maxitg commented 4 years ago

It's actually really simple. All you need is

toHypergraph[graph_] := List @@@ EdgeList @ graph

Then, i.e.,

In[] := toHypergraph[CompleteGraph[5]]
Out[] = {{1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}, {3, 4}, {3, 
  5}, {4, 5}}

Keep in mind though that our hypergraphs are ordered. If you want to faithfully represent an undirected graph as a hypergraph, take a look at section 7.2 of the Technical Introduction.