<!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>A Concurrent Simulator for Petri Nets Based on the Paradigm of Actors of Hewitt</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Luca Bernardinello</string-name>
          <email>luca.bernardinello@unimib.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Francesco Adalberto Bianchi</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Dipartimento di Informatica sistemistica e comunicazione Universita` degli studi di Milano-Bicocca Viale Sarca 336 U14</institution>
          ,
          <addr-line>Milano</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <fpage>217</fpage>
      <lpage>221</lpage>
      <abstract>
        <p>In this paper we propose a concurrent simulator for Petri nets based on the model of Actors of Hewitt. The classes of Petri nets that are supported for the simulation are Place-Transition Nets and Elementary Nets. The simulator is written in Scala, a programming language with a library implementing the Actors model. This paper deals with the design and implementation of a concurrent simulator for Petri nets based on Hewitt's Actor model. Different versions of the simulator have been built: two versions for Marked Graphs, one version for Free Choice Nets and finally the simulator for general Petri Nets. All the versions support both the firing rule of Elementary Nets and the firing rule of Place-transitions Nets. In this paper we will only describe the case of Place-Transition nets. The simulator is based on the algorithm described by Dirk Taubner in [4], and is written in Scala, an object-oriented language built over Java. We chose to use the Actor model for the implementation of the concurrent simulator to make a comparison between the level of concurrency offered by this paradigm and that offered by Java threads. The algorithm is explained in Section 2. The paradigm of Actors was introduced in 1973 by Carl Hewitt in [1]. An Actor is an independent entity which, concurrently to other Actors, can receive messages from other Actors, change its internal state, send new messages and create new Actors. Each Actor is identified by a mailing address; an Actor needs to know the mailing address of the Actors with which it wants to communicate. Each message contains the address of the sender. Section 3 describes how Scala implements the Actor model. Several experiments have been made whose results are discussed in Section 5.</p>
      </abstract>
      <kwd-group>
        <kwd>Petri Nets</kwd>
        <kwd>Simulation</kwd>
        <kwd>Actor Model</kwd>
        <kwd>Scala programming language</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>ties in the program. The strategy applied in our simulator provides a process
for each place and for each transition of the net. Each transition communicates
with its input places to check the firing condition. If enabled, the transition
asks its neighbouring places either to decrement or to increment their number
of tokens. The processes associated to places manage their number of tokens
and the requests made by transitions. The communication between place and
transition must follow a specific protocol because of conflicts. In a conflict
situation a place must manage requests from different transitions; for this reason,
a token reservation strategy is needed. Conflicts can also generate deadlocks in
a simulator; if two transitions have made some of their reservations but they
need a further reservation that they can’t make because of the reservations of
the other, a deadlock situation is generated. To avoid it, a transition must be
able to cancel previous reservations.</p>
      <p>The strategies just described are applied in the Polling of places in a fixed
order algorithm (also called PTO). Each transition sequentially polls the
processes corresponding to its input places in a fixed order and waits for the answer.
At the first refusal, the transition cancels reservations made earlier and restarts
polling from the first place. If the transition receives affirmative answers from
all the places, it informs each place to increment or decrement its number of
tokens. On the other hand, a place manages the reservation requests: if it can
satisfy a request, it reserves the necessary token to the transition and it sends
an affirmative message to the transition; if it can not satisfy a request, it sends
a negative message to the transition.
3</p>
    </sec>
    <sec id="sec-2">
      <title>Scala and Actor Model</title>
      <p>Several programming languages realize concurrency through the paradigm of
Actors. Scala has been designed in 2001 by Martin Odersky and it was released
for the first time in 2004 on Java platform. Scala runs on the Java Virtual
Machine, providing a high compatibility with existing Java code. Scala is a pure
object-oriented language, supporting also functional programming. A library is
provided implementing the Actor model. Each Actor in Scala has a mailbox in
which it stores the received messages. The react() and receive() methods pick
a message from the mailbox and check if it matches one of the patterns specified
in the Actor. Scala Actors using react() are lightweight in comparison to Java
threads. In particular, if an Actor implements the receive() method, Scala
makes a one to one mapping with Java Virtual Machine threads; therefore each
Scala Actor is implemented as a Java thread. For this reason, a program
implemented through Scala Actors using receive() method has similar performances
of a program based on Java threads. An Actor using the react() method
instead, when it is started its behavior is captured in a closure and its stack is
discarded. At this point, the Actor is suspended and the associated thread is free
to execute other tasks. When the Actor receives a message, the corresponding
closure is executed by a thread. Using this strategy, a thread is able to execute
more than one Actor at the same time.</p>
    </sec>
    <sec id="sec-3">
      <title>Implementation of the Simulator</title>
      <p>The simulator is composed first of all by the Net, Place and Transition classes
that define the structure of the net. When the user asks for the simulation of the
specified Petri net, the class Net provides for the creation of the Actors needed.
Two kinds of Actors are needed: one to represent places and one to represent
transitions. For this reason, the classes PlaceActor and TransitionActor have
been implemented. Each implements an Actor whose behavior reflects the task
described in Taubner’s algorithm.</p>
      <p>In the first version for Marked Graphs, in which conflicts are not allowed,
the reservations and cancellation strategies are not needed. In a second version
of the simulator of Marked Graphs each place is seen as just a communication
channel between two transitions, and not as an Actor.</p>
      <p>Another version simulates Free Choice Nets, in which if two or more
transitions are in conflict, then they have a single input place (that is the same for all
the transitions in conflict). In this case the reservation strategy is needed, but
there is no need for cancelling reservations.</p>
      <p>Finally, the simulator for general Petri nets has been implemented. This
version reflects Taubner’s algorithm, implementing both reservation and
cancellation strategies.
5</p>
    </sec>
    <sec id="sec-4">
      <title>Experimental Results</title>
      <p>A series of experiments has been made in order to compare the degree of
concurrency offered by the simulator based on Actors and the simulator based on
Java threads: by degree of concurrency we mean the number of processes that
the simulator can start during a simulation. We recall that when we speak about
simulator based on Java threads we mean a simulator implemented through Scala
Actors using receive() method. Moreover we have studied the ratio between
the number of transition firings and the number of cancellations of reservations.</p>
      <p>For the first experiments we used a net with a regular structure, whose size
is simply parameterizable. In particular, we considered the following net, where
the basic module can be replicated:</p>
      <p>The experiments have been conducted on two different computers: the first
has a dual-core processor with 2 GB of memory, the second has a quad-core
processor with 4 GB of memory. The results of experiments made on first computer
are the following:</p>
      <sec id="sec-4-1">
        <title>Actors Threads</title>
      </sec>
      <sec id="sec-4-2">
        <title>Processes 18 000 200</title>
      </sec>
      <sec id="sec-4-3">
        <title>Core 1 30% 100%</title>
      </sec>
      <sec id="sec-4-4">
        <title>Core 2 30% 100%</title>
      </sec>
      <sec id="sec-4-5">
        <title>Memory used</title>
        <p>From the table it can be seen that the number of processes started in the case
of Actors is much greater. In the case of Actors the number of started processes is
limited by memory, which is totally occupied; in case of threads, the limit comes
from the processors usage. The experiments made on the second configuration
have yielded results consistent with those just described.</p>
        <p>The aim of the second type of experiments was to record some significant
parameters to test the efficiency of the implementation. The net used in this case
models the dining philosophers (see Fig 1). Specifically, we consider a variant of
the model in which some philosophers take first their left fork, while the others
take first the right fork.</p>
        <p>The first kind of data we wanted to record was the number of transitions
that fire and the number of negative answers that the transitions receive.</p>
        <p>An interesting property shown by data concerns the ratio between the number
of transitions that fire and the number of refusal received by transitions (see
table below); this ratio is constant and independent from time and number of
transitions. Its value is close to 0.1, which means that each transition, to obtain
the permission to fire, receives on average ten refusals. This result is justified
by the fact that each transition continually tries to fire, this suggests to explore
changes to the algorithm in order to reduce the number of refusals.</p>
      </sec>
      <sec id="sec-4-6">
        <title>Philosophers</title>
      </sec>
      <sec id="sec-4-7">
        <title>Transitions</title>
      </sec>
      <sec id="sec-4-8">
        <title>Negative answers Time (sec) 60</title>
        <p>600
Time
(sec)
0.9885
1.0408
1.2419
The second kind of data that we have recorded is the number of transitions that
fire and the number of messages sent by transitions to cancel a reservation (see
the table below). We recall that the number of negative answers (recorded in the
first experiments) and the number of cancellations of reservations are not the
same. In fact if a transition receives a negative answer from the first place, it does
not need to cancel any reservation. In this case the ratio between the number
of transitions and the number of cancellations of reservations is approximately
1, which means that each transition sends on average a single message to cancel
reservations before firing.</p>
      </sec>
      <sec id="sec-4-9">
        <title>Philosophers</title>
      </sec>
      <sec id="sec-4-10">
        <title>Transitions</title>
      </sec>
      <sec id="sec-4-11">
        <title>Delete reservation</title>
        <p>6</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Conclusion</title>
      <p>Taubner’s algorithm allowed us to implement a concurrent simulator for Petri
nets. Furthermore Scala has proved to be a very simple and elegant
programming language, which, thanks to Actors model, offers a level of concurrency
significantly higher than threads Java. Planned future developments are the
implementation of a GUI for the simulator and other tools for analyzing the results
of simulations. We will also explore alternative algorithms which exploit
structural properties of the net to be simulated. In particular, we will consider nets
that can be decomposed in several State Machine. An Actor will be associated
to each sequential component.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>Carl</given-names>
            <surname>Hewitt</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Peter</given-names>
            <surname>Bishop</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Richard</given-names>
            <surname>Steiger</surname>
          </string-name>
          .
          <article-title>A universal modular actor formalism for artificial intelligence</article-title>
          .
          <source>In IJCAI</source>
          , pages
          <fpage>235</fpage>
          -
          <lpage>245</lpage>
          ,
          <year>1973</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>Martin</given-names>
            <surname>Odersky</surname>
          </string-name>
          , Lex Spoon,
          <string-name>
            <given-names>Bill</given-names>
            <surname>Venners</surname>
          </string-name>
          .
          <source>Programming in Scala. Artima, First edition</source>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>Philipp</given-names>
            <surname>Haller</surname>
          </string-name>
          , Frank Sommers. Actors in Scala. Artima,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>Dirk</given-names>
            <surname>Taubner</surname>
          </string-name>
          .
          <article-title>On the implementation of Petri nets</article-title>
          .
          <source>In European Workshop on Applications and Theory of Petri Nets</source>
          , pages
          <fpage>418</fpage>
          -
          <lpage>434</lpage>
          ,
          <year>1987</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>