Abstract
On one hand, Petri nets are widely used as a modeling formalism to assess both structural and behavioral properties of the multi-agent system bacause of their mathematical foundations and the rich underlying analysis tools has developed around them. On the other hand, Maude is a very powerful formal specification language based on rewriting logic that is known as a unifying framework for different types of Petri nets and offers a wide range of analysis techniques.
In this paper, we will present a new algorithm allowing the automatic generation of Maude specifications from Petri nets models in order to help designers to effectively obtain the rewriting logic based specification of their multi-agent systems and then facilitate their analysis, pick up time and stay away from human related errors occurred during the manual preparation of such specification.
Introduction
It is very evident that the paradigm of Multi-Agent System (MAS) has emerged as one of the cutting-edge approaches that led to the study of a wide range of problems in different fields [61, 48, 42, 32]. However, due to the complex nature and heterogeneity of multi-agent based system components, designers need to simulate the system behavior and for that they often use formal modeling notations and approaches to assess key properties of multi-agent systems. Such approach could be used to provide a formal description of agent’s behavior and/or system functions, provide guidelines for the design of MAS, facilitate their preliminary analysis, ensure that the system will comply with a set of required properties and then make decision about its feasibility [24, 47, 63].
In this context, Petri nets are the most popular modeling language that have proven to be very reliable in practice for both MAS simulation and analysis [16, 51]. This success of Petri nets is principally due to their graphical notation, simple semantics, and the rich underlying mathematical theory that has developed around them for analyzing their models. For instance, Petri nets have been used to describe both the internal and external behavior of agents [1, 37, 38], conversation and interaction protocols [15, 8, 50] and developing cooperation for multi-agent systems [39, 31]. However, their potentiality of modeling should not hide the increasing need for automatic techniques, methods and tools facilitating the formal analysis of large scale Petri net models.
On the other hand, Maude [23] is a very powerful formal specification language based on rewriting logic [44] that is a unifying framework for Petri nets [33, 7, 9, 55, 35]. In addition, Maude offers a wide range of analysis techniques and it has been used in different works to specify and analyze multi-agent systems [57, 59, 4]. However, the transcription of Petri net models into Maude specifications is prepared manually. There lacked a bridge to directly link Petri net models and the Maude system. Such operation is turned out to be difficult, time consuming and error-prone especially in the case of large scale and complex models.
The main goal of this paper is to bridge the gap between Petri net models and Maude system and for that we present a new algorithm to automatically generate Maude specifications from Petri Net models of multi-agent based systems, to palliate the above mentioned difficulties, and their consequently related risks; especially in the case of safety-critical systems. In addition, it is worthy to note that the advantages of this algorithm will not be limited to those designing multi-agent systems, but all practitioners building models with Petri nets can benefit from this algorithm and then exploit the Maude analysis tools for their models.
The following Section 2 gives a short literature review on the use of Petri nets and rewriting logic in the context of multi-agent systems. Section 3 introduces the required concepts of rewriting logic and Petri nets and we alternatively refer to [45, 53] for background. In Section 4, we present the process to generate Maude specifications from Petri nets models. Then, a case study and results are presented in Section 5. Section 6 presents the most related work to this paper. Finally, Section 7 concludes the paper with perspectives for the future work.
Literature review
In fact, various modeling techniques have been proposed and used in order to go from the informal or less formal system description to its formal specification and then, the individual agents with their relationships are described in terms of activities by means Petri nets, automata, state machine, logic rules or conditional statements (if-then) … etc. [29, 58, 49, 36, 2]. In this section, and because it is out of the scope of this paper, we will not compare Petri nets and Maude with other formalisms and specification languages since our interest is focused on the automatic generation of Maude specification from Petri net. However, we will present some previous works to show the advantages, effectiveness and then motivate our choice of Petri nets and rewriting logic.
Petri nets based works
Petri-net is still known as one of the most popular used formalism to assist designers in the early stages of multi-agent-based simulation of models development [3, 21]. For instance, Petri nets have been widely used to describe both the internal, external and social behavior of agents [1, 46, 37, 38], conversation and interaction protocols [15, 8, 50] and developing cooperation for multi-agent systems [39, 31]. In addition, a lot of extensions have been also proposed for Petri nets in order to describe intentional agents and other aspects in MAS [37, 17, 30, 18, 43, 19] and maintain significant properties (mathematical foundation) of ordinary Petri nets.
Moreover, Petri nets have been widely favored for analyzing multi-agent systems because of their exact mathematical definition of their execution semantics with the well-developed theory for process analysis. Hence, the corresponding Petri net models of multi-agent systems will be assessed by using the existing analysis methodologies and simulation techniques for Petri nets [41, 6, 52, 20, 14]. In [5], Petri net models are generated from the multi-agent UML diagrams to simulate the behavior of an agent. Thereafter, Petri net analysis techniques are applied to automatic agent behavioral testing.
Rewriting logic based works
The Maude term rewriting language has been advocated in several works for the specification and verification of multi-agent systems. The Maude system is mainly characterized by its expressive strength, as well as the large number of formal analysis tools. For instance, the paper [60] presents a Maude based implementation of (a simplified version of) the cognitive agent programming language 3APL. In such implementation, the 3APL configurations are represented as terms, and the transition rules are mapped into rewrite rules. In the enhanced version [59], Maude is used for prototyping agent programming language BUpL (Belief Update programming Language) and executing agent programs. Thereafter, the LTL-model checker and Maude analysis tools are also used for verification and testing. Authors in [40] used Maude to gain a formal description for Agent-Group-Role-based-organization models and, they are simulated and verified by means of its associated tools.
Finally, the Maude language is used for behavior formalization of DIMA model’s agents [13]. In this work, the inherent aspects of a DIMA models are captured and then, the corresponding Maude descriptions have been validated using the analysis tools of Maude. Such work has been extended to support both formal description and verification of DIMA multi-agent models [12]. However, the common main disadvantage of all these works is that the translation of multi-agent models into Maude specification is prepared manually in ad hoc manner. Hence, it may be very difficult to ensure that such specification is a faithful description of the studied multi-agent system.
Synthesis
According to what we have exhibited, it turns out to be evident that the use of Petri nets and Maude in MAS context is very advantageous and helpful. On one hand, the Petri nets formalism permits to normally visualize the parallelism, the synchronization, the sharing of resources and conflicts in distributed systems. What’s more, it allows to model the behavior (internal and external) of the agents, interaction protocols and the social aspect (organization). Nevertheless, Petri nets practitioners need to use a formal verification techniques that identifies and mitigates risks in their proposed models. On the other hand, Maude is also used directly for the development of MAS or indirectly as a formal unifying framework for a wide range of Petri nets. In addition, Maude offers some advanced analysis tools allowing the automatic verification of Petri nets based models properties. In particular, the Maude LTL model checker is a powerful tool that combines a very expressive and general-purpose system specification language with on-the-fly explicit-state model checking techniques, which is one of the most commonly used approaches to model checking. Moreover, Maude allows using another complementary technique, i.e., a reachability tool that can explicitly check the existence of critical states in the studied system from a pre-defined initial state and then offers a very quick verification time if the best initial state is used.
Therefore, even if the Petri net models are attentively prepared, Maude specification defects can be introduced during the manual preparation of such specification for Petri net based models of multi-agent system. These defects may be introduced by designers because of the large size and/or complexity of described behaviour of multi-agent systems. Consequently, the best solution to cater this problem is the automatic generation of Maude specifications from the Petri net models. In addition, automatic generation provide considerable saving of time and reproducible quality of the generated code.
Finally, we will focus on the presentation of a straightforward algorithm for the automatic translation from Petri nets based models to Maude specifications.
Preliminaries
Firstly, rewriting logic [44] is a formal specification language built upon the membership equational logic by adding “rewrite rules” to deal with change, dynamic and concurrency. In such logic, the rewrite theory
Secondly, Maude [23, 22] is a rewriting logic based language in which a system specification can be written in two modules. While functional modules are used to define the signature (basic elements) of the system such as, sorts, operations, terms and equations, system modules are very general rewrite theories that may have equations in addition to rewrite rules to define the dynamic part (behavior) of the system.
Thirdly, a Petri net consists of a set of places, transitions and a set of arcs connecting places with transitions. In fact, a Petri net is defined as a 5-tuple
Pre: Post:
According, a place (which may contain different number of tokens) with an arc starts from itself to a transition is an input place, and a place with an arc starts from a transition to itself is an output place. An arc has a weight “
A transition
The global state of a Petri net (marking), designs in fact the distribution of tokens over places. This distribution is defined via the function
Example of Petri net.
In the Fig. 1, P1, P2, P3 and P4 represent the set of places and T1, T2, T3 and T4 represent the set of transitions. All arcs in this Petri net have implicitly weights equal to “1” except the one connecting P1 with T2. In addition, the transition T1 is called source transition since it hasn’t any input place and the transition T4 is called sink transition because it hasn’t any output place. Moreover, the place P3 is at the same time an input and an output to the transition T4 which represent a self-loop. Therefore, the present Petri net is not a pure Petri net since it has a self-loop.
Finally, Petri nets have been well-studied in the context of rewriting logic and in order to facilitate their description in Maude, we give the following example (see Fig. 2) that describes the behavior of the famous dining philosophers problem. In such well-known problem, we consider four philosophers (simple agents) eating at the same round table, sharing four forks. For sake of simplicity, we consider that each philosopher agent alternates between thinking with eating states.
The corresponding Maude specification of such Petri net is given in Listing 1.
Maude specification modules of dining philosophers behaviour.
fmod PETRI_NET is mod DINING_PHILOSOPHERS is
sorts Place Marking . including PETRI_NET .
subsorts Place < Marking . rl [takes-forks0] : T0 F3 F0 => E0 .
op empty : -> Marking . rl [releases-forks0] : E0 => T0 F3 F0 .
op Initial : -> Marking . rl [takes-forks1] : T1 F0 F1 => E1 .
ops E0 T0 E1 T1 E2 T2 E3 T3 : -> State . rl [releases-forks1] : E1 => T1 F0 F1 .
ops F0 F1 F2 F3 : -> Fork . rl [takes-forks2] : T2 F1 F2 => E2 .
op __ : Marking Marking -> Marking rl [releases-forks2] : E2 => T2 F1 F2 .
[assoc comm id: empty] . rl [takes-forks3] : T3 F2 F3 => E3 .
eq Initial = F0 F1 F2 F3 T0 T1 T2 T3 . rl [releases-forks3] : E3 => T3 F2 F3 .
endfm endm
In this specification, the static part (components or signature) of the system is given in a functional module
Our algorithm is principally based on the translation mechanism proposed in [56] and its general description is illustrated in Fig. 3.
Petri net describing the dining philosophers behaviour.
Generating algorithm description.
The proposed algorithm is principally based on the use of the incidence matrix and modules templates for both functional and system modules.
Incidence matrix
The algebraic representation of a Petri net
Fill the pre-incidence matrix (PRE)
Petri Net : N places, M transitions
procedure Fill_PRE_Matrix(PRE : Matrix of N
M of integer)
Ouput : PRE Matrix of N
M of integer
for
do
for
do
if (an arc leads from place
to transition
) then
else
end
if
end
for
end
for
end
procedure
Fill the pre-incidence matrix (PRE)
Petri Net : N places, M transitions
Ouput : PRE Matrix of N
Similarly, we present the procedure Fill_POST_Matrix in Algorithm 2.
Fill the post-incidence matrix (POST)
Petri Net : N places, M transitions
Ouput : POST Matrix of N
As one can see in Listing 1, some parts are not changeable in both functional and system modules. Therefore, the use of a specification template file that contains the constant specification parts will be very useful. Such specification templates FTemplate (func_petrinet) and STemplate (system_petrinet) are given in Listing 2.
Maude specification templates for functional and system modules.
1. fmod FUNC_PETRINET is 1. mod SYSTEM_PETRINET is
2. sorts Place Marking . 2. including FUNC_PETRINET .
3. subsorts Place < Marking . 3. rl [Trans-Name] : lhs => rhs .
4. op empty : -> Marking . … Other Rules …
5. ops PLACES_NAMES : -> Place . 4. endm
6. op __ : Marking Marking -> Marking
[assoc comm id: empty] .
7. endfm
Maude specification templates for functional and system modules.
1. fmod FUNC_PETRINET is 1. mod SYSTEM_PETRINET is
2. sorts Place Marking . 2. including FUNC_PETRINET .
3. subsorts Place < Marking . 3. rl [Trans-Name] : lhs => rhs .
4. op empty : -> Marking . … Other Rules …
5. ops PLACES_NAMES : -> Place . 4. endm
6. op __ : Marking Marking -> Marking
[assoc comm id: empty] .
7. endfm
The proposed algorithm consists of two parts. The first one concerns the generation of the functional module, whereas the second concerns the generation of the system module. Such two modules are complementary to describe the whole system.
Specification modules creation
The following procedure (see Algorithm 3) describes the process of creation of the specification modules by using the templates files (Listing 2). In fact, this procedure will copy the template file in the specification module to be created.
Creation of specification files
Template file
procedure Create_specification_file(Specificationfilename : String, Templatefilename : String)
Ouput : Specification file : Maude file
copy “Template file” to “Specification file”
end
procedure
Creation of specification files
Template file
Ouput : Specification file : Maude file
In order to facilitate the generation process of the Maude specification, we assume that places are labeled as: P1, P2, … P
The first procedure extracts the number of places from the incidence matrix IM in order to generate the corresponding specification line in a string variable “placenames” which will be inserted in the appropriate place in the functional module as given in Algorithm 4.
Generation of the place names for the functional module
N: rows number of IM Matrix
procedure Place_Names(placenames: String)
Ouput : placenames : String
this will replace line 5 in functional module template
placenames
“ops”
“ ”
for
do
placenames
placenames
“P”
Asstring(i)
“ ”
Asstring(i): converts
into string
end
for
placenames
placenames
“:
Place .”
end
procedure
Generation of the place names for the functional module
N: rows number of IM Matrix
Ouput : placenames : String
The following function Is_Source (resp, Is_Sink) is an intermediate function that determines the source (resp, sink) transitions in the Petri net and it is given in Algorithm 5 (resp, Algorithm 6). In fact, such two functions are necessary since their corresponding rewrite rules will be prepared with special treatment.
Similarly, the next function Is_Sink is given as follow.
The second procedure generates a new rewrite rule for each transition in the incidence matrix IM then save result in a string variable “RewriteRule”. These strings will be inserted in the system module. This procedure is illustrated in Algorithm 7.
Verification of source transitions
PRE Matrix
Ouput : result : boolean
Is_Source
Verification of sink transitions
POST Matrix
Ouput : result : boolean
Is_Sink
Generation of the corresponding rewrite rule for a transition
Matrix IM (PRE and POST matrices)
Ouput : RewriteRule : String
In order to write placenames and RewriteRule in the specification files, we need another procedure (see Algorithm 8) for which we need the specification file name and the line number where we have to write the strings placenames or RewriteRule.
Insertion of generated code in the specification file
Specification file
The full proposed algorithm for the automatic generation of Maude specifications from Petri nets is given in Algorithm 9 as follows.
Automatic generation of Maude specification
Petri Net : N places, M transitions
: Functional template file
: System template file
Specification Files : Functional module, System Module
Begin
: integer
0
M : is equal 0 when there is (are) not sink or source transition(s)
Sink_or_Source : boolean
Sink_or_Source
False
Fill_PRE_Matrix(PRE)
Fill_POST_Matrix(POST)
Create_specification_file(functional_module, FTemplate)
Place_Names(placenames)
Insert(functional_module, placenames, 5)
Create_specification_file(system_module, STemplate)
j
1
while
not(Sink_or_Source) do
Test the existence of source or sink transitions
if (Is_Sink(j) or (Is_Source(j)) then
Sink_or_Source
True
end
if
j
j + 1
end
while
if (Sink_or_Source) then
Insert(system_module, “op M :-
Marking .”, 3
S)
Add the variable M declaration to the specification
Incrementing S to insert the next rule in the following line
end
if
for
do
Rewrite_Rule(j, RewriteRule)
Insert(system_module, RewriteRule, 3
S)
Incrementing S to insert the next rule in the following line
end
for
End
Automatic generation of Maude specification
Petri Net : N places, M transitions
Specification Files : Functional module, System Module
Begin
Sink_or_Source : boolean
Sink_or_Source
Fill_PRE_Matrix(PRE)
Fill_POST_Matrix(POST)
Create_specification_file(functional_module, FTemplate)
Place_Names(placenames)
Insert(functional_module, placenames, 5)
Create_specification_file(system_module, STemplate)
Sink_or_Source
Insert(system_module, “op M :-
Rewrite_Rule(j, RewriteRule)
Insert(system_module, RewriteRule, 3
End
In order to test the correctness of the proposed algorithm, we have implemented a prototype1 of such algorithm by using the Delphi programming language, as we have used the same Petri net (Fig. 2) as entry to ensure the correctness of the automatic generation of Maude specification process.
To do so, we have followed the propositions cited in Subsection 4.2 to rename places and transitions. The resulted equivalent Petri Net is given in Fig. 4.
On the other hand, by using the procedure fill_matrix, the corresponding incidence matrix of such Petri net is given in the following Table 1.
Incidence matrices
Incidence matrices
Equivalent Petri net describing the dining philosophers behaviour.
After executing the prototype implementing our algorithm, we have exactly obtained the following specification modules.
The generated specification modules.
fmod FUNC_PETRINET is mod SYSTEM_PETRINET is
sorts Place Marking . including FUNC_PETRINET .
subsorts Place < Marking . rl [ T1] : P1 P9 P12 => P2 .
op empty : -> Marking . rl [ T2] : P2 => P1 P9 P12 .
ops P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 rl [ T3] : P3 P9 P10 => P4 .
P12 : -> Place . rl [ T4] : P4 => P3 P9 P10 .
op __ : Marking Marking -> Marking [assoc rl [ T5] : P5 P10 P11 => P6 .
comm id: empty] . rl [ T6] : P6 => P5 P10 P11 .
endfm rl [ T7] : P7 P11 P12 => P8 .
rl [ T8] : P8 => P7 P11 P12 .
endm
In order to confirm the syntax correctness of the generated specification, we have compiled the specification files with Maude system by using the Maude command “load” and everything is gone ok and Maude compiler gave us a positive result.
Let’s now analyze the time complexity of the proposed algorithm. This complexity will be given as a function of the size of an incidence matrix
where
So, the time of the matrix filling process is a linear function of the number of elements in the matrix
As to the time of the generation of the functional template file, this process need a linear time of the number of places, that is
The generation of system template file is done in lines 22–26 of Algorithm 9 in Listing 3. This process generate a rule of each transition
The total cost is therefore
Related works
Quite number of works and tools have been proposed and realized for automatic code generation from Petri nets into many other languages such as to C [27], C++ [25], Java [28, 62], VHDL [26] and PROMELA [54]. However, we cannot compare our work with the most of them because the description languages are radically different and then, we will discuss only those related to the Maude language.
Although, the formal specification of Petri nets based on rewriting logic dates to a couple of decades ago [56], only a little number of works for the automatic generation have been published. For instance, the first rewriting logic based tool is the one presented in [10] for editing, simulating, and analyzing Extended Concurrent Algebraic Terms Nets (ECATNets) via a quasi-complete collection of formal analysis tools. The second one is the approach presented in [34] that combines meta-modeling and graph grammars to automatically generate the Maude specification in order to simulate and analyse ECATNets Models by means A Tool for Multi-formalism and Meta-Modelling (ATOM3). In that work, a Unified Modeling Language (UML) class diagram is used to define a meta-model of ECATNets. Then, a graph grammar is proposed to generate the Maude specification of the specified ECATNets models to perform the simulation.
Finally, to the best to our knowledge, perhaps the most closely related effort to our present work is that presented in [11], where authors have proposed a graphical tool allowing bidirectional translation from colored Petri Nets to Maude and vice versa. At the same time, we should note that all the pre-cited works present their tools as black box, and none of them neither presents a straightforward algorithm to generate the Maude specification nor makes available of such tool. In addition, still the major advantage and thus, contribution of our work is that it is fully automatic and based on a well-defined algorithm.
Conclusion and future work
In this paper, we have presented a well-defined algorithm for the automatic generation of Maude specifications from Petri net models representing multi-agent based systems architecture. This algorithm (prototype) will be helpful for all Petri nets practitioners and designers building large models and even who don’t have too much experience with rewriting logic. It will permit them to save time, avoid human related errors during the usually manual translation process as it will give them the opportunity to exploit all Maude advanced analysis tools for their models. Our future work is to create a complete tool or an Eclipse plug-in implementing this algorithm and providing a convenient GUI (Graphical User Interface) interface for end users to edit the Petri net and then generate the incidence matrix and the Maude specification from the Petri net model. In addition, we also aim to generalize the proposed algorithm for other Petri net categories by using the appropriate data structures.
Footnotes
Available at:
Acknowledgments
This work is financially supported by a grant No: 034/PNE/ENS/Spain/13-14 from the Algerian ministry of higher education and scientific research. In addition, our special thanks goes to my friend BENALI Abdel kamel for his help and guidance in preparing the algorithm time complexity subsection.
Author’s Bios
