networks: Add build-all-boolean-states and build-full-boolean-state-graph.
This commit is contained in:
parent
f88bc0d01b
commit
b0acbadadd
2 changed files with 31 additions and 3 deletions
|
@ -67,6 +67,11 @@
|
||||||
#hash((a . #f) (b . 3))))
|
#hash((a . #f) (b . 3))))
|
||||||
(check-equal? (make-boolean-domains '(a b))
|
(check-equal? (make-boolean-domains '(a b))
|
||||||
#hash((a . (#f #t)) (b . (#f #t))))
|
#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))]
|
(let* ([n #hash((a . (not b)) (b . a))]
|
||||||
[doms (make-boolean-domains '(a b))]
|
[doms (make-boolean-domains '(a b))]
|
||||||
|
@ -119,7 +124,8 @@
|
||||||
[gr1 (dds-build-n-step-state-graph asyn (set s) 1)]
|
[gr1 (dds-build-n-step-state-graph asyn (set s) 1)]
|
||||||
[gr-full (dds-build-state-graph asyn (set s))]
|
[gr-full (dds-build-state-graph asyn (set s))]
|
||||||
[gr-full-pp (ppsg gr-full)]
|
[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)))
|
(check-equal? (dds-step-one asyn s) (set (st '((a . #f) (b . #f)))
|
||||||
(st '((a . #t) (b . #f)))))
|
(st '((a . #t) (b . #f)))))
|
||||||
(check-equal? (dds-step-one-annotated asyn s)
|
(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:#f b:#f"))
|
||||||
(check-true (has-vertex? gr-full-pp "a:#t 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: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)))))))
|
||||||
|
|
14
networks.rkt
14
networks.rkt
|
@ -28,6 +28,7 @@
|
||||||
[build-all-states (-> domain-mapping/c (listof state?))]
|
[build-all-states (-> domain-mapping/c (listof state?))]
|
||||||
[make-same-domains (-> (listof variable?) generic-set? domain-mapping/c)]
|
[make-same-domains (-> (listof variable?) generic-set? domain-mapping/c)]
|
||||||
[make-boolean-domains (-> (listof variable?) (hash/c variable? (list/c #f #t)))]
|
[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))]
|
[get-interaction-sign (-> network-form? domain-mapping/c variable? variable? (or/c '+ '- '0))]
|
||||||
[build-signed-interaction-graph (-> network-form? domain-mapping/c graph?)]
|
[build-signed-interaction-graph (-> network-form? domain-mapping/c graph?)]
|
||||||
[build-boolean-signed-interaction-graph (-> network-form? graph?)]
|
[build-boolean-signed-interaction-graph (-> network-form? graph?)]
|
||||||
|
@ -46,7 +47,8 @@
|
||||||
[pretty-print-boolean-state (-> state? string?)]
|
[pretty-print-boolean-state (-> state? string?)]
|
||||||
[pretty-print-state-graph-with (-> graph? (-> state? string?) graph?)]
|
[pretty-print-state-graph-with (-> graph? (-> state? string?) graph?)]
|
||||||
[pretty-print-state-graph (-> graph? 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
|
;; Predicates
|
||||||
(contract-out [variable? (-> any/c boolean?)]
|
(contract-out [variable? (-> any/c boolean?)]
|
||||||
[state? (-> any/c boolean?)]
|
[state? (-> any/c boolean?)]
|
||||||
|
@ -186,6 +188,10 @@
|
||||||
(define (make-boolean-domains vars)
|
(define (make-boolean-domains vars)
|
||||||
(make-same-domains vars '(#f #t)))
|
(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
|
;;; Given two interacting variables of a network form and the domains
|
||||||
;;; of the variables, returns '+ if the interaction is monotonously
|
;;; of the variables, returns '+ if the interaction is monotonously
|
||||||
;;; increasing, '- if it is monotonously decreasing, and '0 otherwise.
|
;;; increasing, '- if it is monotonously decreasing, and '0 otherwise.
|
||||||
|
@ -335,3 +341,9 @@
|
||||||
|
|
||||||
;;; A shortcut for pretty-print-boolean-state-graph.
|
;;; A shortcut for pretty-print-boolean-state-graph.
|
||||||
(define-syntax-rule (ppsgb gr) (pretty-print-boolean-state-graph gr))
|
(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))))))
|
||||||
|
|
Loading…
Reference in a new issue