diff --git a/networks.rkt b/networks.rkt index f3a89ef..6bf92d2 100644 --- a/networks.rkt +++ b/networks.rkt @@ -34,8 +34,8 @@ build-signed-interaction-graph/form Modality Mode dynamics% Dynamics% make-syn make-asyn - make-asyn-dynamics make-syn-dynamics pretty-print-state - pretty-print-state/boolean pretty-print-state-graph-with + make-asyn-dynamics make-syn-dynamics build-full-state-graph + pretty-print-state pretty-print-state/boolean pretty-print-state-graph-with pretty-print-state-graph ppsg pretty-print-state-graph/boolean ppsgb ) @@ -701,6 +701,23 @@ (pretty-print-state-graph-with gr pprinter/any)) (define ppsgb pretty-print-state-graph/boolean) + + (: build-full-state-graph (All (a) (-> (Dynamics% a) Graph))) + (define (build-full-state-graph dyn) + (send dyn + build-state-graph + (build-all-states (network-domains (get-field network dyn))))) + + (module+ test + (let* ([n1 : (Network Boolean) + (forms->boolean-network (hash 'x '(not y) + 'y 'x + 'z '(and y z)))] + [dyn-syn (make-syn-dynamics n1)] + [sg ((inst build-full-state-graph Boolean) dyn-syn)]) + (test-case "build-full-state-graph" + (check-equal? (graphviz sg) + "digraph G {\n\tnode0 [label=\"'#hash((x . #t) (y . #t) (z . #t))\"];\n\tnode1 [label=\"'#hash((x . #t) (y . #f) (z . #f))\"];\n\tnode2 [label=\"'#hash((x . #f) (y . #t) (z . #t))\"];\n\tnode3 [label=\"'#hash((x . #t) (y . #f) (z . #t))\"];\n\tnode4 [label=\"'#hash((x . #f) (y . #f) (z . #t))\"];\n\tnode5 [label=\"'#hash((x . #f) (y . #f) (z . #f))\"];\n\tnode6 [label=\"'#hash((x . #f) (y . #t) (z . #f))\"];\n\tnode7 [label=\"'#hash((x . #t) (y . #t) (z . #f))\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t}\n\tsubgraph D {\n\t\tnode0 -> node2 [];\n\t\tnode1 -> node7 [];\n\t\tnode2 -> node4 [];\n\t\tnode3 -> node7 [];\n\t\tnode4 -> node1 [];\n\t\tnode5 -> node1 [];\n\t\tnode6 -> node5 [];\n\t\tnode7 -> node6 [];\n\t}\n}\n")))) ) (require 'typed) diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index d3c25d1..3c7db1c 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -461,6 +461,23 @@ Creates the synchronous dynamics for a given network: an instance of @racket[dynamics%] with @tt{network} as the network and the synchronous mode as @tt{mode}. +See @racket[build-full-state-graph] for an example. + +} + +@defproc[(build-full-state-graph [dyn (Dynamics% a)]) Graph]{ + +Builds the full state graph of the given dynamics. + +@ex[ +(require (only-in "utils.rkt" dotit)) + +(let* ([n (forms->boolean-network (hash 'a '(and a b) + 'b '(not b)))] + [syn-dynamics (make-syn-dynamics n)]) + (dotit ((inst build-full-state-graph Boolean) syn-dynamics))) +] + } @section[#:tag "networks_Pretty_printing"]{Pretty printing}