Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hypergraph head symbol #494

Open
maxitg opened this issue Oct 26, 2020 · 4 comments
Open

Hypergraph head symbol #494

maxitg opened this issue Oct 26, 2020 · 4 comments
Assignees
Labels
feature New functionality, or change in existing functionality utilities Has to do with utility functions such as WolframModelRuleData, HypergraphUnifications, etc. wolfram language Requires Wolfram Language implementation

Comments

@maxitg
Copy link
Owner

maxitg commented Oct 26, 2020

The problem

Have a Hypergraph symbol analogous to Graph, which will convert Hypergraph[{hyperedges... }] to a (hopefully) optimized standard form. This will make easier the addition of new functions for working with hypergraphs as we could overload WL symbol (e.g. VertexList, EdgeAdd, etc.). Also, the head would allows as to make use of MakeBoxes to represent the hypergraph using HypergraphPlot.

Possible solution

Proposed functionality:

vertexList = Sort @* Union @* Catenate;
hypergraphQ = MatchQ[Hold[#], Hold[Hypergraph[_List, {__Hyperedge}, ___]]] &;

Hypergraph[hypergraph : {__List}] :=
 Hypergraph[
  vertexList @ hypergraph,
  Apply[Hyperedge] /@ hypergraph]

Hypergraph /: Normal[hg_Hypergraph ? hypergraphQ] := List @@@ hg[[2]]

Hypergraph /: MakeBoxes[
  hg_Hypergraph ? hypergraphQ,
  fmt_] := ToBoxes @ WolframModelPlot[Normal @ hg]
In[]:= Hypergraph[{{x, x, y, z}, {z, w}}]

image

In[]:= % // InputForm
Out[]//InputForm= Hypergraph[{w, x, y, z}, {Hyperedge[x, x, y, z], Hyperedge[z, w]}]

Comment

Should the hyperedges be of the form Hyperedge[{x, x, y, z}] instead of Hyperedge[x, x, y, z]? The idea was to specify directedness as a second argument, i.e. Hyperedge[..., "Directed" | "Undirected"].

Additional context

The symbol should probably optimize when the hypergraph is solely composed of integer, i.e. by using PackedArray's.

@maxitg maxitg added the feature New functionality, or change in existing functionality label Oct 26, 2020
@daneelsan daneelsan changed the title Hypergraph head Hypergraph head symbol Oct 26, 2020
@maxitg
Copy link
Owner Author

maxitg commented Oct 30, 2020

The box should be some kind of an interpretation box (ideally with a purple frame like Graph if possible). Otherwise, if you copy it and use it as an input, it does not work.

And yes, the format should be Hyperedge[{vertices...}] because, as you say, we need the second argument for other functionality.

@maxitg maxitg added utilities Has to do with utility functions such as WolframModelRuleData, HypergraphUnifications, etc. wolfram language Requires Wolfram Language implementation labels Oct 30, 2020
@daneelsan
Copy link
Collaborator

Yes, that was really a quick implementation. As you said, the idea would be to TimeConstrain it and show the Graph-like box if it takes too much time.

@maxitg
Copy link
Owner Author

maxitg commented Oct 30, 2020

We can probably estimate how long it would take and constrain based on the number of vertices/hyperedges.

@taliesinb
Copy link
Collaborator

taliesinb commented Nov 2, 2020

I'd like to suggest the following syntax for when it comes time to implement symmetries on hyperedges:

  • DirectedHyperedge[{1, 2, 3}, {4, 5, 6}]
  • UndirectedHyperedge[{1, 2, 3}, {4, 5, 6}] (which is the same as UndirectedHyperedge[{4, 5, 6}, {1, 2, 3}])
  • ColoredHyperedge[{1 → 1, 2 → 1, 3 → 2, 4 → 2}] (which is ColoredHyperedge[{1, 2, 3, 4} → {1, 2, 2}])

These all evaluate to Hyperedge[vertexlist, symmetrygroup].
The symmetry for colors is fully symmetric within each color.
The symmetry for directed and undirected hyperedges is fully symmetric within the source, and the destination separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality, or change in existing functionality utilities Has to do with utility functions such as WolframModelRuleData, HypergraphUnifications, etc. wolfram language Requires Wolfram Language implementation
Projects
None yet
Development

No branches or pull requests

3 participants