Skip to content

Instantly share code, notes, and snippets.

@hellonico
Last active August 29, 2015 13:59
Show Gist options
  • Save hellonico/10443429 to your computer and use it in GitHub Desktop.
Save hellonico/10443429 to your computer and use it in GitHub Desktop.
Playing with loom
; https://github.com/aysylu/loom
(require-lib '[[aysylu/loom "0.4.2"]])
(use 'loom.graph)
(use 'loom.io)
; define the graph
(def g (graph [1 2] [2 3] {3 [4] 5 [6 7]} 7 8 9))
; view the graph if you have graphviz included
(view g)
; define a graph where the edges are two ways
(def dg (digraph g))
; view it
(view dg)
; see the nodes of the graph g
(nodes g)
; #{7 1 4 6 3 2 9 5 8}
; see all the edges of the graph g
(edges g)
; ([7 5] [1 2] [4 3] [6 5] [3 4] [3 2] [2 1] [2 3] [5 7] [5 6])
; view all the successors of the node "3"
(successors g 3)
; #{4 2}
; apply some clojure magic
(map #(eval %1) (:adj g))
; ([7 #{5}] [6 #{5}] [5 #{7 6}] [4 #{3}] [3 #{4 2}] [2 #{1 3}] [1 #{2}])
; do some path finding
(use 'loom.alg)
; find the path from 2 to 4
(bf-path g 2 4)
; (2 3 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment