-
-
Save ashnur/43f57cb21df375998e04a7b5e6a44eac to your computer and use it in GitHub Desktop.
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
(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