# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Evolve a Petri net configuration by applying all possible transition firings

Contributed by:
Jonathan Gorard

ResourceFunction["PetriNetMultiwayEvolution"][ evolves a Petri net configuration defined by the PetriNetObject expression | |

ResourceFunction["PetriNetMultiwayEvolution"][ evolves a Petri net defined by the list of places | |

ResourceFunction["PetriNetMultiwayEvolution"][ evolves a Petri net defined by the association of places, transitions and arcs | |

ResourceFunction["PetriNetMultiwayEvolution"][…, gives the property " |

A Petri net is an abstract mathematical representation of a distributed system (frequently used for describing chemical reactions, biological processes, concurrent computing, etc.) consisting of a directed bipartite graph whose vertices are classified as either "places" or "transitions". The directed edges connecting places and transitions together are known as "arcs".

Each place can contain a number of "tokens", and a given transition will "fire" if the places connected to it by input arcs all contain at least one token. When a transition fires, it redistributes tokens from places connected to it by input arcs to places connected to it by output arcs.

ResourceFunction["PetriNetMultiwayEvolution"] supports the specification of Petri nets either by PetriNetObject expressions, a collection of three lists (places *p*, transitions *t* and arcs *a*), or by an explicit association of the form <|"Places"→*p*,"Transitions"→*t*,"Arcs"→*a*|>. The list of arcs *a* should be a list of either rules or DirectedEdge objects (each connecting a place to a transition, or vice versa).

PetriNetObject expressions can be constructed using the MakePetriNet resource function.

When specifying Petri nets in terms of lists or associations, the list *init* should be a list of integers specifying how many initial tokens to assign to each place. If a list *init* is not given, ResourceFunction["PetriNetMultiwayEvolution"] will assume that each place contains no tokens.

ResourceFunction["PetriNetMultiwayEvolution"] evolves the specified Petri net by applying all possible transition firings at each step.

When no step count *n* is specified, ResourceFunction["PetriNetMultiwayEvolution"] will evolve the Petri net for a single step and return a list of all possible results. When a step count *n* is specified, ResourceFunction["PetriNetMultiwayEvolution"] will evolve the Petri net for *n* steps and return a nested list containing all possible results at each step.

When no property *prop* is specified, ResourceFunction["PetriNetMultiwayEvolution"] will assume the "PetriNetObjects" property (i.e. it will return a list of the PetriNetObject expressions obtained during the evolution).

In ResourceFunction["PetriNetMultiwayEvolution"][…,"*prop*"], the following properties can be requested:

"PetriNetObjects" | list of PetriNetObject expressions obtained |

"LabeledGraphs" | list of directed graph representations obtained (with token counts represented graphically) |

"LabeledGraphsHighlighted" | list of directed graph representations obtained (with token counts represented graphically), and with transition firings highlighted |

"WeightedGraphs" | list of directed graph representations obtained (with token counts represented as vertex weights) |

"WeightedGraphsHighlighted" | list of directed graph representations obtained (with token counts represented as vertex weights), and with transition firings highlighted |

"Tokens" | list of token numbers associated to each place after each firing |

"TokenFirings" | list of token numbers associated to each place after each firing, with the corresponding transition firing specified |

ResourceFunction["PetriNetMultiwayEvolution"] accepts the same options as Graph.

In a PetriNetObject expression, the following properties are supported:

"AssociationForm" | Petri net represented as an association of places, transitions and arcs |

"Places" | list of places in the Petri net |

"PlaceCount" | number of places in the Petri net |

"Transitions" | list of transitions in the Petri net |

"TransitionCount" | number of transitions in the Petri net |

"Arcs" | list of arcs in the Petri net |

"ArcCount" | number of arcs in the Petri net |

"Tokens" | list of token numbers associated to each place in the Petri net |

"TokenCount" | total number of tokens across all places in the Petri net |

"UnlabeledGraph" | directed graph form of the Petri net without token counts represented graphically |

"LabeledGraph" | directed graph form of the Petri net with token counts represented graphically |

"WeightedGraph" | directed graph form of the Petri net with token counts represented as vertex weights |

By convention, ResourceFunction["PetriNetMultiwayEvolution"] renders places as circles, transitions as squares, arcs as directed edges and tokens as black dots.

Construct a simple Petri net from lists of four places, three transitions and eight arcs, with an initial distribution of six tokens:

In[1]:= |

Out[1]= |

Evaluate one step in the multiway evolution of this Petri net:

In[2]:= |

Out[2]= |

Evaluate the first three steps in the multiway evolution of this Petri net:

In[3]:= |

Out[3]= |

Show the set of labeled graphs obtained after one step, with every possible transition firing highlighted:

In[4]:= |

Out[4]= |

Show the set of labeled graphs obtained after one step, but without any transition firings highlighted:

In[5]:= |

Out[5]= |

Show the sets of labeled graphs after three steps, without any transition firings highlighted:

In[6]:= |

Out[6]= |

Evolve a Petri net (representing a reversible chemical reaction) specified by an association of three places, two transitions and six arcs, with an initial distribution of twelve tokens, for three steps:

In[7]:= |

Out[7]= |

Show the lists of token numbers obtained after each of the three steps:

In[8]:= |

Out[8]= |

Show the lists of token numbers obtained after each of the three steps, along with the corresponding transition firings:

In[9]:= |

Out[9]= |

Show the sets of labeled graphs obtained after two steps, with every possible transition firing highlighted:

In[10]:= |

Out[10]= |

Show the sets of weighted graphs obtained after two steps, with every possible transition firing highlighted:

In[11]:= |

Out[11]= |

Show the sets of weighted graphs obtained after two steps, but without any transition firings highlighted:

In[12]:= |

Out[12]= |

Evolve a more complicated Petri net representing a concurrent communications protocol between two agents (specified as lists of places, transitions, arcs and tokens) for two steps:

In[13]:= |

Out[13]= |

Show the lists of token numbers obtained after each of the two steps, along with the corresponding transition firings:

In[14]:= |

Out[14]= |

If PetriNetMultiwayEvolution is called without an explicit list of token numbers, it is assumed that each place contains no tokens:

In[15]:= |

Out[15]= |

Construct a Petri net representing a simple producer-consumer problem in concurrency theory:

In[16]:= |

Out[16]= |

Show the list of Petri net objects obtained after two steps of multiway evolution:

In[17]:= |

Out[17]= |

Show the list of directed graph representations (with token counts represented graphically) after two steps of multiway evolution:

In[18]:= |

Out[18]= |

Show the list of directed graph representations (with token counts represented graphically, and with transition firings highlighted) after two steps of multiway evolution:

In[19]:= |

Out[19]= |

Show the list of directed graph representations (with token counts represented as vertex weights) after two steps of multiway evolution:

In[20]:= |

Out[20]= |

Show the list of directed graph representations (with token counts represented as vertex weights, and with transition firings highlighted) after two steps of multiway evolution:

In[21]:= |

Out[21]= |

Show the list of token numbers associated to each place after each firing, following two steps of multiway evolution:

In[22]:= |

Out[22]= |

Show the list of token numbers associated to each place after each firing (with the corresponding transition firings specified), following two steps of multiway evolution:

In[23]:= |

Out[23]= |

PetriNetMultiwayEvolution supports the same options as Graph:

In[24]:= |

Out[24]= |

In[25]:= |

Out[25]= |

- Wikipedia–Petri net
- The Wolfram Physics Project
- Stephen Wolfram's A New Kind of Science | Online
- Multiway System–Wolfram MathWorld

- 1.0.0 – 13 December 2021

This work is licensed under a Creative Commons Attribution 4.0 International License