Last active
September 22, 2016 06:05
-
-
Save TikhonJelvis/11272905 to your computer and use it in GitHub Desktop.
Generating graphs for my Quora answer
This file contains 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
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
import qualified Data.Graph.Inductive as Graph | |
import Data.Graph.Inductive (Gr, match, matchAny) | |
import Data.String.Interpolation (str) | |
complex :: Gr () () | |
complex = Graph.mkGraph nodes edges | |
where nodes = [(x, ()) | x <- [1..10]] | |
edges = [(x, y, ()) | x <- [1..10], y <- [1..10], x < y] | |
modular :: Gr () () | |
modular = Graph.mkGraph nodes edges | |
where nodes = [(x, ()) | x <- [1..10]] | |
edges = [(x, y, ()) | x <- [1..10], y <- [1..10], x < y, same x y] | |
same a b = (a < 6) == (b < 6) | |
unlabeled graph = [str| | |
digraph fgl { | |
margin = "0" | |
page = "6" | |
size = "6" | |
ratio = "fill" | |
#node in Graph.nodes graph:$:node$| | |
# | |
#(a, b, l) in Graph.labEdges graph:$:a$ -> $:b$ [arrowhead = none]| | |
# | |
} | |
|] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment