Skip to content

Instantly share code, notes, and snippets.

@tsurushuu
Created October 2, 2011 13:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsurushuu/1257473 to your computer and use it in GitHub Desktop.
Save tsurushuu/1257473 to your computer and use it in GitHub Desktop.
Graph test
module Main where
import System.Cmd
import Data.Graph.Inductive
import Data.Graph.Inductive.Graphviz
import Data.Graph.Inductive.Example
myGraph :: Gr String ()
myGraph = mkGraph
[(0, "n0"), (1, "n1"), (2, "n2"), (3, "n3"), (4, "n4"), (5, "n5"), (6, "n6")]
[(2, 1, ()), (2, 3, ()), (4, 2, ()), (4, 5, ()), (0, 6, ())]
makeDotPng :: String -> String -> IO ()
makeDotPng name src = do
let dotfile = name ++ ".dot"
pngfile = name ++ ".png"
writeFile dotfile src
system $ unwords ["dot", dotfile, "-Tpng", ">", pngfile]
return ()
main = do
print myGraph
print "------"
putStrLn $ graphviz' myGraph
print "------"
makeDotPng "00" $ graphviz' myGraph
makeDotPng "01" $ graphviz myGraph "test" (0, 0) (0, 0) Landscape
makeDotPng "02" $ graphviz myGraph "test" (0, 0) (0, 0) Portrait
print "------"
let dg name graph = makeDotPng name $ graphviz graph name (0,0) (0,0) Portrait
dg "a" a
dg "dag3" dag3
dg "abb" abb
dg "ab" ab
dg "loop" loop
dg "e" e
dg "c" c
dg "b" b
dg "e3" e3
dg "cyc3" cyc3
dg "g3b" g3b
dg "g3" g3
dg "dag4" dag4
dg "d1" d1
dg "d3" d3
dg "clr479" clr479
dg "clr489" clr489
dg "clr486" clr486
dg "clr508" clr508
dg "clr528" clr528
dg "clr595" clr595
dg "gr1" gr1
dg "kin248" kin248
dg "vor" vor
print "------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment