The Azimuth Project
delete 25 (Rev #15)



This is the expository computing page for the article on Petri nets. These pages should be addressed to a range of computationally oriented readers, which includes coding enthusiasts, programmers, software engineers, computer scientists, and scientists who write code. The aim is first to provide a tutorial, then to discuss programming approaches, and then to present small programs that highlight the concepts.

Here are some guidelines:

  • The readers should be able to run these programs with a minimum of fuss. A scripting language that can represent abstractions is recommended.

  • Try keep the code as succinct and transparent as possible, while still aiming for code that runs.

  • Don’t increase usability at the expense of clarity.

  • Don’t improve performance at the expense of clarity. If there is a significant optimization that deserves to be discussed, consider presenting two versions of the program, starting with the one which is simpler but less efficient.

For an illustration, consider this section of code from the present article, which constructs a Petri net for a simplistic two-transition chemical reaction network, and then simulates it:

# combine: 2 H + 1 O --> 1 H2O
# split: 1 H20 --> 2 H + 1 O

petriNet = PetriNet(
    ["H", "O", "H2O"],    # states
    ["combine", "split"], # transitions
    [("combine",2,"H"), ("combine",1,"O"), ("split",1,"H2O")], # inputs
    [("combine",1,"H2O"), ("split",2,"H"), ("split",1,"O")],   # outputs

initialLabelling = {"H":5, "O":3, "H2O":4}

steps = 20
petriNet.RunSimulation(steps, initialLabelling)

Usability would be improved by passing the arguments from the environment. But that would swell the code with argument-parsing logic, which is routine and tangential to the subject at hand. It would also make the code less readable:

net = PetriNet(

Article contents

The contents have been move to Blog - Petri net programming (part 1).