Skip to content

senorflor/hypergraphs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hypergraphs

Minimalist hypergraphs:

(require '[clojure.math.combinatorics :as c] '[hypergraphs.core :as hg] '[hypergraphs.utils :as hg-utils])

;; This library uses sets extensively:
(def some-nodes #{1 2 3 4})

;; Here's a not-very-busy hypergraph. Each hyperedge is a set of 1 or
;; more nodes which are considered adjacent.
(def sparse-hg [some-nodes #{ #{1 2} #{2 3 4} }])

;; Here's a complete hypergraph; the set of hypernodes is the Powerset
;; of the nodeset (excluding the empty set)
(def complete-hg [some-nodes
                  (into #{} (->> (c/subsets some-nodes)
                                 (filter #(< 1 (count %)))
                                 (map set))])

(hg/nodes complete-hg)
;=> #{1 4 3 2}

(hg/edges complete-hg)
;=> #{#{4 3} #{1 4 3 2} #{4 3 2} #{1 4} #{4 2} #{1 3 2} #{1 3} #{1 2} #{1 4 3} #{3 2} #{1 4 2}}

(hg/neighbors complete-hg 1)
;=> #{1 4 3 2}

(hg/nodes sparse-hg)
;=> #{1 4 3 2}

(hg/edges sparse-hg)
;=> #{#{4 3} #{1 2}}

(hg/neighbors sparse-hg 1)
;=> #{1 2}

;; Let's find paths as a first exercise:

(hg/naive-paths sparse-hg 1 4)
;=> ((#{1 2} #{4 3 2}))
;; Yay!

(hg-utils/naive-paths complete-hg 1 4)
;=> ...
;; Go get some coffee. Time to figure out what good pathfinding algos
;; for hypergraphs look like...

Usage

Not yet.

TODO

Just about everything :)

License

Copyright © 2014 Patrick Flor

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Minimalist hypergraphs in Clojure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published