Mapping Petri Nets onto a Calculus of Context-Aware Ambients

: Petri nets are a graphical notation for describing a class of discrete event dynamic systems whose behaviours are characterised by concurrency, synchronisation, mutual exclusion and conflict. They have been used over the years for the modelling of various distributed systems applications. With the advent of pervasive systems and the Internet of Things, the Calculus of Context-aware Ambients (CCA) has emerged as a suitable formal notation for analysing the behaviours of these systems. In this paper, we are interested in comparing the expressive power of Petri nets to that of CCA. That is, can the class of systems represented by Petri nets be modelled in CCA? To answer this question, an algorithm is proposed that maps any Petri net onto a CCA process. We prove that a Petri net and its corresponding CCA process are behavioural equivalent. It follows that CCA is at least as expressive as Petri nets, i.e., any system that can be specified in Petri nets can also be specified in CCA. Moreover, tools developed for CCA can also be used to analyse the behaviours of Petri nets.


Introduction
Over the years, a large number of mathematical formalisms for concurrency theory have been developed, each with its distinct features.Petri nets [1,2] were among the first formalisms for modelling interacting sequential processes.Then, Tony Hoare developed the calculus of Communicating Sequential Processes (CSP) [3], and Robin Milner the Calculus of Communicating Systems (CCS) [4].These formalisms provided notations for modelling different forms of concurrency.Later on, the π-calculus [5] was introduced to extend CCS with the notion of mobility.In the π-calculus, mobility is modelled using the mechanism of scope extrusion, i.e., a name sent through a receptor (i.e., a name that is used to receive messages) can also be used as a receptor.However, this makes the implementation of the π-calculus difficult in distributed systems.Join-calculus [6] was thus developed by Fournet and Gonthier to provide a formal basis for the design of distributed programming languages, by replacing the communication and mobility mechanisms of π-calculus with the notion of join definition, which is much easier to implement in distributed systems.Recently, the Calculus of Context-aware Ambients (CCA) [7,8], inspired by the Calculus of Mobile Ambient (MA) [9], was developed to provide constructs for concurrency, mobility and context awareness based on a single notion of ambient, which is an abstraction of a place where computation can happen.CCA emerges as a suitable formalism to reason with the behaviours of pervasive systems and the Internet of Things [10].
It is customary in formal methods to compare the expressive powers of formalisms, i.e., whether one formalism can be mapped onto another.In [11], Mennicke presents operational Petri net semantics for join-calculus.An approach to mapping Petri nets to concurrent programs in CC++ is proposed in [12], which establishes a link between Petri nets and object-oriented concurrent programming and forms a foundation for a Petri-netbased transformational software development methodology.Similarly, Ref. [13] proposes a mapping from Petri nets to the language of the B-Method in an effort to incorporate the Petri nets' graphical notation into a software development method based on the B-language.A mapping of Petri nets to DEVS (Discrete Event System Specification) is presented in [14], so DEVS-based platforms can be used to analyse systems specified in Petri nets.
This paper proposes an approach to mapping Petri nets onto CCA.This allows for the graphical language of Petri nets to be used in combination with CCA for the modelling of complex distributed systems.The contributions of the paper is fivefold:

•
We propose an algorithm that transforms any Petri net into a CCA process (Section 2.3).

•
We prove that a Petri net and its corresponding CCA process are behavioural equivalents (Section 2. 3.3).This shows that CCA is at least as expressive as Petri nets, i.e., any system that can be specified in Petri nets can also be specified in CCA.

•
We demonstrate that the proposed algorithm is efficient and scalable (Section 2.3.4).Indeed, the time complexity of the algorithm is quadratic (i.e., the execution time is in the order of the square of the size of the Petri net in input) and the size of the CCA process generated in output grows linearly with the size of the Petri net in input.

•
The proposed algorithm is implemented in Python so a Petri net can be translated into a CCA process automatically at a click of a button (Section 2.3.4 and Appendix A).

•
The proposed approach is illustrated using a case study of the dining cryptographers problem (Section 3).
The remainder of the paper is structured as follows.Section 2 presents the proposed algorithm for mapping Petri nets onto CCA and discusses the efficiency and scalability of the algorithm.The notion of behavioural equivalence is also introduced in this section.The case study is presented in Section 3. In Section 4, we discuss the results.Section 5 concludes the paper and proposes future work.

Overview of Petri Nets
Petri nets are a graphical formalism to describe systems whose dynamics are characterised by concurrency, synchronisation, mutual exclusion and conflict [2,15].A Petri net consists of places, transitions, and directed arcs.A place is represented by a circle and a transition by a rectangle.Arcs run from a place to a transition or vice versa, and never between places or between transitions.A place may contain a non-negative integer number of marks called tokens.An example of a Petri net is depicted in Figure 1.Any distribution of tokens over the places will represent a configuration of the net called a marking.The places from which an arc runs to a transition are called the input places of the transition; the places to which arcs run from a transition are called the output places of the transition.Similarly, the transitions from which an arc runs to a place are called the input transitions of the place; the transitions to which arcs run from a place are called the output transitions of the place.Therefore, a Petri net can be defined formally as a tuple (P, T, I, O, m 0 ), where • P is a finite set of places.

•
T is a finite set of transitions, such that P ∪ T ̸ = ∅ and P ∩ T = ∅.• I : P × T → N is an input function.I(p, t) is the number of directed arcs from the place p to the transition t.

•
O : T × P → N is an output function.O(t, p) is the number of directed arcs from the transition t to the place p. • m 0 : P → N is the initial marking, which defines the initial number of tokens in each place.
Example 1.The Petri net shown in Figure 1 models the following ball game [16].The tokens in the places red and black represent red and black balls in an urn, respectively.As long as there are at least two balls in the urn, a person takes two balls from the urn.If the balls are of the same colour, then a black ball is returned; otherwise, a red ball is returned.Transition rb fires if the person takes two balls of different colours, transition rr fires if two red bails are taken and transition bb fires if two black balls are taken.This Petri net is formally defined as follows: Let us denote by Input(t) (with respect to Output(t)) the set of all input places (with respect to all output places) of a transition t, i.e., Input(t) = {p ∈ P | I(p, t) > 0} and Output(t) = {p ∈ P | O(t, P) > 0}.Transitions are the active components of a Petri net.A transition t is enabled if each of its input places p contains at least I(p, t) tokens, as formulated in (1), where m is the marking of the Petri net.
A transition may execute (or fire) if it is enabled.The execution of a transition t is atomic and consumes I(p, t) tokens from each input place p, and creates O(t, p) tokens in each output place p.Therefore, the execution of a transition t updates the marking of each place p connected to it, as in (2), where m(p) is the marking of a place p before the transition is executed and m ′ (p) is the marking of a place p after the transition is executed.
For example, Figure 2 shows the marking of the Petri net of Figure 1 after the transition rr has been executed.The execution of Petri nets is non-deterministic: when multiple transitions are enabled at the same time, they will execute in any order.

Overview of CCA
CCA [7,8] is a process calculus for specifying and reasoning regarding the behaviour of context-aware, mobile and concurrent systems.CCA is based on a single notion of ambient, which conceptualises an entity in which a computation can happen.An ambient is represented in the form n[P], where n is the name of the ambient and P is a process describing the behaviour of the ambient.We can also say that the process P is executed by the ambient n.An ambient can contain other ambients, called child ambients, forming a hierarchy of ambients.For example, in n[P | m[Q]], n is the parent ambient of m and m is a child ambient of n.Two ambients that have the same parent are siblings.There is a special ambient called root, which represents the root of the ambient hierarchy.Any ambient in CCA is a descendent of the root ambient.Ambients can be composed in parallel, using the parallel operator "|", to form a concurrent system.During their execution, ambients can communicate through a hand-shake message passing mechanism; i.e., an ambient (the sender) can send a message to another ambient (the receiver) and the sender and the receiver must synchronise for the communication to happen, as explained in Section 2.2.2.An ambient can be mobile; the mobility capabilities "in" and "out", described in Section 2.2.2, allow an ambient to move inside a sibling ambient and outside its parent ambient, respectively.An ambient can also be aware of its context so that its behaviour can change in response to changes in the context.This is undertaken using context expressions and context-guarded processes (see Section 2.2.4).A context expression is a predicate over the state of the ambient hierarchy.In distributed systems, each component of a system can be modelled as an ambient, e.g., sensors and computers.An example is given in Section 2.2.5.
CCA is formally described by the grammar in Table 1, based on three syntactic categories: processes P (or Q), capabilities M, and context expressions κ.The symbols n, x, y and z are names.Note that comments can be added anywhere in a specification using the prefix // for a single line comment or the pair /* and */ for a multiline comment.The syntax of a process P is given in Table 1.The process 0, also known as the inactivity process, does nothing and terminates immediately.The process P | Q denotes the parallel composition of the processes P and Q.A process of the form {P} behaves just like P. The process (new n) P creates a new name n and the scope of that name is limited to the process P. The replication !P denotes a process which can always create a new parallel copy of P, i.e., !P is equivalent to P | !P.The process n[P] denotes an ambient named n whose behaviour is described by the process P. A context expression κ is a logical formula that specifies a property upon the state of the environment.A context-guarded prefix < κ > M.P is a process that waits until the environment satisfies the context expression κ, and then performs the capability M and continues like the process P. We let M.P denote the process < true > M.P.An if-then process if < κ 1 > M 1 .P 1 . . .< κ ℓ > M ℓ .P ℓ fi waits until at least one of the context expressions (κ i ) 1≤i≤ℓ holds, and then proceeds nondeterministically like one of the < κ j > M j .P j processes for which κ j holds.An if-then-else process if < κ 1 > M 1 .P 1 . . .< κ ℓ > M ℓ .P ℓ else P fi behaves like an if-then process, but does not wait and continues like the P process if none of the branches can be executed.A process let x 1 = e 1 , . . ., y ℓ = e ℓ in P behaves like the process P in which each occurrence of x i is substituted to the value of the arithmetic expression e i , for 1 ≤ i ≤ ℓ and ℓ ≥ 1.A search process find x 1 , . . ., x ℓ : κ for P looks for a list of names n 1 , . . ., n ℓ in the context such that the context expression κ in which each occurrence of x i is replaced by n i holds, and continues like the process P in which each occurrence of x i is replaced with n i , 1 ≤ i ≤ ℓ and ℓ ≥ 1.A process of the form proc x(y 1 , . . ., y ℓ ) P defines a process abstraction named x, whose behaviour is described by the process P. The names y 1 , . . ., y ℓ are the formal parameters and the process abstraction is ℓ ≥ 0. A process abstraction is a mechanism to give a name, say x, to a process P and to later use that name anywhere to refer to the process P, just the same way as functions and procedures are used in programming languages.

Capabilities
A capability is an elementary action that an ambient can perform.The syntax of a capability M is given in Table 1.The capability skip represents one transition, i.e., one execution step.An ambient can move into a sibling ambient n by performing the capability in n, and move out of its parent ambient by executing the capability out.An ambient can exchange messages with another ambient using the output capability α send(z 1 , . . ., z ℓ ) to send a list of names z 1 , . . ., z ℓ to a location α, and the input capability α recv(y 1 , . . ., y ℓ ) can receive a list of names from a location α for the variables y 1 , . . ., y ℓ , for some ℓ ≥ 0. The location α can be '@' to mean any parent, 'n@' to mean a specific parent n, '#' to mean any child ambient, 'n#' to mean a specific child n, '::' to mean any sibling, 'n ::' to mean a specific sibling n, or ϵ (empty string) to mean the executing ambient itself.A capability del n deletes an empty child ambient n (i.e., n[0]).A capability of the form α x(z 1 , . . ., z ℓ ) calls the process abstraction x defined at the location α, and the names z 1 , . . ., z ℓ are the actual parameters, ℓ ≥ 0.

Context Model
In CCA, a context is modelled as a process with possibly a single hole in it.The hole (denoted by ⊙) in a context C represents the position of the process, for which C is a context.For example, suppose a system is modelled by the process Thus, the context of a CCA process is described by the grammar in Table 2.A context expression (CE, for short) is a formula representing some property over context.

Context Expressions
The syntax of a process expression κ is given in Table 1.The formal semantics of context expressions (CEs) with respect to the context model of Table 2 are given in Table 3, where the notation C |= κ means that the context C satisfies the context expression κ.We also write |= κ to mean that a context expression κ is valid, i.e., κ is satisfied by all contexts.

|= true
The CE true holds for all contexts, while the CE false holds for no context.A CE n = m holds if the names n and m are identical.The CE 0 holds for the empty context 0. The CE this holds solely for the hole context, i.e., the position of the process evaluating that context expression.Propositional operators such as not, and and or expand their usual semantics to context expressions.A CE κ 1 | κ 2 holds for a context if that context is a parallel composition of two contexts such that κ 1 holds for one and κ 2 holds for the other.A CE n[κ] holds for a context if that context is an ambient named n such that κ holds inside that ambient.A CE next κ holds for a context if that context has a child context for which κ holds.A CE somewhere κ holds for a context if there exists somewhere in that context a sub-context for which κ holds.Some examples of context expressions that are used later in this paper are given in Table 4.
the lock is on.
Context expressions are used in CCA to specify context-aware processes.We recall in Table 5 the formal semantics of context-aware processes, where σ is a substitution of names, ≡ is the congruence relation of processes and −→ is the reduction relation of processes.The notation val(e) represents the value of an expression e.The complete formal semantics of CCA can be found in [7,8].

An Example
This example illustrates how to model a distributed system in CCA.Consider a simple access control system that consists of a RFID tag, RFID reader, a garage door and a server.The system controls access to the garage through the door.When the reader detects an RFID tag, it reads the ID (aka identification) number of the tag and sends an access request to the server.The server checks if the ID number is valid (i.e., permitted to access), in which case the reader shows a green light and the garage door opens.If the ID number is invalid, the reader shows a red light (to mean that the access request is denied) and the door stays closed.Let us assume that a valid ID number is a value between 100 and 200, exclusive.Each component (RFID tag, RFID reader, garage door and the server) of this distributed system can be modelled as an ambient in CCA.
Indeed, an RFID tag is a device that stores an ID number.The ID number is sent to an RFID reader when the tag is in the range of the reader.In CCA, an RFID tag and an RFID reader can be represented as ambients.The boundary of the reader ambient delimits the range of the reader, i.e., an RFID tag is in the range of a reader if that tag is a child ambient of the reader.An RFID tag that contains the ID number 166 can be modelled in CCA by the ambient in Listing 1.It is assumed that initially the RFID tag is not in the range of the RFID reader, and then it moves into the range of the reader using the capability "in" (described in Section 2.2).
Listing 1.The ambient representing the RFID tag.

RFID_tag[ !@send(166).0 | in RFID_reader.0 ]
An RFID reader can be specified, as in Listing 2. It reads the value of an RFID tag and requests the access control service (ac_service) from the server.Upon receipt of a response (status) from the server, the reader shows a green light (status=valid) to indicate that the access request is authorised, and a red light (status=invalid) if the access request is denied.
Listing 2. The ambient representing the RFID reader.

RFID_reader[
!recv().#recv(id).server::send(RFID_reader,ac_service, id).server::recv(status).send().0| send().0] The server can be modelled as the ambient in Listing 3. It receives a service request from a client and executes the requested service.A service is modelled as a process abstraction.In this example, there is only one service: the access control service ac_service.The last component of the system to specify is the garage door.The door can be controlled by the server and is modelled by the ambient in Listing 4. It closes if it receives the command "close" from the server and opens if it receives the command "open".The current state of the door (closed/opened) is checked using the context expression state(x) defined in Table 4.The overall access control system is modelled in Listing 5 as the parallel composition of its four components described in Listings 1-4.
Listing 5.The CCA process representing the access control system of Section 2.2.5.Since CCA specifications are executable, the simple access control system can be analysed using the CCA simulator ccaPL, and the simulation outputs are illustrated in Figures 4 and 5 in Section 3.1.The next section presents an algorithm for translating a Petri net into an equivalent CCA process.

An Algorithm for Mapping a Petri Net onto a CCA Process
Algorithm 1 translates a Petri net (see Section 2.1) into a CCA process.The algorithm takes as input a Petri net (P, T, I, O, m 0 ) and returns in output a CCA process in the variable cca_str.In CCA, Petri net places and transitions are modelled as ambients, as explained in Sections 2.3.1 and 2.3.2.We call a place ambient an ambient that models a Petri net place.Likewise, we call a transition ambient an ambient that models a Petri net transition.A semaphore is used to guarantee that the execution of a transition ambient is atomic, i.e., at most one transition ambient can be executed at a time.In order to execute, a transition ambient must obtain the semaphore; otherwise, the transition ambient must wait until the semaphore is released by another transition ambient.This semaphore is described in CCA by the ambient lock defined in Listing 6.The semaphore is in the obtained state if the ambient contains a child ambient on[0] and is in the released state otherwise.

lock[ recv().::recv(t).{ on[0] | t::recv().del on.send().0 } | send().0 ]
The behaviour of the ambient lock can be explained as follows.Initially, the semaphore is in the released state, i.e., no transition ambient is being executed.The ambient waits (using the capability :: recv(t)) until a transition ambient t is willing to obtain the semaphore, and then creates a child ambient on[0] to indicate that the semaphore is obtained by the transition ambient t.The semaphore remains in the obtained state until it is released by the transition ambient t (using the capability t :: recv()), in which case the child ambient on[0] is deleted.The context expression lockOn() defined in Table 4 holds if the semaphore lock is in the obtained state, i.e., if it contains a child ambient on[0].
In Algorithm 1, the declaration of the context expression lockOn() is created in line 2, together with other simulation directives such as the execution mode and the simulation length.In ccaPL, these declarations appear between the keywords "BEGIN_DECLS" and "END_DECLS".The semaphore lock is created in line 3 of Algorithm 1.The lines 5-7 of Algorithm 1 are explained in Section 2.3.1 and the lines 9-25 are explained in Section 2.3.2.

Modelling Places
In this section, we show how a Petri net place can be modelled as an ambient in CCA.For each place p ∈ P, an ambient (called place ambient) of the same name is created in line 7 of Algorithm 1.The general form of this place ambient is given in Listing 7. Initially, a place ambient contains m 0 (p) = x tokens.This is represented in the place ambient in Listing 7 by the process "send(x).0".A child ambient of the place ambient is also created as "_(1000 + x)[0]", e.g., if x = 1 then the child ambient is "_1001[0]".This encoding reflects in the child ambient's name the number of tokens in the place ambient and satisfies the property stated in Theorem 1.Therefore, the names of the child ambients of the place ambients can be compared instead of the number of tokens of these place ambients.The behaviour of a place ambient can be summarised as follows.A place ambient (see Listing 7) reads its current number of tokens, calculates the name of its child ambient and then waits until a transition ambient it is connected to starts executing (see ":: recv(v)").It then deletes its current child ambient, updates its number of tokens according to (2) and creates a child ambient that reflects its new number of tokens.It also signals to the running transition ambient that it has completed updating (see ":: send()").For example, the place ambients for the places red and black of the Petri net in Figure 1  Definition 2. The marking (also known as the number of tokens) of a place ambient is a non-negative integer number x such that the name of its child ambient is "_" + str(1000 + x).For example, the marking of the place ambient red in Listing 8 is 3 and that of the place ambient black is 2.
Theorem 1.Let n, x and y be three integers such that n ≥ 1, 0 ≤ x < 10 n and 0 ≤ y < 10 n .Then, x ≥ y ⇔ str(10 n + x) ≥ str(10 n + y).The proof of Theorem 1 can be carried out by induction on n, as follows.

Induction case:
Suppose that the theorem holds for n and prove that the theorem also holds for n + 1.

Modelling Transitions
Similarly to a place, a Petri net transition can be modelled as an ambient in CCA.Indeed, Algorithm 1, in the lines 9-25, creates for each transition t ∈ T an ambient (called transition ambient) named t of the form described in Listing 9.The transition ambient uses the context expression state(p, x) defined in Table 4 to check if a place ambient p has a child ambient x.Note that the name of a child ambient of a place ambient is encoded to reflect the number of tokens of that place ambient and to satisfy the property stated in Theorem 1.In Listing 9, the variables p1, . . ., pn denote the names of the input place ambients of the transition ambient and q1, . . ., qk denote the input or output place ambients of the transition ambient.The behaviour of the transition ambient is an iterative process, which waits until the semaphore lock is released and then obtains the semaphore lock (line 2 in Listing 9).It then finds the names of the child ambients of the input place ambients p1, . . ., pn (line 3) and checks if the guard of the if-statement holds (line 4), in which case the number of tokens of each place ambient connected to it is updated according to (2) (line 5).Finally, the process releases the semaphore lock and readies itself for further execution (lines 6 and 7).The guard of the if-statement can be formulated as in (3), where t (with respect to p) denotes a transition (with respect to a place) and t a (with respect to p a ) the transition ambient of t (with respect to the place ambient of p).guard(t a ) = ∀p ∈ Input(t) ∃x : state(p a , x) ∧ x ≥ "_" + str(1000 + I(p, t)).
(3) Definition 3. We say that a transition ambient t a is enabled if guard(t a ) holds.
An example of a transition ambient is given in Listing 10 for the transition rr of the Petri net in Figure 1.
Listing 9. General form of a transition ambient.
the number of tokens (also known as marking) of a place the name of the child ambient of a place ambient encodes the number of tokens of the place ambient, as in Definition 2.
a Petri net the parallel composition of the semaphore ambient lock defined in Listing 6 with all the place ambients and all the transition ambients.An example is given in Listing 11

Behavioural Equivalence
In this section, we prove that the behaviour of a Petri net and that of its corresponding CCA process, generated by Algorithm 1, are equivalent according to Definition 4.

Definition 4 (Behavioural Equivalence
).A Petri net (P, T, I, O, m 0 ) is behaviourally equivalent to its corresponding CCA process generated by Algorithm 1 if:

•
Each place p ∈ P and its corresponding place ambient p a have the same initial marking, i.e., ∀p ∈ P : m 0 (p) = m 0 (p a ).
• A transition t ∈ T is enabled if and only if its corresponding transition ambient t a is enabled, i.e., ∀t ∈ T : enabled(t) ⇔ guard(t a ).
• For each transition t ∈ T, the execution of its corresponding transition ambient t a is atomic, i.e., two transition ambients cannot execute at the same time.

•
For each transition t ∈ T, the execution of its corresponding transition ambient t a updates the markings of the place ambients, as in (2).
In the following lemmas, we assume a Petri net (P, T, I, O, m 0 ) and its corresponding CCA process generated by Algorithm 1.For each place p ∈ P, we let p a denote the corresponding place ambient, and for each transition t ∈ T, we let t a denote the corresponding transition ambient.
Proof.A semaphore lock (defined in Listing 6) is used to guarantee that two transition ambients cannot execute at the same time.The execution of a transition ambient is guarded by a guarded prefix "< not lockOn() >lock::send(t)", as shown in Listing 9. Therefore, the execution starts only if the context expression "not lockOn()" holds, i.e., if the semaphore is not in the obtained state, according to the semantic rule (R1) in Table 5 and the definition of the context expression "lockOn()" in Table 4.When the semaphore is not in the obtained state, a transition ambient can obtain the semaphore by sending its name to the semaphore using the semantic rules (R9), (R10), (R1) and (R12) in sequence.Once the semaphore has been obtained, it is released only when it receives a message from the transition ambient t that obtained it, according to the continuation process "t::recv().delon" in Listing 6.This continuation is executed by applying the semantic rule (R14) followed by (R8).This happens only when the transition ambient t has reached Line 6 (or Line 7) of Listing 9, and is willing to send a message to the semaphore lock using the semantic rule (R14).Therefore, no two transition ambients can execute at the same time.
Lemma 4. The execution of an enabled transition ambient updates the markings of the place ambients, as in (2).
Proof.The general form of a transition ambient is given in Listing 9, and that of a place ambient is shown in Listing 7. Therefore, the execution of an enabled transition ambient t (i.e., (3) holds for this transition ambient) is carried out as follows, using the semantic rules of Table 5.

•
In Line 2 of Listing 9, the rules (R9) and (R12) are applied to obtain the semaphore lock.

•
In Line 3, the rule (R5) is applied to find the name of the child ambient of each input place ambient.

•
In Line 4, the condition of the if-statement is evaluated to be true, since the transition ambient is enabled (see ( 3)).Therefore, Line 5 is executed next, according to the semantic rule (R3).

•
In line 5, for each input or output place ambient p of the transition ambient t, the process "p::send(-I(p,t)+O(t,p)).p::recv()" is executed to send (using the rule (R12)) to p the value −I(p, t) + O(t, p), and then it must wait for the acknowledgement (using the rule (R13)) that p has successfully updated its marking.Note that the value −I(p, t) + O(t, p) is a constant for each pair {p, t}.

•
In Line 6, the transition ambient releases the semaphore lock using the semantic rule (R14).
In the meantime, each input or output place ambient p (specified as in Listing 7) runs in parallel to t and behaves as follows.

•
The rules (R9) and (R10) are applied to receive in the variable n the current marking of p.  2), and to calculate (at the same time) the new name of the child ambient of p (y = "_" + str(1000 + w)) in the variable y. • Rules (R9) and (R10) are applied to set the new marking of the place ambient to w. • Rule (R13) is used to tell the running transition ambient that the marking of p has been updated.• Finally, the new child ambient named y is created.
We conclude that the execution of an enabled transition ambient updates the makings of the place ambients, as in (2).Theorem 2. A Petri net (P, T, I, O, m 0 ) and its corresponding CCA process generated by Algorithm 1 are behaviourally equivalent.
Proof.The proof of Theorem 2 is straightforward from Definition 4 and the Lemmas 1-4.

Complexity of the Algorithm
It is important to discuss the complexity of the algorithm in terms of the execution time, and the size of the CCA process produced as the output in comparison to the size of the Petri net received as the input.For a Petri net of n places and m transitions, Algorithm 1 takes O(n) time to generate the place ambients (see the loop in line 5) and O(nm) time to generate the transition ambients (see the loop in line 9).Therefore, the overall time complexity of Algorithm 1 is O( ñ2 ), where ñ = max(n, m); i.e., the execution time is in the order of the square of the size of the input.In addition, the algorithm creates two ambients for each place (see lin 5): a place ambient with a child ambient, as depicted in Listing 7.However, a single ambient is created for each transition in line 9 of Algorithm 1.The general form of a transition ambient is depicted in Listing 9. Finally, a unique semaphore ambient named lock (see Listing 6) is created in line 3. Thus, the total number of ambients created is 2 × n + m + 1, and so the size of the CCA process generated by Algorithm 1 is in the order of O( ñ), i.e., the size of the CCA process generated as the output grows linearly with the size of the Petri net as the input.The proposed algorithm is thus efficient and scalable.An implementation of the algorithm in Python (version 3.10.11) is given in Appendix A, so the mapping of a Petri net onto a CCA process can be carried out automatically at the click of a button.

Results
In this section, the proposed algorithm is validated through experiments using a case study of the dining cryptographers problem.The experiments are carried out using the CCA simulator ccaPL.

Overview of the CCA Simulator ccaPL
The syntax of a ccaPL program is given in Table 7, where P is a process and k is a context expression defined in Table 1; <Id> stands for an identifier (i.e., a name), e for empty string, and <Val> is a non-negative integer number.It follows that a ccaPL program is composed of a declaration block (optional) and a body, which is a CCA process.The declaration block starts with the keyword BEGIN_DECLS and ends with the keyword END_DECLS.In between these keywords, one can add the definitions of context expressions using the keyword def, and the declarations of execution directives.Note that ccaPL programs are case-sensitive.An example of a ccaPL program is given in Listing 11.The execution directives control how the parallel processes of a program are executed.By default, at each execution step the process to be executed is chosen deterministically based on two criteria: how long the process has been willing to execute (FIFO (First In First Out)) and, in case of conflict, the sequential order as they appear in the program text.The execution directive mode random changes the execution mode to a random selection of the processes to be executed.The directive display code forces the program code to be displayed after each execution step.By default, only reduction steps are shown in the execution traces; with the directive display congruence, the congruence steps are also shown in the execution traces.The directive length = xx stops the execution of the program after xx steps.Comments can be added anywhere in a program text using the prefix // for a single line comment or the pair /* and */ for a multiline comment, just like in the Java programming language.The ccaPL tool can generate three types of execution output, as shown in Figure 3: a textual execution trace, a communication graph and a behaviour graph.For illustration, the execution outputs for the simple access control system described in Section 2.2.5 are depicted in Figures 4 and 5.

Textual Execution Trace
The execution trace is a text describing the execution steps.An example of textual execution trace is given in Figure 4.Each execution step trace is prefixed by the symbol --> (with respect to <-->) for a reduction step (with respect to a congruence step), followed by the explanation of the execution step between a pair of curly brackets { and }.For example, the explanation of a message-passing step has the form {child to parent: A ===(X)===> B}, meaning that a message X is sent by a child ambient A to a parent ambient B. Notations such as Child to parent, Parent to child, Sibling to sibling and local provide information about the relationship between the sender A and the receiver B. In particular, local means the sender is the receiver (i.e., A and B are the same ambient).An explanation of the form {binding: n -> X} corresponds to the execution of a statement of the form find n:k for P and means that the value (i.e., name) X has been found for the variable n such that the context expression k holds in the current context.The variable n will then be replaced by the name X in the process P (see the semantic rule R5 in Table 5).The remaining execution step explanations are straightforward.To generate a textual execution trace, use the following command line, where myprog.cca is your program file.

Communication Graph
The execution trace is a diagram showing the timeline of the communications between the ambients.An example of the communication graph is given in Figure 5a.The top row of the diagram is the list of the ambients being executed.The execution timeline of each ambient is denoted by a vertical dashed line, and the time increases from top to bottom.An arrow from one timeline (sender ambient) to another (receiver ambient) indicates a communication step between the corresponding ambients.This arrow is labelled with the message exchanged.A communication graph is created using the following command line, where XXX is the image format, like ps, jpg, png, PDF and so on.java -jar ccaPL.jar-gXXX myprog.cca

Behaviour Graph
This is similar to a communication graph, but in addition it shows the movement steps using a grey box containing a text of the form A --> B on the timeline of an ambient to indicate that the ambient has moved from Location A to Location B. An example of a behaviour graph is given in Figure 5b.Recall that an ambient can move from one location to another by performing the capability in or the capability out (see Section 2.2).The following command line will generate a communication graph myprog_0.XXX and the corresponding behaviour graph myprog_1.XXX.java -jar ccaPL.jar-gxXXX myprog.ccaNote that the generation of the graphical execution traces requires that the Graphviz package [17] be installed on your computer.

A Case Study: The Dining Cryptographers Problem
The standard dining cryptographers problem [18] consists of three diners and requires that the identity of the person who pays the bill (which may be one of the cryptographers or an external person) remains anonymous.In this section, we consider a simplified version of the problem with just two diners.This version is also used in [19,20], and can be extended to three or more diners.Alice and Bob are two cryptographers who have a dinner in a restaurant.When it is time for the bill, they are informed by the waiter that the bill has already been paid.Both Alice and Bob, would like to know whether the bill was paid by a third person, or whether it was one of them.However, if it is the second case, then they do not want an eavesdropper, Yves, on a neighbouring table to know which of them paid.The following is the protocol that they decided to use to solve this problem.

A Dining Cryptographers Protocol
Firstly, they toss two coins that are visible to both of them.At the same time, they ensure that Yves cannot see either of them.If Alice paid, she lies about the parity of the two coins i.e., she calls 'agree' if she sees a head and a tail, and 'disagree' otherwise.If Alice did not pay, she tells the truth about the parity of the coins.The same applies for Bob.Now Alice and Bob both know whether one of them paid.In case their calls are the same they know that a third person paid, otherwise it must have been one of them-in this example they actually both know which.On the other hand, Yves can only tell whether or not one of Alice and Bob paid, but not which one.It should be noted that Yves also knows about the protocol.A possible encoding of the protocol using a Petri net is depicted in Figure 6.The two places at the left of the net represent Alice's initial state: having paid is shown by placing a single token in place AP, and having not paid is shown by placing a single token in place A¬P.The initial state of Bob is represented by the places on the right.The three possible initial markings for Alice and Bob are given in (4).
The top two places in the centre of the net represent the first coin: heads is represented by placing two tokens in the place c 1 h, and tails is represented by placing two tokens in the place c 1 t.The bottom two places, c 2 h and c 2 t, represent the second coin.As was mentioned, both Alice and Bob must see the coins.For this reason, the marked places must contain two tokens.As a result, the possible initial markings for the coins are the multi-sets in (5).
The cross-product of the cryptographer markings in (4) and the coin markings in (5) denotes the set of all 12 possible initial markings.The eight transitions on the right represent the eight possible scenarios for Bob, given by two possibilities for each coin multiplied by the two possibilities for his own initial state.The transitions on the right represent Bob saying that the coins 'disagree' (B0) or Bob saying that the coins 'agree' (B1), and it is similar for Alice on the left.

Mapping the Petri Net of the Dining Cryptographers Protocol onto a CCA Process
Algorithm 1 was applied to map the Petri net in Figure 6 onto a CCA process.In this section, it is shown that the CCA process and the Petri net behave in the same way.To achieve this, the CCA process is executed in ccaPL for each of the 12 possible initial markings.The result is summarised in Table 8.It follows that the transitions enabled in the Petri net correspond exactly to the transition ambients executed by the CCA process.A sample of the execution traces, in the form of a communication graph, is given in Figure 7.This corresponds to the simulation of the case in which Alice paid the bill and Bob did not (i.e., {AP, B¬P}), and the toss of the two coins shows heads for coin 1 and tails for the other (i.e., {c 1 h, c 1 h, c 2 t, c 2 t}).The execution trace indicates, with a pair of consecutive arrows, a transition ambient that is not enabled (see (3)).The current number of tokens of each place ambient is shown as a label to a loop-arrow along the execution timeline (i.e., the vertical dashed line) of the place ambients.The execution trace of an enabled transition ambient starts with an arrow labelled with the name of the transition ambient and terminates with an arrow labelled end.Therefore, in Figure 7, the simulation shows that the only enabled transitions (and thus those executed) for this case are the transition ambients A1a and B0c.This experiment can be reproduced using the Python implementation of Algorithm 1 given in Appendix A to generate the CCA process for the dining cryptographers protocol, and then the CCA process can be executed in the simulation tool ccaPL.

Discussion
There has been a substantial amount of research that adapts and relates features of process algebras to Petri nets.Petri Box calculus [21,22], for instance, is a process algebra based on CCS that presents compositional semantics for high-level constructs of concurrent programming languages with regard to Petri nets.Reference [23] proposed a translation from Condition/Event (C/E) nets to Circal process algebra based on a binary composition and hiding operators.Moreover, in [24][25][26], frameworks that endow Petri nets with labelled transition systems are presented, applying techniques come from process algebra.In particular, in [24], the theory of bigraphs is applied to C/E nets, by converting C/E nets to bigraphs and examining their behavioural theory.Moreover, there has been significant work in translating process algebra to Petri nets [27], with applications in the verification of mobile systems [28].For instance, refs.[29,30] proposed a translation of CCS into Petri nets, while [31] presented distributed semantics for π-calculus based on Petri nets.
Powerful, usable and flexible contemporary systems are characterised by features such as dynamic reconfigurability, where nodes in networks can dynamically appear or vanish, and logical mobility, where connections in ad hoc networks can be formed dynamically.These systems are also called reference-passing systems (RPS) [27].As the number of such systems is constantly increasing, the correct functionality of such systems is of paramount importance to eliminate potential costly errors in the design phase.
There are a number of formalisms that are suitable for modelling and verifying specifications that are characterised by concurrency and the ability to form dynamic logical connections between individual modules [32,33].The major factors and trade-offs in selecting an appropriate formalism are its expressiveness and the tractability of the associated verification techniques.Formalisms that are expressive are Turing-powerful, and so not decidable in general.However, it is possible to apply some restrictions (e.g., finiteness of the control) that would ensure decidability, while preserving a reasonable modelling power.
In [34], the authors present a number of equivalence notions on Petri nets that can be used in the construction of algebraic models.In [29], the authors proposed a new set of inference rules for a subclass of Calculus of Communicating Systems (CSS).This allowed for a direct translation to a subclass of Petri nets, and more particularly to condition/event nets.Early work on translating Petri nets into CCA is presented in [35], but the proposed algorithm is limited to a subset of Petri nets without multiple arcs between a place and a transition.Our algorithm can handle Petri nets with multiple arcs between places and transitions, e.g., the Petri net in Figure 1.In [36], a notion of net calculus is introduced, which is defined through a place/transition Petri net.The authors proposed a calculus of nets, called SCONE.Based on this, relationships between SCONE and a subset of CCS are studied.In [37], different approaches for the modelling of parallel processes are examined.The work considers process algebra, like CCS and communicating sequential processes (CSP) as main representatives.It is shown that the construction of transition nets is possible for all CCS programs in which recursive calls start sequentially.In [32], Finite Control Processes (FCP), a subclass of π-calculus, have been proposed, where the system is defined as a parallel composition of sequential entities.In [27], the authors introduced a translation of FCP to safe Petri nets to formally verify mobile systems.

Conclusions
In formal methods, it is customary to compare the expressive power of various languages and provide ways of mapping one language to another.This paper has followed the same approach and proposes an algorithm that maps Petri nets onto CCA.It is formally proven that a Petri net and its corresponding CCA process (generated by the proposed algorithm) are behaviourally equivalent.This demonstrates that any system that can be specified in Petri nets can also be specified in CCA.Thus, CCA is at least as expressive as Petri nets.It follows from this work that a Petri net can now be analysed using CCA verification tools like ccaPL.To do so, a Petri net is first translated into a CCA process using the proposed algorithm, and then the CCA process is analysed using ccaPL.The algorithm is implemented in Python so that the translation of a Petri net into a CCA process can be performed automatically at the click of a button.A real-world case study of the dining cryptographers problem was used to illustrate the proposed approach.

Figure 2 .
Figure 2. Petri net of Figure 1 after the execution of the transition rr.

Listing 3 .
The ambient representing the server.

Listing 4 .
The ambient representing the garage door.

Figure 7 .
Figure 7. Execution trace for the case where Alice paid and Bob did not pay (i.e., {AP, B¬P}) and coin 1 shows heads and coin 2 shows tails (i.e., {c 1 h, c 1 h, c 2 t, c 2 t}).

Table 2 .
Syntax of contexts.

Table 3 .
Satisfaction relation for context expressions.

Table 4 .
Examples of context expressions.

Table 5 .
Semantics of context-aware processes.

Table 6 .
is presented in Listing 11.Table6summarises the mapping of the Petri net concepts to CCA concepts.Example of the CCA process generated by Algorithm 1 for the Petri net in Figure1.Mapping of Petri net concepts to CCA concepts.

Table 7 .
Syntax of a ccaPL program.

Table 8 .
Comparison of the behaviours of the Petri net in Figure6to those of its corresponding CCA process.The column # numbers the 12 possible initial markings of the Petri net.