From fe0fbc3ed0300efa8a99fb428de9c8bc1c0408e0 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Thu, 19 Nov 2020 00:22:01 +0100 Subject: [PATCH] networks: Add build-signed-interaction-graph/form. --- networks.rkt | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/networks.rkt b/networks.rkt index 52ce1d0..f7c8d68 100644 --- a/networks.rkt +++ b/networks.rkt @@ -36,6 +36,7 @@ [build-interaction-graph (-> network? domain-mapping/c graph?)] [build-interaction-graph/form (-> network-form? domain-mapping/c graph?)] [build-signed-interaction-graph (-> network? domain-mapping/c graph?)] + [build-signed-interaction-graph/form (-> network-form? domain-mapping/c graph?)] [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)))] @@ -556,24 +557,29 @@ #:unless (eq? sign #f)) (list sign x y)))) +;;; Like build-signed-interaction-graph, but takes a network form and +;;; converts it a to a network. +(define (build-signed-interaction-graph/form form doms) + (build-signed-interaction-graph (network-form->network form) doms)) + (module+ test (test-case "build-signed-interaction-graph" - (define n-bool (network-form->network - (hash 'x '(not y) - 'y 'x - 'z '(and y z) - 't '(or (and (not x) y) - (and x (not y)))))) + (define n-bool + (hash 'x '(not y) + 'y 'x + 'z '(and y z) + 't '(or (and (not x) y) + (and x (not y))))) (define bool-doms (make-boolean-domains '(x y z t))) - (check-equal? (graphviz (build-signed-interaction-graph n-bool bool-doms)) + (check-equal? (graphviz (build-signed-interaction-graph/form n-bool bool-doms)) "digraph G {\n\tnode0 [label=\"y\"];\n\tnode1 [label=\"z\"];\n\tnode2 [label=\"x\"];\n\tnode3 [label=\"t\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode1 -> node1 [label=\"1\"];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node2 [label=\"-1\"];\n\t\tnode0 -> node3 [label=\"0\"];\n\t\tnode0 -> node1 [label=\"1\"];\n\t\tnode2 -> node3 [label=\"0\"];\n\t\tnode2 -> node0 [label=\"1\"];\n\t}\n}\n") - (define n-multi (network-form->network - (hash 'x '(min (+ y 1) 2) - 'y '(max (- y 1) 0) - 'z '(- 2 y) - 't '(abs (- y 1))))) + (define n-multi + (hash 'x '(min (+ y 1) 2) + 'y '(max (- y 1) 0) + 'z '(- 2 y) + 't '(abs (- y 1)))) (define 123-doms (make-same-domains '(x y z t) '(0 1 2))) - (check-equal? (graphviz (build-signed-interaction-graph n-multi 123-doms)) + (check-equal? (graphviz (build-signed-interaction-graph/form n-multi 123-doms)) "digraph G {\n\tnode0 [label=\"y\"];\n\tnode1 [label=\"z\"];\n\tnode2 [label=\"x\"];\n\tnode3 [label=\"t\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node0 [label=\"1\"];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node2 [label=\"1\"];\n\t\tnode0 -> node3 [label=\"0\"];\n\t\tnode0 -> node1 [label=\"-1\"];\n\t}\n}\n"))) ;;; ====================