Giter Club home page Giter Club logo

behavior's Introduction

Behavioral Models for Racket

GitHub release Travis Status Coverage Status raco pkg install behavior Documentation GitHub stars MIT License

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.

Modules

  • 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.

Examples

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)

Racket Language

behavior's People

Contributors

johnstonskj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.