SetReplace
SetReplace copied to clipboard
HypergraphDistanceMatrix
The problem
The function HypergraphDistanceMatrix should compute the distance between any 2 vertices in the hypergraph, similar to GraphDistanceMatrix, where (hypergraph) distance is (roughly) defined as the minimum length of a path that connects both vertices.
Possible solution
One "easy" solution is to use both HypergraphToGraph and GraphDistanceMatrix to compute this:
HypergraphDistanceMatrix[hg_, "Directed"] :=
GraphDistanceMatrix[HypergraphToGraph[hg, "DirectedDistancePreserving"]]
HypergraphDistanceMatrix[hg_, "Undirected"] :=
GraphDistanceMatrix[HypergraphToGraph[hg, "UndirectedDistancePreserving"]]
In[]:= vertexList = Sort@*Union@*Catenate;
With[{hg = {{x, x, y, z}, {z, w}, {w, a}}},
Table[
{method, TableForm[HypergraphDistanceMatrix[hg, method], TableHeadings -> Table[vertexList@hg, 2]]},
{method, {"Undirected", "Directed"}}] // Grid[#, Frame -> All, FrameStyle -> LightGray] &
]

Alternative solutions
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.