<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>SimPN: A Python Library for Modeling and Simulating Timed, Colored Petri Nets</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Remco M. Dijkman</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Eindhoven University of Technology</institution>
          ,
          <addr-line>Eindhoven</addr-line>
          ,
          <country country="NL">The Netherlands</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>SimPN is a Python library for discrete event simulation using timed, colored Petri nets. It provides essential simulation functionality, such as visualization of runs, warm-up time, replications, and reporting, including reporting to event logs that can be used for analysis in process mining tools. In addition, it supports the integration of Python functions, enabling the implementation and performance evaluation of planning and optimization functionality within a simulated business process context. The library also accommodates modeling, simulation, and visualization of higher-level languages like the Business Process Model and Notation. The library is open-source, fully documented, and has been successfully used in a course at Eindhoven University of Technology.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Petri Net</kwd>
        <kwd>Simulation Library</kwd>
        <kwd>Modeling Tool</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        Petri nets [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] are commonly used as the mathematical underpinning for methods and techniques
from the area of Business Process Management. Consequently, having tool support for modeling
and analyzing Petri nets is important to the discipline. Such support facilitates the development
of new methods and techniques that are based on Petri net theory. At the same time it can
be used to teach Petri net theory to students. Given the increasing development of analysis
methods and techniques in Python, having a Python library to support the creation of such
methods is highly beneficial.
      </p>
      <p>SimPN provides such a Python-based library for modeling and simulating timed, colored
Petri nets. It provides advanced functionality for visualizing Petri net simulations, along with
essential simulation features like replications, warm-up time, and reporting. This includes
reporting in the form of event logs to allow for analysis with process mining tools. Additionally,
it supports the development of simulations for higher-level modeling languages, including the
Business Process Model and Notation (BPMN), leveraging the same library for visualization.
The library also supports the integration of Python functions. This is especially useful if such
functions are used to model (in code) planning or optimization functionality, because then such
functionality can be evaluated in the context of the business process that is being simulated.</p>
      <p>The remainder of this paper further introduces the library and is structured as follows.
Section 2 presents other Petri net modeling and simulation tools and in doing so presents the
innovations that the proposed library brings. Section 3 presents the Petri net modeling and
simulation features of the library, and Section 4 presents the maturity of the library.</p>
    </sec>
    <sec id="sec-2">
      <title>2. Related Work</title>
      <p>There exist a large number of Petri net modeling and simulation tools and libraries, in particular
in the area of Business Process Management. The proposed library contributes to this collection
by providing a Python library with full timed, colored Petri net simulation capabilities as well
as native integration with Python functionality.</p>
      <p>
        A recent overview of Petri net modeling and simulation tools and libraries is provided by
Kumbhar and Chavan [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. This overview covers Petri net modeling and simulation tools,
among which the long-running and well-maintained tools WoPeD [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] and CPN Tools [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. The
overview also discusses Petri net libraries, including the Matlab-based library SimHPN [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] and
the Python-based library SNAKES [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. SNAKES is the closest to the proposed library. The two
main diferences between SimPN and SNAKES are:
• SimPN has a more comprehensive integration with Python by supporting Python
functions, while SNAKES only supports Python expressions. This has important implications
for the ability to use other functionality, in particular functionality for business process
optimization, as will be discussed in Section 3.
• SimPN has stronger business process simulation support. In particular it provides direct
support for timed Petri nets, including their visual simulation, while in SNAKES support
for timed Petri nets has to be implemented separately. Also, SimPN provides additional
functionality for business process simulation, including support for simulating and
visualizing higher level languages, such as BPMN, and support for replications, warm-up
time, and direct export to process mining tools.
      </p>
      <p>These diferences are due to fundamental design choices to make SimPN and SNAKES suitable
for diferent use cases. In particular, SimPN primarily aims at supporting business process
simulation and optimization, while SNAKES primarily aims at supporting formal analysis of
Petri nets. This, for example, makes it logical for SimPN to support Python functions and
SNAKES to just support Python expressions instead. It also makes it logical for SimPN to have
more comprehensive functionality for simulation.</p>
    </sec>
    <sec id="sec-3">
      <title>3. Features</title>
      <p>The SimPN library is primarily designed for business process simulation. While it can be used
as a general simulation tool, it has an emphasis on simulating planning and optimization of
business processes, such as simulating a policy for allocating employees to tasks in a business
process. This facilitates studies that aim to develop and evaluate business process planning and
optimization functionality. To this end, the SimPN library provides the following features:
• Simulation functionality, including support for vizualizing simulation runs, replications,
warm-up time, reporting, and export to process mining tools.
• Support for Python functions, including support for planning and optimization through
mathematical programming, heuristics, and computational intelligence.
• Higher level language support, including support for visualizing higher-level language
constructs.</p>
      <sec id="sec-3-1">
        <title>3.1. Simulation Functionality</title>
        <p>The SimPN library is based on timed, colored Petri nets. As such, it has places, transitions,
and tokens, where tokens can have colors and delays. The code below illustrates how a simple
simulation can be set up for a shop with a cashier and two waiting customers. The cashier
serves the customers with a delay of 0.75 time units.</p>
        <p>shop = SimProblem()
resources = shop.add_var("resources")
customers = shop.add_var("customers")
resources.put("cashier")
customers.put("c1")
customers.put("c2")
def process(customer, resource):</p>
        <p>return [SimToken(resource, delay=0.75)]
shop.add_event([customers, resources], [resources], process)
shop.simulate(10, SimpleReporter())</p>
        <p>The code shows how two places are created using the add_var method, one for the cashier
resources and one for the customers. Subsequently, one cashier is added to the resources place
and two customers are added to the customers place.</p>
        <p>Transitions can be created using the add_event method. This method takes the list of
incoming places and the list of outgoing places of the transition as parameters. In addition, a
function must be defined that describes how the transition generates outgoing tokens based on
incoming tokens. In the example, the process function takes (the value of) a token from the
customers place, which it calls customer and (the value of) a token from the resources place,
which it calls resource. The function must return a list of tokens that are put on the outgoing
places. In this case, the function returns a single token that has the same value as the incoming
resource token. The token is made available with a delay of 0.75 time units, which simulates
that it takes a cashier 0.75 time units to process a customer.</p>
        <p>The simulation is started using the simulate method. This method takes the number of
time units to simulate and a reporter as parameters. The reporter is an object that can be used
to report what happens in the simulation. In the example, the SimpleReporter is used, which
simply prints the firing of each transition to the standard output.</p>
        <p>The library also has more advanced reporting functionality. In particular it provides
functionality for adding warm-up times and replications to obtain valid conclusions from the simulation.</p>
        <p>It also provides functionality for reporting to an event log that can subsequently be used for
process mining and it provides functionality for visualizing the Petri net and step-wise animation
of simulation as illustrated in Figure 1.</p>
      </sec>
      <sec id="sec-3-2">
        <title>3.2. Support for Python Functions</title>
        <p>The Python code example above illustrates that the library has support for invoking Python
functions. Any self-defined Python function can be used in the simulation. These functions can
take token values as input and produce token values as outputs. Lambda functions can also be
used to simplify the code, in case only simple passing of token values is required.</p>
        <p>The benefits of using Python functions are mainly sought when evaluating business
process optimization functionality through simulation. The optimization functionality can be
implemented as a Python function. Subsequently, the efect of the optimization function on
a particular business process can be evaluated by simulating that business process as a Petri
net in combination with the optimization functionality. As an example consider the simulation
of a treatment process in a hospital, where patients follow a path through through diferent
activities and wards in the hospital that depends on their diagnosis. A planning function can be
developed in Python that plans patients in timeslots upon arrival. The reception of the patient
in the timeslot and subsequent progress of the patient through the hospital, depending on the
availability of resources, can then be simulated as a Petri net.</p>
        <p>
          In previous work we have specifically studied the integration of Petri nets with planning
functions based on Deep Reinforcement Learning [
          <xref ref-type="bibr" rid="ref6">6</xref>
          ].
        </p>
      </sec>
      <sec id="sec-3-3">
        <title>3.3. Higher-level Language Support</title>
        <p>The SimPN library has support for higher-level languages of which the semantics is defined in
terms of Petri nets. Some concepts from the Business Process Model and Notation (BPMN) have
been implemented in the library already. Using the library, it is possible to define a higher-level
language construct, like a BPMN task or choice construct in terms of Petri net places and
transitions. This is done by defining a class for this construct that inherits from the Prototype
class and generates the desired composition of places and transitions when it is instantiated.
That class can then be instantiated each time the specific higher-level language construct is
required. For example, the following code creates a BPMN start event with a label ‘customer
arrived’ and an exponential inter-arrival time with a mean of 1.</p>
        <p>A prototype can easily be enriched with visualization functionality, which enables its
simulation to be visualized according to its own notation.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Tool Maturity</title>
      <p>The SimPN library is available open source1 and can be installed using the Python package
manager pip by the name simpn. The library is fully documented2 and comes with a large number
of examples that demonstrate its functionality. The documentation also contains teaching
materials that explain the theory and examples in detail and a short video3 demonstrating the
main functionality. These teaching materials will be further developed as the library develops.
The SimPN library has successfully been used in the 2024 iteration of the course ‘Business
Process Simulation’ at Eindhoven University of Technology with 39 students.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>K.</given-names>
            <surname>Jensen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L. M.</given-names>
            <surname>Kristensen</surname>
          </string-name>
          , L. Wells,
          <article-title>Coloured petri nets and cpn tools for modelling and validation of concurrent systems, Intl</article-title>
          .
          <source>Journal on Software Tools for Technology Transfer</source>
          <volume>9</volume>
          (
          <year>2007</year>
          )
          <fpage>213</fpage>
          -
          <lpage>254</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>V. B.</given-names>
            <surname>Kumbhar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. S.</given-names>
            <surname>Chavan</surname>
          </string-name>
          ,
          <article-title>A review of petri net tools and recommendations</article-title>
          ,
          <source>in: Proc. of the Intl. Conf. on Applications of Machine Intelligence and Data Analytics (ICAMIDA)</source>
          , Atlantis Press,
          <year>2023</year>
          , pp.
          <fpage>710</fpage>
          -
          <lpage>721</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>T.</given-names>
            <surname>Freytag</surname>
          </string-name>
          ,
          <article-title>Woped-workflow petri net designer</article-title>
          , University of Cooperative Education (
          <year>2005</year>
          )
          <fpage>279</fpage>
          -
          <lpage>282</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>J.</given-names>
            <surname>Júlvez</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Mahulea</surname>
          </string-name>
          ,
          <string-name>
            <surname>C.</surname>
          </string-name>
          -R. Vázquez,
          <article-title>SimHPN: A MATLAB toolbox for simulation, analysis and design with hybrid petri nets</article-title>
          ,
          <source>Nonlinear Analysis: Hybrid Systems</source>
          <volume>6</volume>
          (
          <year>2012</year>
          )
          <fpage>806</fpage>
          -
          <lpage>817</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>F.</given-names>
            <surname>Pommereau</surname>
          </string-name>
          ,
          <article-title>SNAKES: A flexible high-level petri nets library</article-title>
          , in: R.
          <string-name>
            <surname>Devillers</surname>
            ,
            <given-names>A</given-names>
          </string-name>
          . Valmari (Eds.),
          <source>Proc. of the Intl. Conf. on Application and Theory of Petri Nets and Concurrency (PETRI NETS)</source>
          , Springer,
          <year>2015</year>
          , pp.
          <fpage>254</fpage>
          -
          <lpage>265</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>R.</given-names>
            <surname>Lo</surname>
          </string-name>
          <string-name>
            <surname>Bianco</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Dijkman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Nuijten</surname>
          </string-name>
          ,
          <string-name>
            <surname>W. van Jaarsveld</surname>
          </string-name>
          ,
          <article-title>Action-evolution petri nets: A framework for modeling and solving dynamic task assignment problems</article-title>
          , in: Prof. of Intl.
          <source>Conf. on Business Process Management (BPM)</source>
          , Springer,
          <year>2023</year>
          , pp.
          <fpage>216</fpage>
          -
          <lpage>231</lpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>