Type build-full-state-graph.

This commit is contained in:
Sergiu Ivanov 2022-09-22 00:15:35 +02:00
parent fb56dc6589
commit 47602a1785
2 changed files with 36 additions and 2 deletions

View file

@ -34,8 +34,8 @@
build-signed-interaction-graph/form build-signed-interaction-graph/form
Modality Mode dynamics% Dynamics% make-syn make-asyn Modality Mode dynamics% Dynamics% make-syn make-asyn
make-asyn-dynamics make-syn-dynamics pretty-print-state make-asyn-dynamics make-syn-dynamics build-full-state-graph
pretty-print-state/boolean pretty-print-state-graph-with pretty-print-state pretty-print-state/boolean pretty-print-state-graph-with
pretty-print-state-graph ppsg pretty-print-state-graph/boolean ppsgb pretty-print-state-graph ppsg pretty-print-state-graph/boolean ppsgb
) )
@ -701,6 +701,23 @@
(pretty-print-state-graph-with gr pprinter/any)) (pretty-print-state-graph-with gr pprinter/any))
(define ppsgb pretty-print-state-graph/boolean) (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) (require 'typed)

View file

@ -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 @racket[dynamics%] with @tt{network} as the network and the synchronous mode as
@tt{mode}. @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} @section[#:tag "networks_Pretty_printing"]{Pretty printing}