## Petri Net Agent

The Petri Net is a powerful model for state machine representation and simulations. The ABLE Petri Net agent utilizes the ABLE Rule Language (ARL) to specify variables, one-time initialization logic, initial markings and transition rule logic.

PetriNets are composed of nodes and links. The nodes can represent states (called Places) and actions (called Transitions). Places and Transitions are connected by arcs. Tokens, which can be any Java objects, can flow between nodes via the arcs.

The standard token is a Boolean. However, any Java object can be defined as the Token type and used to flow between nodes in the Petri Net. For example, you could define a Person class and declare Person token; in the variable section of the Petri Net. Place and Transition nodes could then refer to data members or invoke methods on the Person object indirectly through the token variable. An initial marking in a Place node could be tokens.add(new Person("Mary")); ... which would add a single Person token to that Place when the Petri Net is initialized. A Transition node could then access and display the Persons name println("The person's name is " + token.getName());

### Implementation

The Petri Net model implemented in ABLE can be used to model simple Place/Transition networks as well as more complex high-level Petri networks.

You can define global variables and import Java classes.

You can define a one-time initialization logic as an ARL init() ruleblock.

You can define the initial marking of the Petri Net by specifying the initialization expressions in each Place node.

You can define the number of tokens that will flow over an arc by specifying the multiplicity of the arc.

Arcs can be enabling (default) or inhibitory. Inhibitory arcs can be used to disable Transitions when tokens already exist in an input Place.

### Architecture

A PetriNet is comprised of a collection of Places (states) and Transitions (action) nodes connected by directed arcs. Tokens flow through the network based on the connections and probabilities associated with the Transitions. When a transition is selected to fire, the transition rule logic is performed.

### Simulations

To run a Petri Net simulation, you must first init the PetriNet. This step dynamically creates an ARL ruleset by concatenating the variables, initialization sections from the PetriNet customizer, combined with all of the defined Place and Transition rules. This ruleset is then parsed. If the resulting ruleset parses cleanly, then the Petri Net is ready to run a simulation.

Initialization of the Petri Net results in invocation of the init() ruleblock (if defined) and any initial marking expression Place rules. Any Place which has initial expressions defined has a corresponding rule added to the process() ruleblock.

For each process step of the Petri Net, all of the enabled Transition nodes are collected and one of them is randomly selected to fire. Firing means that the associated Transition rule logic is executed, subject to evaluation of the guard clause (if defined).

### References

For more information refer to the PetriNetAgent details or PetriNetTutorial.