Last active
August 29, 2015 14:22
-
-
Save jpjacobs/ce6252c4a4a5ec5ecbc5 to your computer and use it in GitHub Desktop.
plotgraph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NB. Make square grid of side y | |
grid =: |:@:(,"2)@(,: |:)@(#"0 i.) | |
plotgraph =: 4 : 0 NB. todo: implement autoplacement of locations not given | |
pd 'reset' | |
pd 'type line;pensize 1;color blue' | |
edges =. ; (i.#x) ;/@,.&({&x)"0 &.> y | |
edges =. <"1 ~.@:(({~"1 /:@{.)"2) > edges NB. normalize: sort points on ascending x, eliminate double edges. | |
edges =. (#~ -.@({.&>-:{:&>)"1) edges NB. eliminate loops. Empties automagically disappear. | |
pd"1 edges | |
pd 'type dot;pensize 4;color red' | |
pd ;/|:x | |
pd'show' | |
#edges | |
) | |
(grid 10) plotgraph <"1 ? 100 3 $ 100 NB. graph with 100 vertices and 3 random neighbors per verrtex | |
(grid 10) plotgraph <@,"0] 1|.i.100 NB. now works correctly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment