From 5e155d0a6170f1317f85601823026a96c9ab4437 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 24 Mar 2023 16:20:23 +0100 Subject: [PATCH] Type random-network. --- networks.rkt | 15 ++++++++++++++- scribblings/networks.scrbl | 9 +++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/networks.rkt b/networks.rkt index c7910dd..93ad496 100644 --- a/networks.rkt +++ b/networks.rkt @@ -50,7 +50,7 @@ table+vars->network table->network table+headers->network - random-function/state random-boolean-function/state + random-function/state random-boolean-function/state random-network ) (define-type (State a) (VariableMapping a)) @@ -1077,6 +1077,19 @@ (define f (random-boolean-function/state '(x1 x2))) (check-equal? (tabulate-state+headers/boolean f '(x1 x2)) '((x1 x2 f1) (#f #f #f) (#f #t #f) (#t #f #t) (#t #t #t))))) + + (: random-network (All (a) (-> (DomainMapping a) (Network a)))) + (define (random-network domains) + (network (for/hash : (VariableMapping (UpdateFunction a)) + ([(x x-dom) (in-hash domains)]) + (values x (random-function/state domains x-dom))) + domains)) + + (module+ test + (test-case "random-network" + (check-equal? + (tabulate-network+headers (random-network (hash 'a '(1 2) 'b '(#f #t)))) + '((a b f-a f-b) (1 #f 1 #f) (1 #t 1 #f) (2 #f 2 #t) (2 #t 2 #f))))) ) (require 'typed) diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index a4019ac..b47edfb 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -916,6 +916,15 @@ variables in @racket[args]. (tabulate-state+headers/boolean (random-boolean-function/state '(a b)) '(a b)) ]} +@defproc[(random-network [domains (DomainMapping a)]) + (Network a)]{ + +Generates a random network from the given domain mapping. + +@ex[ +(tabulate-network+headers (random-network (hash 'a '(1 2) 'b '(#f #t)))) +]} + @section{TBF/TBN and SBF/SBN} This section defines threshold Boolean functions (TBF) and networks (TBN), as