diff --git a/networks-tests.rkt b/networks-tests.rkt index 48fe184..042ce32 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -67,6 +67,11 @@ #hash((a . #f) (b . 3)))) (check-equal? (make-boolean-domains '(a b)) #hash((a . (#f #t)) (b . (#f #t)))) + (check-equal? (build-all-boolean-states '(a b)) + '(#hash((a . #f) (b . #f)) + #hash((a . #f) (b . #t)) + #hash((a . #t) (b . #f)) + #hash((a . #t) (b . #t)))) (let* ([n #hash((a . (not b)) (b . a))] [doms (make-boolean-domains '(a b))] @@ -119,7 +124,8 @@ [gr1 (dds-build-n-step-state-graph asyn (set s) 1)] [gr-full (dds-build-state-graph asyn (set s))] [gr-full-pp (ppsg gr-full)] - [gr-full-ppb (ppsgb gr-full)]) + [gr-full-ppb (ppsgb gr-full)] + [gr-complete-bool (build-full-boolean-state-graph asyn)]) (check-equal? (dds-step-one asyn s) (set (st '((a . #f) (b . #f))) (st '((a . #t) (b . #f))))) (check-equal? (dds-step-one-annotated asyn s) @@ -147,4 +153,14 @@ (check-true (has-vertex? gr-full-pp "a:#f b:#f")) (check-true (has-vertex? gr-full-pp "a:#t b:#f")) (check-true (has-vertex? gr-full-ppb "a:0 b:0")) - (check-true (has-vertex? gr-full-ppb "a:1 b:0")))) + (check-true (has-vertex? gr-full-ppb "a:1 b:0")) + + (check-equal? (get-edges gr-complete-bool) + '((#hash((a . #f) (b . #f)) #hash((a . #t) (b . #f))) + (#hash((a . #f) (b . #f)) #hash((a . #f) (b . #f))) + (#hash((a . #t) (b . #f)) #hash((a . #t) (b . #f))) + (#hash((a . #t) (b . #f)) #hash((a . #f) (b . #f))) + (#hash((a . #t) (b . #t)) #hash((a . #f) (b . #t))) + (#hash((a . #t) (b . #t)) #hash((a . #t) (b . #t))) + (#hash((a . #f) (b . #t)) #hash((a . #f) (b . #t))) + (#hash((a . #f) (b . #t)) #hash((a . #t) (b . #t))))))) diff --git a/networks.rkt b/networks.rkt index eadc0c0..31bdff9 100644 --- a/networks.rkt +++ b/networks.rkt @@ -28,6 +28,7 @@ [build-all-states (-> domain-mapping/c (listof state?))] [make-same-domains (-> (listof variable?) generic-set? domain-mapping/c)] [make-boolean-domains (-> (listof variable?) (hash/c variable? (list/c #f #t)))] + [build-all-boolean-states (-> (listof variable?) (listof state?))] [get-interaction-sign (-> network-form? domain-mapping/c variable? variable? (or/c '+ '- '0))] [build-signed-interaction-graph (-> network-form? domain-mapping/c graph?)] [build-boolean-signed-interaction-graph (-> network-form? graph?)] @@ -46,7 +47,8 @@ [pretty-print-boolean-state (-> state? string?)] [pretty-print-state-graph-with (-> graph? (-> state? string?) graph?)] [pretty-print-state-graph (-> graph? graph?)] - [pretty-print-boolean-state-graph (-> graph? graph?)]) + [pretty-print-boolean-state-graph (-> graph? graph?)] + [build-full-boolean-state-graph (-> dynamics? graph?)]) ;; Predicates (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)] @@ -186,6 +188,10 @@ (define (make-boolean-domains vars) (make-same-domains vars '(#f #t))) +;;; Builds all boolean states possible over a given set of variables. +(define (build-all-boolean-states vars) + (build-all-states (make-boolean-domains vars))) + ;;; Given two interacting variables of a network form and the domains ;;; of the variables, returns '+ if the interaction is monotonously ;;; increasing, '- if it is monotonously decreasing, and '0 otherwise. @@ -335,3 +341,9 @@ ;;; A shortcut for pretty-print-boolean-state-graph. (define-syntax-rule (ppsgb gr) (pretty-print-boolean-state-graph gr)) + +;;; Builds the full state graph of a Boolean network. +(define (build-full-boolean-state-graph dyn) + (dds-build-state-graph + dyn + (list->set (build-all-boolean-states (hash-keys (dynamics-network dyn))))))