You are on page 1of 7

2019 19th International Conference on Computational Science and Its Applications (ICCSA)

Pattern Based Model Reuse Using Colored Petri Nets


Syed Hassan Askari Muhammad Haris
Department of Software Engineering Department of Computer Science & IT
University of Lahore, Pakistan University of Lahore, Pakistan
syed.hassan@se.uol.edu.pk muhammad.haris3@cs.uol.edu.pk
Shahrukh Ali Khan Muhammad Shoaib
Department of Software Engineering Department of Software Engineering
University of Lahore, Pakistan University of Lahore, Pakistan
shahrukh.ali@se.uo.edu.pk muhammad.shoaib1@se.uol.edu.pk

Abstract— Colored Petri Net (CPN) is a graphical modeling


language for simulation and modeling and for verification of
discrete event systems. CPN allows developers to define a model in experience reoccurrence of the same problem repeatedly. Hence,
the form of reusable components. A model component is an a sound understanding of certain problems gives developers a
independent element, which is specified using a formalized wide choice to pick the best possible solution by looking up in
description, can conform to a certain component standard, has a pattern catalog. This consumes less effort and time in
well-defined interface, and encapsulates certain behavior. Modern development while providing novel solutions.
components can help the developer reuse existing models according
“Composability” is the ability to select and merge various
to their requirement as it reduces the cost and time of development.
Composability is the capability to select and integrate various components in order to satisfy the user requirements [3].
components to fulfill user requirements. Composability provides “Reuse” is when existing component are utilized for different
the means to achieve reusability where “reuse” is the ability of a applications [4] [5].
simulation component to be reclaimed for various applications. We We propose reusability patterns, verify their relationship
propose a verification framework for developers to select and between patterns and enable easy navigation using CPN pattern
assemble CPN-based components and verify their composability. language. The goal is to make a pattern, so that developers can
The goal of this paper is to provide a pattern which helps developer search a pattern which is related to problem in a solution catalog
in making models of concurrent systems. We present a case study using these patterns. Therefore, developers will not need to
of a restaurant model as proof of concept. A verified composition develop a model from the scratch to satisfy their user
affirms reuse of model components in a meaningful manner by requirements.
satisfying given requirement specifications.

Keywords— Patterns, Pattern Reuse, Colored Petri nets,


II. BACKGROUND
Composability Verification In the following section, we will discuss some basic understood
notions about pattern, composability and verification.
I. INTRODUCTION A. Pattern
When building up a model of a concurrent system and A pattern is defined in terms of a recurring problem in
verification of its properties, the graphical language being used certain domain providing the generalized solution for that
is known as “Colored Petri Nets” [1]. CPN models are problem [2]. The idea of pattern was introduced by C. Alexander
executable and are used to model and specify the behavior of [6]. Gamma explained that there are four important elements for
parallel systems. These models are both state and action pattern i.e.: name of the pattern, the problem, solution for the
oriented. Moreover, the CPN tool is used to provide a design problem and explanation of the consequences [7]. A pattern
pattern that simulates the proposed solution. It’s applicable in provides solutions to the developer in making their model, while
various domains not only in work flow modeling but also in the avoiding redundant solutions to the problems. Patterns depend
design of complex concurrent computer systems. on experience, as they provide a sound solution to the problem
A pattern is specifically a recurring problem in a domain where that are continuously occurring in a certain domain. Developers
a generalized solution is required for that problem [2]. Basically, who are working in similar domains would experience
a pattern provides the solution to the developer in making their occurrence of same problem repeatedly. A sound understanding
model, while avoiding redundant solutions for the problems. of a certain problem gives modeler a wide choice for picking the
Patterns depend on experience, as they provide a sound solution best possible solution by looking up in pattern catalogue. This
for problems which are continuously occurring in a certain consumes less effort and time in development while providing
domain. Usually developers working in similar domain novel solution.

978-1-7281-2847-4/19/$31.00 ©2019 IEEE 32


DOI 10.1109/ICCSA.2019.000-7
B. Pattern reuse create analysis reports which play an important role in the
Pattern reuse promises effective development of systems as verification process.
it can reduce the development cost and time. When reusing
patterns, we need composability [8]. Hence, we are aiming to 1) Hierarchical CPN
provide a composability of patterns in order to achieve a CPN consists of different modules and the modules can be
sophisticated model. considered as black boxes which perform all the processing on
abstract level by concentrating on one module at a time. An
C. Composability
entire CPN model can be replaced by a transition that can be
Composability is the ability to select and merge various connected to the main model to make hierarchical CPN models
components in order to satisfy user requirements [3] [9]. We
using CPN tools. The entire model then can be broken down into
propose reusability of patterns and verify their relationship
between patterns and enable easy navigation using CPN pattern different smaller modules and can be used to help in modular
language. Verification is required to achieve successful development [1] [12]. CPN hierarchical features are used in our
composability [10] [19]. CPN component model.
D. Colored Petri Nets E. Verification
Verification is defined as a process that can check model
CPN is a mathematical modeling language for simulation and implementation accurately [15] and according to the
modeling, as well as for the verification of discrete event specifications [16]. We use verification technique named “state
system. Essentially, it is a powerful language which can be used space analysis” to check the system properties and verify if
to display parallel or concurrent activities in a system [1] [11]. models fulfil the requirements [17] [18].
By using a CPN tool [12], a model is created for analyzing
system performance. CPNs are a buildup and well-researched
III. CASE STUDY: FAST FOOD RESTAURANT
means for system modeling and simulation [13]. A CPN is a
MODEL
bipartite diagram in which we have places, transition and arc.
A case study of restaurant model is presented in this section
Arc runs from transition to place and vice versa, but never
to explain our approach “Pattern Based Model Reusability”.
between transition and between places. This case study explains a scenario; in which different patterns
can be combined using Composability. Pattern can be defined as
CPN = (P, T, A, Ȉ, V, C, G, E, I) a problem that keeps occurring in a defined sequence. Consider
Where: this, our model provides a generalized solution for reoccurring
problem. Following is a pattern that can be used in this case
P is a finite set of places
study.
T is a finite set of transitions such that: P ∩ T = ∅
Arrival: Figure 1 illustrates a unique ID is assigned to each
A ‫ ك‬P×T ‫ ׫‬T×P is a set of directed arcs.
arriving customer. Exponential time function has used with a
Ȉ is a finite set of non-empty color sets. mean equal to 9.
V is a finite set of typed variables such that: Type[v] ‫ א‬Ȉ for all
variables v ‫ א‬V
C: PĺȈ is a color set function that assigns a color set to each
place.
G: T ĺ Expression is a guard function that assigns a guard to
each transition t
E: Aĺ Expression is an arc expression function that assigns an
arc expression to each arc a
I: P ĺ Expression is an initialization function that assigns an
initialization expression to each place p

A comprehensive description of colored petri nets is outside the


scope of this paper, so interested readers are suggested to see [1]
[12] [13]. CPN is a well-known tool for the development of
models, their verification using state-space analysis and analysis Figure 1: Arrival Pattern
of CPN models [12]. They provide an integrated development
environment (IDE) for the development of CPN models. For Split: Figure 2 illustrates splitting of the customer and assigns
efficiently executing timed and untimed nets, it has a bundled different queues to them. Discrete function has used to divide
simulator. State-space analysis is the most important feature of customers randomly to different outputs.
CPN tools. It consists of different query functions and helps to

33
Payment Service: Figure 6 illustrates that provides a service to
the customers in which a resource which receives the payment
from a customer and forwards his order.

Figure 2: Split Pattern

Queue: Figure 3 illustrates that FIFO queue pattern is used to


entertain the customer. A customer arriving first will always be
served first.
Figure 6: Payment Service pattern

FoodReady Queue: Figure 7 illustrates FIFO Queue pattern is


used in which a food that is prepared first is served first, and
also includes a waiting time that is required in preparing and
processing the food.
Figure 3: Queue Pattern
Resource: Figure 4 illustrates that it includes moving resources
that can move on their own like in our example it represent staff
e.g. waiter. We are using a resource “Waiter” that can be
generated by a resource pattern which determines the order in
which he takes order from the customer.
Figure 7: FoodReady Queue Pattern

Service: Figure 8 illustrates that this pattern uses a resource to


provide a service to the customer. When a food is ready it is
served to the customer. The duration required to actually serve
the prepared food to the customer is included in this pattern. The
function norm Time is used to generate a random number from a
Gaussian distribution.

Figure 4: Resource Pattern


Order Service: Figure5 illustrates that in this pattern a resource
can be added that actually provides services to the customer and
also adding a waiting time that tells us how much time is
required to entertain a customer.

Figure 8: Service Pattern

Sink: Figure 9 is usually the end point in a process model in


which after receiving their food all customers leave the
restaurant.

Figure 5: Order Service Pattern

34
1. Component Integration

Using this approach, we can integrate different patterns to check


their correctness whether they are connected according to their
requirements or not. In order to verify component integration,
we use the Breath First Search (BFS) algorithm. Using this
algorithm, we can verify that different components are
connected correctly. We use function that performs the graph
traversal in a BFS manner. In order to check the verification of
Figure 9: Sink Pattern the model by using the following conditions on the graph for the
Figure 10 illustrates that different patterns are used to build a verification of the model graph nodes with each other
restaurant model. Through Composability, we combine different individually and reading the meta information about the nodes in
components and develop a fast food restaurant model where a order to use these conditions;
unique id is assigned to customers as they arrive in the • First of all, we check the source pattern and destination
restaurant. After that, they randomly split into one of the queues. pattern in the meta file that are available or not. For
In a queue, they have to wait for the order to be placed. When a every provider, there is require and for every require,
customer arrives to the counter, a resource is needed to take the there is a provider i.e. we must check for the unused
order from the customer and after placing the order, customers nodes if any dead links exist.
pays the bill and waits for the food. After receiving their food
• Number of parameters and ColorSet of the input and
customer leaves the restaurant.
We propose a reusability of patterns, verifying output nodes should be the same i.e. in order to
relationships between patterns and easy navigation using CPN communicate between the nodes, the medium should be
pattern language. We also need verification in order to achieve same.
successful Composability. We used a verification technique • Check the links status from the above conditions; if
named as “state space analysis”. Using CPN state space satisfied then nodes are connected in correct manner
calculation tools we generate the state space of the entire model.
i.e. nodes are connected using require and provider and
When state space is generated, different query function can be
used in order to answer the various verification questions. their data types also match with each other and are
The following properties are considered as requirement compatible.
specification: If none of the above are satisfied, then nodes are not
connected in correct manner, either it has dead links, useless
1. Component Integration providers, requires the data type, or ColorSet is not same for
2. Deadlock Freedom communication.
3. Mismatching

The steps of verifying a composed model are as follows:

Figure 10: Restaurant Model

35
or not. If it is true, then it will be checked that for every provider
Algorithm: Verify component Integration property there is acquire and vice versa.
Input: {Actions}, Patterns Second rule is that for communication, the medium should
Output: TRUE, FALSE be the same i.e. their number of parameters and colset both must
be the same.
1 BFS(v){ Third rule is used to check that marked node is visited and
2 {add v to queue and mark it} components are connected according to their rules as discussed
3 Add(Q, v) above.
4 Markvas visited
5 while (not IsEmpty(Q)) do
6 begin
7 w = QueueFront(Q)
8 Remove(Q)
9 {loop invariant: there is a path from vertex w to every vertex
in the queue Q}
10 for each unvisited vertex u adjacent to w do
11 begin
12 Mark u as visited
13 Add (Q , u)
14 src = w
15 dest = u
16 if srcPattren or destPattren not found
17 exit using pattern not found error
18 for each provider p in srcPattren
19 begin
20 Rule1:
21 r = destPattren requires
22 if p not in r and r not in p {not usage of provider in
requires and vice versa} Figure 11: Restaurant Model Graph
23 exit using condition 1 not met error
24 Rule2: Scenario B (Counter Example)
25 pType = dataType in provider p In this scenario, we change the behavior of the waiter in which
26 dType = dataType in require r he takes the order from the customers. After the food is ready,
27 pColSet = color set in provider p waiter serves the food to the customers and the customer request
28 dColSet = color set in require r for bill and goes to waiting state and leaves the restaurant
29 if pType is not equal to dType and pColSet is not equal to without payment.
dColSet The red line shown in the graph represents the customer leaving
the restaurant without payment. We verify the behavior of model
30 exit using condition 2 not met error to check if it is working correctly. In order to verify the model,
31 Rule3: we apply the BSF algorithm.
32 mark src, dest as linked{components are linked as they Using this algorithm we check the components are connected
have met all the required conditions} correctly.
33 exit using success code
34 end {for}
35 if exit code is not success
36 mark src, dest as not linked{components are not linked as
they have not met all the required conditions}
37 end { for }
38 end{ while}

Scenario A
Using Graph Stream Library, we build restaurant model
graph. Orange nodes represent that node are visited and green
arrow shows that components are correctly connected according
to their rules that are defined in algorithm.
According to the first rule, it must be checked whether the
source pattern and destination pattern are present in the meta file
Figure 12: Restaurant Model Graph (Counter Example)

36
2. Deadlock Freedom CPNs and its techniques are very beneficial as it is one of the
competitive tools for development of models for systems. CPN’s
A built in function ListDeadMarkings () is executed after the role in Composability verification is very constructive, because
creation of state-space which, after searching the whole state- it also focuses on dynamic Composability level.
space, provides a list of all dead markings. Empty set means that
there are no deadlocks in model. CPN communities have been working on the analysis techniques
to improve the performance of CPN tools and their work
3. Mismatching: provides a notable and efficient reasoning when working on the
model correctness.
Services promote business so they are assumed as good state. An In future, we aim to build a complex system in different
example of bad state may be going out of restaurant without application areas e.g business critical systems or mission critical
paying the bill because it causes loss to the restaurant. The systems using pattern based approach and also checking the
correct sequence of events to reach the good state “service” is correctness of system through verification techniques.
given below:
V. REFRENCES

Customer! OrderFood ĺ Waiter! TakingOrder ĺ [1] K. Jensen and L. M. Kristensen, "Coloured Petri Nets Modelling and .
WaitingForFood! FoodReady ĺ Waiter! ServeFood ĺ . Validation of Concurrent Systems," Springer-Verlag Berlin Heidelberg, . .
2009.
Customer! Bill ĺ Waiter! ReceivedPayment
[2] N. M. and W. M. v. d. Aalst, "Towards a Pattern Language for Colored .
When the monitor notices the sequence, it will activate “Leave Petri Nets," sixth workshop and tutorial on practical use Coloured Petri . .
Without Payment” event because after the event “Waiter Serves Nets and the CPN Tools., 2005.
Food” is done, the next event is “The Customer Requesting Bill” [3] I. Mahmood, R. Ayani, V. Vlassov, and F. Moradi, " Verifying Dynamic .
but due to no payment it goes into the waiting state. The Semantic Composability of BOM-Based ComposedModels Using Colored .
composed restaurant model can be considered verified in terms Petri Nets", ACM/IEEE/SCS 26th Workshop on Principles of Advanced . .
of requirements and behavior of the system if the good states are and Distributed Simulation, 2012.
reached more than zero times and the system never reaches to a
[4] Lemos, A. J. P., P. and A. , "Reuse of coloured petri nets software
bad state. ……models.," In: Proc. of The Eighth International Conference on Software
……Engineering and Knowledge Engineering,SEKE’01, Buenos Aires,
The behavior of the waiter is changed in this scenario, i.e. he ……Argentina, p. 145–152, 2001.
takes the order and instantly he calculates the customer’s bill
[5] L. D. d. Silva, K. G. and A. P., "Petri Nets for Component-Based ……
and provides it to him so that the customer can make the ……. Software Systems Development," I-Tech Education and Publishing, ……
payment. Meanwhile, the waiter waits for the payment Vienna, Austria, February 2008.
Figure 10. Once the bill is paid by the customer, the order is
conveyed to the kitchen by the waiter. [6] C. Alexander, "Timeless Way of Building", Oxford University Press, …..
1979.
Customer! OrderFood ĺ Waiter! TakingOrder ĺ [7] E. Gamma, R. Helm, R. Johnson and J. Vlissides, "Design Patterns, ……
Customer! Bill ĺ Waiter! ReceivedPayment Elements of Reusable Object-Oriented Software" Addison-Wesley, …… 1995.
WaitingForFood! FoodReady ĺ Waiter! ServeFood ĺ
[8] K. C. Gorgonio and A. Perkusich , "Adaptation of Coloured Petri Nets …..
Models of Software Artifacts for Reuse," Springer-Verlag Berlin …..
As all the events are same but the order is different, this system …….Heidelberg, 2002.
modification passes structural analysis.
[9] M. D. Petty and E. W. Weisel, "A theory of simulation composability", ….
Old Dominion University, Norfolk, Virginia,, 2004..
IV. SUMMARY AND CONCLUSION:
[10] I. Mahmood, "A Verification Framework for Component Based
In this paper, we proposed the reusability of pattern. We built …….Modeling and Simulation "Putting the pieces together", Doctoral thesis
a pattern and reused them to build complex models according to …….in Electronics and Computer Systems, Sweden, 2013.
the given requirement. The modeler doesn’t need to build a
[11] Wil M. P. van der Aalst, C. Stahl, M. Westergaard, “Strategies for
component from the scratch. Using CPN hierarchical features …….Modeling Complex Processes Using Colored Petri Nets”, Springer,
we developed the component. Through composability, we …….Berlin, Heidelberg, 2013.
combined different components and made a model. In order to
[12] 2017. CPN Tools. Accessed December 2017. http://cpntools.org/.
achieve successful composability, we needed verification.
[13] M. N. and J. W. Janneck, "Design patterns in petri net system modeling",
We used the BFS algorithm to check the components are …… Proceedings.," Fourth IEEE International Conference on Engineering of
correctly connected as per requirement specifications. We …. Complex Computer Systems (Cat. No.98EX193), 1998.
verified different properties in our restaurant model including
component integration, deadlock freedom and miss matching. In [14] L. M. Kristensen, "State Space Methods for Coloured Petri Nets,",
……Department of Computer Science, University of Aarhus, Aarhus,
order to ensure that our model works correctly, we verified these ……Denmark, Ph.D. Dissertation, 2000.
properties. For efficient and accurate verification of models,

37
[15] O. Balci, "Verification, Validation and Accreditation of simulation
…….models", in Proceedings of the Winter Simulation Conference, Atlanta,
…….GA, 1997.

[16] M. D. Petty, "Verification and Validation", in Principles of Modeling and


……Simulation: John Wiley & Sons,, p. ch. 6., 2009,.

[17] K. Jensen and L. M. Kristensen, ”Colored Petri Nets: A Graphical


…….Language for Formal Modeling and Validation of Concurrent Systems”,
…….Communications of the ACM, Vol. 58 No. 6, pp. 61-70, June, 2015.

[18] I. Mahmood, R. Ayani, V. Vlassov and F. Moradi, "Composability


……Verification of Real Time System Models using Colored Petri Nets,"
……UKSim 15th International Conference on Computer Modelling and
……Simulation, 2013.

[19] O. Balci, J. D. Arthur and W. F. Ormsby, "Achieving reusability and


……composability with a simulation conceptual model," Journal of
……simulation, pp. 157-165, 2011.

38

You might also like