Skip to content

Instantly share code, notes, and snippets.

@ashnur
Created December 15, 2016 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashnur/43f57cb21df375998e04a7b5e6a44eac to your computer and use it in GitHub Desktop.
Save ashnur/43f57cb21df375998e04a7b5e6a44eac to your computer and use it in GitHub Desktop.
(ns combo-network.graph)
;; A model for social networks
;; Riitta Toivonen!, Jukka-Pekka Onnela, Jari Sarama¨ki,
;; Jo¨rkki Hyvo¨nen, Kimmo Kaski
;; Laboratory of Computational Engineering, Helsinki University of Technology
(def initial-contact-ratio 0.95)
(def secondary-contact-ratio 0.05)
(defn seed
[init-nodes-count]
(range 0 init-nodes-count))
;; initial-contacts (select-random seed-nodes)
;; secondary-contact (select)
(defn grow-step [graph]
(let [nodes (:nodes graph)
edges (:edges graph)]
{:nodes (conj nodes (+ (apply max nodes) 1))
:edges edges}))
(defn graph-size
[graph]
(count (:nodes graph)))
(defn grow [final-size graph]
(if (> final-size (graph-size graph))
(fn [] (grow final-size (grow-step graph)))
graph))
(defn grow-graph-to-size [graph final-size]
(trampoline grow final-size graph))
(defn graph [init-nodes-count final-size]
(let [seed-nodes (seed init-nodes-count)]
(grow-graph-to-size {:nodes seed-nodes :edges []} final-size)))
(js/console.log (graph 1 5)) ;; {:nodes (4 3 2 1 0) , :edges []}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment