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

Subhypergraph #412

Closed
maxitg opened this issue Sep 17, 2020 · 1 comment · Fixed by #431
Closed

Subhypergraph #412

maxitg opened this issue Sep 17, 2020 · 1 comment · Fixed by #431
Labels
analysis Adds or changes evolution analysis tools, e.g., `WolframModelEvolutionObject` properties feature New functionality, or change in existing functionality good first issue Good for newcomers help wanted Extra attention is needed wolfram language Requires Wolfram Language implementation

Comments

@maxitg
Copy link
Owner

maxitg commented Sep 17, 2020

The problem

Subhypergraph is a small utility function that selects hyperedges that only contain vertices from the requested list.

Possible solution

Subhypergraph[h_, vertices_] := 
 Select[h, AllTrue[#, MemberQ[vertices, #] &] &]
In[] := Subhypergraph[{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}, {1, 2, 3, 4}]
Out[] = {{1, 2, 3}, {2, 3, 4}}
@maxitg maxitg added feature New functionality, or change in existing functionality help wanted Extra attention is needed analysis Adds or changes evolution analysis tools, e.g., `WolframModelEvolutionObject` properties wolfram language Requires Wolfram Language implementation good first issue Good for newcomers labels Sep 17, 2020
@taliesinb
Copy link
Collaborator

I suggest also WeakSubhypergraph that uses AnyTrue instead of AllTrue.

maxitg pushed a commit that referenced this issue Oct 10, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
## Changes
* Closes #412.
* Adding `Subhypergraph[h_, vertices_]` utility function that selects hyperedges from `h` that are subsets of `vertices`.
* Adding the weak version of the previous function: `WeakSubhypergraph[h_, vertices_]` that selects any hyperedge from `h` whose elements are contained in `vertices`.

## Comments
* The second argument of these functions should probably support a `pattern`.

## Examples
* Simple examples:
```wl
In[]:= Subhypergraph[{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}, {1, 2, 3, 4}]

Out[]= {{1, 2, 3}, {2, 3, 4}}
```
```wl
In[]:= WeakSubhypergraph[{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}, {1, 2, 3, 4}]

Out[]= {{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}
```

* Small table comparing the functions:
```wl
With[{h = {{1, 1, 2, 3}, {2, 3, 4}, {2, 3, 4}, {4}}},
 {allV = Subsets[Union@Catenate[h]]},
 TableForm[
  {Function[v, Select[h, AllTrue[#, MemberQ[v, #] &] &]][#], 
     Subhypergraph[h, #], WeakSubhypergraph[h, #]} & /@ allV,
  TableHeadings -> {allV, None}, TableDepth -> 2
  ]
 ]
```
![image](https://user-images.githubusercontent.com/40190339/95042910-e0253180-06a0-11eb-9095-9e3c20cab9a0.png)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/maxitg/setreplace/431)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis Adds or changes evolution analysis tools, e.g., `WolframModelEvolutionObject` properties feature New functionality, or change in existing functionality good first issue Good for newcomers help wanted Extra attention is needed wolfram language Requires Wolfram Language implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants