A Javascript library to display and interact with Petri Nets.
To install the latest version (assuming you are using npm as your package manager):
npm install --save petri-js
petri-js
is intended to be used as a CommonJS module,
in a Webpack or Browserify environment.
This lets you then import the module as follows:
import PetriNet from 'petri-js'
All you need to do is create an instance of simulator, a model to simulate and a SVG element it can renders to:
import PetriNet from 'petri-js'
// Create the Petri Net model:
const model = {
places : [ 'p0', 'p1' ],
transitions: [
{
name : 't1',
preconditions : { 'p0': 1 },
postconditions: { 'p1': 2 },
},
{
name : 't0',
preconditions : { 'p1': 1 },
postconditions: { 'p0': 1 },
},
],
m0: { 'p0': 1, 'p1': 0 },
}
// Create an instance of a simulator.
const petrinet = new PetriNet(document.getElementById('petrinet'), model)
By default, petri-js
assumes the given models can be simulated with the semantics of classic
Place/Transition (PT) nets.