@crinkle/petrinets
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

JavaScript petri-nets

Node version NPM Downloads Minified size License: MIT

Lightweight library for petri-nets.

import { petrinet } from 'petrinets';

const places = [{ key: 'p1' }, { key: 'p2' }, { key: 'p3' }, { key: 'p4' }];
const transitions = [
  {
    key: 't1',
    input: [{ source: 'p1' }],
    output: [{ target: 'p2' }, { target: 'p4' }],
  },
  {
    key: 't2',
    input: [{ source: 'p2' }, { source: 'p4' }],
    output: [{ target: 'p3' }],
  },
  {
    key: 't3',
    input: [{ source: 'p3' }, { source: 'p4' }],
    output: [{ target: 'p1' }, { target: 'p4' }],
  },
  {
    key: 't4',
    input: [{ source: 'p4' }],
    output: [{ target: 'p4' }],
  },
];

const myNet = petrinet(places, transitions);
myNet.add({ place: 'p1', amount: 1 });
myNet.fire('t1');

console.log(myNet.marking); // [{ place: 'p2', amount: 1 }. { place: 'p4', amount: 1 }]

Dependencies (0)

    Dev Dependencies (15)

    Package Sidebar

    Install

    npm i @crinkle/petrinets

    Weekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    5.96 kB

    Total Files

    4

    Last publish

    Collaborators

    • kevtiq