networks: Fix constructing functions and networks.

This commit is contained in:
Sergiu Ivanov 2020-11-22 21:42:41 +01:00
parent 3a2453c92e
commit 2c68055818

View file

@ -962,6 +962,9 @@
;;; ;;;
;;; This function relies on table->function, so the same caveats ;;; This function relies on table->function, so the same caveats
;;; apply. ;;; apply.
;;;
;;; This function sets the domain mappings of the network to the empty
;;; hash table.
(define (table->network table #:headers [headers #t]) (define (table->network table #:headers [headers #t])
(define n (/ (length (car table)) 2)) (define n (/ (length (car table)) 2))
;; Get the variable names from the table or generate them, if ;; Get the variable names from the table or generate them, if
@ -984,7 +987,7 @@
(table->function (for/list ([in st-ins] [o out]) (table->function (for/list ([in st-ins] [o out])
(list in o))))) (list in o)))))
;; Construct the network. ;; Construct the network.
(make-network-from-functions (map cons var-names funcs))) (network (map cons var-names funcs) (hash)))
(module+ test (module+ test
(test-case "table->network" (test-case "table->network"
@ -993,8 +996,8 @@
(#f #t #f #t) (#f #t #f #t)
(#t #f #t #f) (#t #f #t #f)
(#t #t #t #t)))) (#t #t #t #t))))
(define f1 (hash-ref n 'x1)) (define f1 (hash-ref (network-functions n) 'x1))
(define f2 (hash-ref n 'x2)) (define f2 (hash-ref (network-functions n) 'x2))
(check-false (f1 (make-state '((x1 . #f) (x2 . #f))))) (check-false (f1 (make-state '((x1 . #f) (x2 . #f)))))
(check-false (f1 (make-state '((x1 . #f) (x2 . #t))))) (check-false (f1 (make-state '((x1 . #f) (x2 . #t)))))