networks: Add make-same-domain-mapping and make-boolean-domain-mapping.

This commit is contained in:
Sergiu Ivanov 2020-02-23 00:13:36 +01:00
parent cf676028d3
commit 183160da6f
2 changed files with 12 additions and 0 deletions

View File

@ -72,6 +72,8 @@
((a . #t) (b . #f))
((a . #f) (b . #t))
((a . #f) (b . #f))))
(check-equal? (hash->list (make-boolean-domain-mapping '(a b)))
'((a . (#f #t)) (b . (#f #t))))
(let ([n #hash((a . (not b)) (b . a))]
[doms (make-immutable-hash (for/list ([var '(a b)]) (cons var '(#f #t))))])

View File

@ -25,6 +25,8 @@
[build-interaction-graph (-> network-form? graph?)]
[build-all-states (-> (listof (cons/c variable? generic-set?)) (listof state?))]
[build-all-states-same-domain (-> (listof variable?) generic-set? (listof state?))]
[make-same-domain-mapping (-> (listof variable?) generic-set? (hash/c variable? generic-set?))]
[make-boolean-domain-mapping (-> (listof variable?) (hash/c variable? (list/c #f #t)))]
[get-interaction-sign (-> network-form? (hash/c variable? generic-set?) variable? variable? (or/c '+ '- '0))])
;; Predicates
(contract-out [variable? (-> any/c boolean?)]
@ -159,6 +161,14 @@
(define (build-all-states-same-domain vars domain)
(build-all-states (for/list ([v vars]) (cons v domain))))
;;; Makes a hash set mapping all variables to a single domain.
(define (make-same-domain-mapping vars domain)
(make-immutable-hash (for/list ([var vars]) (cons var domain))))
;;; Makes a hash set mapping all variables to the Boolean domain.
(define (make-boolean-domain-mapping vars)
(make-same-domain-mapping vars '(#f #t)))
;;; 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.