Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connect C++ code to SetReplace function (#17)
## Changes * Attaches C++ code from #13 to `SetReplace` function in WL package, so that it is automatically used over LibraryLink for supported rule types. * Adds `Method` option to `SetReplace` that allows one to choose between C++ and Wolfram Language implementations. * Build script now builds the C++ library with `xcodebuild` and puts it into the paclet (only available on macOS). * Implements unit tests for C++ code. ## Tests * Build with `./build.wls` and install the created paclet file `SetReplace-0.1.paclet` by evaluating `PacletInstall["path_to_paclet"]` in Wolfram Language, and then import by ``<< SetReplace` ``. * Run the unit tests in `SetReplace.wlt`: evaluate `TestReport["path_to_wlt_file"]`. * Check that C++ implementation is significantly faster: ``` ListPlot[Table[{i, AbsoluteTiming[ SetReplace[{{0, 0}, {0, 0}, {0, 0}}, FromAnonymousRules[{{{1, 2}, {1, 3}, {1, 4}} -> {{5, 6}, {6, 7}, {7, 5}, {5, 7}, {7, 6}, {6, 5}, {5, 2}, {6, 3}, {7, 4}, {2, 7}, {4, 5}}}], i, Method -> #]][[1]]}, {i, 10, 100, 10}] & /@ {"WolframLanguage", "C++"}, PlotLegends -> {"WL", "C++"}, AxesLabel -> {"Iterations", "Time, s"}] ``` ![image](https://user-images.githubusercontent.com/1479325/59168046-b0403b00-8af9-11e9-91ee-87ce3827462a.png) * C++ time scales linearly with the number of steps, unlike previous WL implementation: ``` ListPlot[Table[{i, AbsoluteTiming[ SetReplace[{{0, 0}, {0, 0}, {0, 0}}, FromAnonymousRules[{{{1, 2}, {1, 3}, {1, 4}} -> {{5, 6}, {6, 7}, {7, 5}, {5, 7}, {7, 6}, {6, 5}, {5, 2}, {6, 3}, {7, 4}, {2, 7}, {4, 5}}}], i, Method -> "C++"]][[1]]}, {i, 100, 1000, 100}], AxesLabel -> {"Iterations", "Time, s"}] ``` ![image](https://user-images.githubusercontent.com/1479325/59168191-4f653280-8afa-11e9-9520-673bfc63e3fd.png) * This allows one to get some massive graphs, for example, this takes ~3.5 minutes and produces a graph with 1 million edges: ``` Graph[DirectedEdge @@@ SetReplace[{{0, 0}, {0, 0}, {0, 0}}, FromAnonymousRules[{{{1, 2}, {1, 3}, {1, 4}} -> {{5, 6}, {6, 7}, {7, 5}, {5, 7}, {7, 6}, {6, 5}, {5, 2}, {6, 3}, {7, 4}, {2, 7}, {4, 5}}}], 125000]] ``` ![image](https://user-images.githubusercontent.com/1479325/59168208-660b8980-8afa-11e9-89db-35b5c25c8722.png) * A branching tree after `5000` steps: ``` HypergraphPlot[ SetReplace[{{1}}, FromAnonymousRules[{{1}} -> {{2}, {2}, {1, 2}}], 5000]] ``` ![image](https://user-images.githubusercontent.com/1479325/59168340-03ff5400-8afb-11e9-8bac-6ead142e8633.png)
- Loading branch information