Skip to content

Commit

Permalink
Simple WL implementation of SetReplace (#2)
Browse files Browse the repository at this point in the history
## Changes

* Implements SetReplace and related functions in Wolfram Language.
  * Implementation is slow, but it can be used to test C++ implementation.
* Implements HypergraphPlot, that plots a set of directed hyperedges (lists) as a Graph with each hyperedge represented as a series of arrows.
* Adds argument checks for all functions.
* Implements unit tests for all functions.

## Test

### Split and combine edges
* Evaluate a rule that splits a single edge into two, and plot the results:
`HypergraphPlot[manyEdges = SetReplace[{{0, 1}}, {{a_, b_}} :> Module[{$0}, {{a, $0}, {$0, b}}], 5]]`
![image](https://user-images.githubusercontent.com/1479325/50428198-23b30080-086a-11e9-8b4b-3626ccf04c02.png)
* Reduce it back to a single edge:
`SetReplaceFixedPoint[manyEdges, {{a_, b_}, {b_, c_}} :> {{a, c}}]`
* You should see `{{0, 1}}` as output.

### Point to a triangle
* As a more complicated example, try converting a point with 3 connections into a triangle:
`HypergraphPlot[
 SetReplace[{{0, 1}, {0, 2}, {0, 3}}, {{a_, b_}, {a_, c_}, {a_, d_}} :> Module[{$1, $2, $3}, {{$1, $2}, {$2, $3}, {$3, $1}, {$1, $3}, {$3, $2}, {$2, $1}, {$1, b}, {$2, c}, {$3, d}}], 1 + 3 + 9 + 27], ColoredEdgeShapeFunction -> (Line[#1] &)]`
![image](https://user-images.githubusercontent.com/1479325/50429569-2d416600-0874-11e9-8225-bf6ed1b39c0f.png)

### Unit tests
* Import or evaluate the package: `Get["path to SetReplace.wl"]`.
* Run unit tests: `TestReport["path to SetReplace.wlt"]`
  • Loading branch information
maxitg committed Dec 26, 2018
1 parent 9444628 commit d85b14c
Show file tree
Hide file tree
Showing 2 changed files with 681 additions and 0 deletions.

0 comments on commit d85b14c

Please sign in to comment.