This package introduces a set of modeling techniques for exploring behavior in software systems. Models such as state machines and Petri nets can be used to model the behavior of a system, and Markov chains be used to generate events to help in simulation of systems.
fsm
-- UML-style State Machines including entry/exit/do behaviors and transition effects and guards.markov-chain
-- Define the state/transition matrix for a Markov chain and execute the chain resulting in a stream of state events.petri-net
-- Simple Petri net model and execution.reporters
-- common mechanisms for tracking events in model execution.
Define a state machine, a simple one, a start and an end with a transition triggered by a single event.
(make-state-machine
'first-fsm
(list (make-state 'hello 'start)
(make-state 'goodbye 'final))
(list (make-transition 'hello 'goodbye #:on-event 'wake)))
Execute the state machine.
(let* ([exec (make-machine-execution simple-fsm (make-logging-reporter))]
[started (machine-execution-start exec)]
[next1 (handle-event started 'sleep)]
[next2 (handle-event next1 'wake)])
(state-machine-complete? next2))
Define a Markov chain with 3 states.
(define a-chain (make-chain
(==> 'a (--> 'a .5) (--> 'b .25) (--> 'c .25))
(==> 'b (--> 'a .5) (--> 'c .5))
(==> 'c (--> 'a .25) (--> 'b .25) (--> 'c .5))))
Execute the chain with 10 steps and display the history of events.
(define an-exec (make-execution a-chain 'b))
(execute an-exec 10)
(displayln (execution-trace an-exec))
(displayln (mkchain->graph-string a-chain))
Define a simple Petri net, two places, one transition.
(define net (make-petri-net 'first-net
(set 'a 'b)
(set 't)
(set (make-arc 'a 't 1)
(make-arc 't 'b 1))))
Execute the Petri net with an initial configuration that has a single token at place "a".
(define exec (make-net-execution net (hash 'a 1)))
(execute-net exec)