networks: Add build-all-states-same-domain.
This commit is contained in:
parent
da3f25922a
commit
25a88c820a
2 changed files with 13 additions and 2 deletions
|
@ -66,4 +66,9 @@
|
||||||
((a . #t) (b . 3))
|
((a . #t) (b . 3))
|
||||||
((a . #f) (b . 1))
|
((a . #f) (b . 1))
|
||||||
((a . #f) (b . 2))
|
((a . #f) (b . 2))
|
||||||
((a . #f) (b . 3)))))
|
((a . #f) (b . 3))))
|
||||||
|
(check-equal? (map hash->list (build-all-states-same-domain '(a b) '(#t #f)))
|
||||||
|
'(((a . #t) (b . #t))
|
||||||
|
((a . #t) (b . #f))
|
||||||
|
((a . #f) (b . #t))
|
||||||
|
((a . #f) (b . #f)))))
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
network?)]
|
network?)]
|
||||||
[list-interactions (-> network-form? variable? (listof variable?))]
|
[list-interactions (-> network-form? variable? (listof variable?))]
|
||||||
[build-interaction-graph (-> network-form? graph?)]
|
[build-interaction-graph (-> network-form? graph?)]
|
||||||
[build-all-states (-> (listof (cons/c variable? generic-set?)) (listof state?))])
|
[build-all-states (-> (listof (cons/c variable? generic-set?)) (listof state?))]
|
||||||
|
[build-all-states-same-domain (-> (listof variable?) generic-set? (listof state?))])
|
||||||
;; Predicates
|
;; Predicates
|
||||||
(contract-out [variable? (-> any/c boolean?)]
|
(contract-out [variable? (-> any/c boolean?)]
|
||||||
[state? (-> any/c boolean?)]
|
[state? (-> any/c boolean?)]
|
||||||
|
@ -151,3 +152,8 @@
|
||||||
(for/list ([s (apply cartesian-product domains)])
|
(for/list ([s (apply cartesian-product domains)])
|
||||||
(make-state (for/list ([var vars] [val s])
|
(make-state (for/list ([var vars] [val s])
|
||||||
(cons var val))))))
|
(cons var val))))))
|
||||||
|
|
||||||
|
;;; Given a list of variables and a domain common to all of them,
|
||||||
|
;;; builds the list of all possible states.
|
||||||
|
(define (build-all-states-same-domain vars domain)
|
||||||
|
(build-all-states (for/list ([v vars]) (cons v domain))))
|
||||||
|
|
Loading…
Reference in a new issue