2. Petri nets in science

requires k tokens on p3. That is, it requires that no reading operation is currently in execution. Correspondingly, when a writing operation is in execution, no read operation is allowed. This is represented by k weighted arc of t1. Thus, when writing operation is in execution, by the firing of t1, the k tokens in p<sup>3</sup> are removed. Once the reading operation is done, the firing of t<sup>2</sup> returns k tokens to p3. The Petri net model allows any of the 2k processes to read and to write to the shared place p<sup>3</sup> by connecting the place p<sup>2</sup> to the reading or writing sections of the net.

Figure 4. A Petri net model that represents the typical problem of readers and writers. The model allows up to 2k

concurrently in a reading operation. On the other hand, the writing process requires k tokens to be on the shared place p3. That is, no reading operation must be executed by any of the 2k readers in p<sup>2</sup> to allow the writing operation. Thus, the writing operation must wait until all the reading operations have finished. Similarly, when a writing operation is in

Other attractive attribute of the Petri nets is their solid mathematical basis. The incidence matrix that represents the structure of the net in Figure 4 is represented by Eq. (1). The incidence matrix is independent of the initial condition of the net. This structure could be analyzed by methods from the matrix theory, linear algebra, or vector spaces, for example.

> 1 �10 0 �1 1 �1 1 �k k �k k 001 �1

The state equation of a Petri net allows a formal definition of its dynamics. The next state of a Petri net can be computed from the current state, and a multiplication of the matrix that represents the structure of the net and a vector that represents the transitions that can fire, as follows:

Mkþ<sup>1</sup> ¼ Mk þ Buk

Parikh vector, in a clear relationship to the Parikh's theorem. This theorem relates the strings in a context-free language and the number of the occurrences of the symbols in these strings.

! represents one or more transitions that are allowed to fire. It is known as the

! (2)

� �. However, only k of them can be

(1)

� � that can read or write to and from shared memory resources <sup>p</sup><sup>3</sup>

execution, no reading operation is allowed, since p<sup>3</sup> is empty.

The vector uk

processes p<sup>2</sup>

4 Petri Nets in Science and Engineering

As mentioned, the Petri nets are a very versatile tool that turns it useful in science, as well as in engineering. In the science field, a wide developed aspect is related to the study of Petri nets as a system and their associated abstract properties.

For example, the study of properties of the Petri net models in terms of vectors and matrices is complemented with the linguistic study in terms of strings and formal languages. The welldeveloped theory of matrices, linear algebra, and vector spaces are well suited to the analysis of properties in the net models, providing efficient solutions. However, other studies such as the reachability analysis, requires the partial expansion of the state space of the models, which turns the investigation in an inverse direction, from a vector space to string over a language. Though, the advantages of the study of the Petri net properties in terms of vectors, matrices, and linear algebra in general are considerable, and many of the theory developed for Petri nets relies on them.

Indeed, by restricting the marking of a Petri net to be non-negative, the state space entirely lies in the positive cone of Z+ . Thus, some of the theory of positive linear systems could be applied [7]. Figure 5(a) depicts the state space, in R<sup>3</sup> , of the Petri net model in (b) for two different initial conditions M<sup>0</sup> ¼ ½ � 100 and M<sup>0</sup> ¼ ½ � 200 , the two hyperplanes are orthogonal to the unitary vector u ¼ ½ � 111 . Moreover, if the net is conservative (i.e., the number of tokens over all its places remains constant for any evolution trajectory), then it is easy to show that the entire state space of the Petri net lives in one of the hyperplanes orthogonal to a vector in R<sup>n</sup>, where n is the number of places of the net.

One of the most active areas of the applications of the Petri nets in science is in the field of the modern control theory. The study of control techniques for discrete event system, including Petri net models, covers the range of applications from design of discrete event controller, design of state observers, analysis of fault tolerant systems, analysis of Lyapunov-like stability, detectability analysis, isolation, and failure recovery techniques, among others [4–6].

In this context, considering a Petri net as an input-output system, as in classical control theory, is useful. Figure 6 depicts the state equation of a Petri net given by a block diagram. The input vector uk ! is operated by the matrix B to produce a marking increment that is added to the current marking. The sum of these two quantities becomes the new marking reached by the current evolution of the net. A unit delay block allows the new marking becoming the current marking for the next evolution of the net.

Considering the state equation of a Petri net as a block diagram as in Figure 6 allows studying the dynamics of the model as in the control theory [4]. Techniques for the construction of feedback controller or state observers could be addressed [6]. Performance analysis is as well, a usual analysis stage in the design of the class of systems that could be modeled by a Petri net [5].

Figure 7 depicts a block diagram of a classical control scheme for a DES modeled as a Petri net. The scheme considers two models, one of the system and the other of a reference. The controller receives the difference of the output of the system and the reference in order to compute the control actions. The objective of the control scheme is to achieve zero error, by the actions that the controller can exert over the system. If the system to be controlled is a software,

for example, either distributed or monolithic, then the reference is a specification or recipe that the software must meet. Then, the controller is another software responsible for computing the required parameters and configurations in order to adapt the main software system to the required behavior in an autonomous fashion. There is a huge trend in cloud computing and artificial intelligence to transform current software systems, such as database clusters, into autonomous intelligent systems that automatically adapts to user requirements and that are

Figure 7. A control scheme for Petri nets. The system is modeled as a Petri net model. The required behavior for the system is modeled as other net model called reference. The objective of the controller is to achieve zero error in the difference of the outputs of the system and reference. If the system is a database software, for example, then the reference is a specification that the database manager requires in the database. The controller is another software that

Figure 6. The state equation of a Petri nets as a block diagram. The input vector uk is multiplied by the matrix B to produce an increment of marking ΔMk. This increment is added to the current marking Mk to produce the new marking

Introductory Chapter: Petri Nets in Science and Engineering

http://dx.doi.org/10.5772/intechopen.79309

7

Mkþ1. This new marking becomes the current marking for the next evolution of the net.

The next section reviews some illustrative use of Petri net models in engineering applications.

The usability of the Petri nets in engineering applications is as well widely accepted. The stages of the design, the implementation, and the validation of systems are suitable addressed with

even able to predict future workloads and adapt to them [11, 12].

3. Petri nets in engineering

makes the overall scheme autonomous.

Figure 5. A Petri net model and its respective state space shown as a hyperplane. The solid arrows show the flow of the marking by the firing of the corresponding transition. Dashed arrows represent the marking change by the firing of a single transition. Increasing the number of tokens in the initial marking represents an orthogonal movement of the hyperplane away of the origin. The figure illustrates two hyperplanes. The lower one represents the initial marking with one token at p1, while the upper one represents the initial marking with two tokens as p1.

Introductory Chapter: Petri Nets in Science and Engineering http://dx.doi.org/10.5772/intechopen.79309 7

Figure 6. The state equation of a Petri nets as a block diagram. The input vector uk is multiplied by the matrix B to produce an increment of marking ΔMk. This increment is added to the current marking Mk to produce the new marking Mkþ1. This new marking becomes the current marking for the next evolution of the net.

Figure 7. A control scheme for Petri nets. The system is modeled as a Petri net model. The required behavior for the system is modeled as other net model called reference. The objective of the controller is to achieve zero error in the difference of the outputs of the system and reference. If the system is a database software, for example, then the reference is a specification that the database manager requires in the database. The controller is another software that makes the overall scheme autonomous.

for example, either distributed or monolithic, then the reference is a specification or recipe that the software must meet. Then, the controller is another software responsible for computing the required parameters and configurations in order to adapt the main software system to the required behavior in an autonomous fashion. There is a huge trend in cloud computing and artificial intelligence to transform current software systems, such as database clusters, into autonomous intelligent systems that automatically adapts to user requirements and that are even able to predict future workloads and adapt to them [11, 12].

The next section reviews some illustrative use of Petri net models in engineering applications.

#### 3. Petri nets in engineering

One of the most active areas of the applications of the Petri nets in science is in the field of the modern control theory. The study of control techniques for discrete event system, including Petri net models, covers the range of applications from design of discrete event controller, design of state observers, analysis of fault tolerant systems, analysis of Lyapunov-like stability,

In this context, considering a Petri net as an input-output system, as in classical control theory, is useful. Figure 6 depicts the state equation of a Petri net given by a block diagram. The input

current marking. The sum of these two quantities becomes the new marking reached by the current evolution of the net. A unit delay block allows the new marking becoming the current

Considering the state equation of a Petri net as a block diagram as in Figure 6 allows studying the dynamics of the model as in the control theory [4]. Techniques for the construction of feedback controller or state observers could be addressed [6]. Performance analysis is as well, a usual analysis stage in the design of the class of systems that could be modeled by a Petri net [5]. Figure 7 depicts a block diagram of a classical control scheme for a DES modeled as a Petri net. The scheme considers two models, one of the system and the other of a reference. The controller receives the difference of the output of the system and the reference in order to compute the control actions. The objective of the control scheme is to achieve zero error, by the actions that the controller can exert over the system. If the system to be controlled is a software,

Figure 5. A Petri net model and its respective state space shown as a hyperplane. The solid arrows show the flow of the marking by the firing of the corresponding transition. Dashed arrows represent the marking change by the firing of a single transition. Increasing the number of tokens in the initial marking represents an orthogonal movement of the hyperplane away of the origin. The figure illustrates two hyperplanes. The lower one represents the initial marking with

one token at p1, while the upper one represents the initial marking with two tokens as p1.

! is operated by the matrix B to produce a marking increment that is added to the

detectability analysis, isolation, and failure recovery techniques, among others [4–6].

vector uk

6 Petri Nets in Science and Engineering

marking for the next evolution of the net.

The usability of the Petri nets in engineering applications is as well widely accepted. The stages of the design, the implementation, and the validation of systems are suitable addressed with Petri net models. The covered applications include communication protocols, distributed systems, distributed database, concurrent and parallel programming and systems, industrial control systems, multicore processor platforms, dataflow-computer systems design, workflows and process-driven systems, fault-tolerant systems, and to mention a few. Properties practical interest such as fairness in the execution of tasks, deadlock avoidance, state reachability, process interlocking, among others, are possible to be analyzed within the Petri net framework.

For example, Figure 8 illustrates a very simple and conceptual communication protocol. The communication act is analyzed from the sending process point of view. A sender process sends a message by the output buffer and blocks its activity while waiting for an acknowledgement by the input buffer. A receiver process is blocked while waiting for an input message. Once a message has arrived, the receiving process reads the message and sends an acknowledgment by the input buffer. After the communication act has finished, the process restarts its logic to be ready for the next communication. This model could be extended to include faulty communication channels, which may lose the messages, acknowledge expiration periods, or other characteristics of practical interest. The analysis and design of communications protocols has been widely addressed with the use of Petri net models [9, 10].

There are some extensions to the Petri nets to handle specific aspects of different engineering problems. Some of the extensions add structure and information to the tokens, transitions, and places of a net. These extensions allow the construction of models that are quite compact

compared to the models obtained with the traditional approach. These models are called

simulation of this model allows us to study the performance of different scheduling policies.

Figure 9. A colored Petri net model of a task scheduling problem. The structure of the net represents the different stages of the processes in a multitasking environment. The working processes compete among them to acquire the jobs that need to be executed. Each token is a composite unit that carries the information about the state of the working process. The

Introductory Chapter: Petri Nets in Science and Engineering

http://dx.doi.org/10.5772/intechopen.79309

9

As an illustration, Figure 9 depicts a CPN for a task scheduling problem. The structure of the net represents the different stages of the working processes in a distributed multitasking environment. The left-hand side of the net structure represents the stages that the processes perform to acquire a job. The right-hand side represents the stages that the working processes perform to release the resources and update the state of the overall scheduling problem. The simulation of the model depicted in the figure allows to study the performance of different scheduling policies over different workload conditions. For example, it is possible to approximate the optimal number of process required by the scheduling problem for a fixed number of tasks. Even more, it is possible to study an optimum rate in the increment of the working

processes given a rate in the increment of the tasks over discrete interval of times [27].

Recently, with the increase of the cloud computing and the massive data content in the social networks, the machine learning techniques and the methods related to the data analytics are essential tools in the study and investigation of the big data. There are several proposals to allow the Petri net models learn some kind of fuzzy reasoning and decision making [22–24]. Similar approaches as that of the supervised and unsupervised learning have been addressed

Figure 10 shows a Petri net representing a workflow pattern for a customer reclaim system. The customer may initiate a request at any time. Two activities are launched in parallel once a request is in the system. First, a ticket check process is executed. Second, an examination of the request is performed. At this point, based on the machine learning, data analytics and/or

Colored Petri Net (CPN) [18].

[21, 25].

Figure 8. A Petri net representing a communication protocol. Process 1 sends a message by the output buffer and waits for an acknowledgement buy the input buffer. Process 2 reads the message from the output buffer and sends an acknowledgment by the input buffer. After the communication protocol is completed, the both processes restart their logics to get ready for the next communication act.

Petri net models. The covered applications include communication protocols, distributed systems, distributed database, concurrent and parallel programming and systems, industrial control systems, multicore processor platforms, dataflow-computer systems design, workflows and process-driven systems, fault-tolerant systems, and to mention a few. Properties practical interest such as fairness in the execution of tasks, deadlock avoidance, state reachability, process

For example, Figure 8 illustrates a very simple and conceptual communication protocol. The communication act is analyzed from the sending process point of view. A sender process sends a message by the output buffer and blocks its activity while waiting for an acknowledgement by the input buffer. A receiver process is blocked while waiting for an input message. Once a message has arrived, the receiving process reads the message and sends an acknowledgment by the input buffer. After the communication act has finished, the process restarts its logic to be ready for the next communication. This model could be extended to include faulty communication channels, which may lose the messages, acknowledge expiration periods, or other characteristics of practical interest. The analysis and design of communications protocols has

There are some extensions to the Petri nets to handle specific aspects of different engineering problems. Some of the extensions add structure and information to the tokens, transitions, and places of a net. These extensions allow the construction of models that are quite compact

Figure 8. A Petri net representing a communication protocol. Process 1 sends a message by the output buffer and waits for an acknowledgement buy the input buffer. Process 2 reads the message from the output buffer and sends an acknowledgment by the input buffer. After the communication protocol is completed, the both processes restart their

logics to get ready for the next communication act.

interlocking, among others, are possible to be analyzed within the Petri net framework.

been widely addressed with the use of Petri net models [9, 10].

8 Petri Nets in Science and Engineering

Figure 9. A colored Petri net model of a task scheduling problem. The structure of the net represents the different stages of the processes in a multitasking environment. The working processes compete among them to acquire the jobs that need to be executed. Each token is a composite unit that carries the information about the state of the working process. The simulation of this model allows us to study the performance of different scheduling policies.

compared to the models obtained with the traditional approach. These models are called Colored Petri Net (CPN) [18].

As an illustration, Figure 9 depicts a CPN for a task scheduling problem. The structure of the net represents the different stages of the working processes in a distributed multitasking environment. The left-hand side of the net structure represents the stages that the processes perform to acquire a job. The right-hand side represents the stages that the working processes perform to release the resources and update the state of the overall scheduling problem. The simulation of the model depicted in the figure allows to study the performance of different scheduling policies over different workload conditions. For example, it is possible to approximate the optimal number of process required by the scheduling problem for a fixed number of tasks. Even more, it is possible to study an optimum rate in the increment of the working processes given a rate in the increment of the tasks over discrete interval of times [27].

Recently, with the increase of the cloud computing and the massive data content in the social networks, the machine learning techniques and the methods related to the data analytics are essential tools in the study and investigation of the big data. There are several proposals to allow the Petri net models learn some kind of fuzzy reasoning and decision making [22–24]. Similar approaches as that of the supervised and unsupervised learning have been addressed [21, 25].

Figure 10 shows a Petri net representing a workflow pattern for a customer reclaim system. The customer may initiate a request at any time. Two activities are launched in parallel once a request is in the system. First, a ticket check process is executed. Second, an examination of the request is performed. At this point, based on the machine learning, data analytics and/or

Figure 10. A Petri net model for a workflow pattern of a customer request. The customer may initiate a new request at any time. Two activities are launched in parallel for every request. One activity is to check the ticket. The other is to examine the request. At this point, a decision is made about how deep to examine the request. At this point, a guard based on the machine learning and data analytics is constructed for the transitions b and c. A decision process then comes, where either a compensation payment, a request rejection, or a request reinitiating may apply.

statistical learning mechanisms, guards for the transitions b and c are constructed. The guards allow deciding when it is more convenient to execute an in-deep examination process or a casual examination process. On the one hand, it saves time by executing a casual examination when the guard determines that it is more likely that the characteristics of the request are that of a genuine customer request. On the other hand, it saves money by executing a thoroughly examination process when the guard determines that the current request is more likely to be a fraudulent request.

Figure 11 represents a Petri net model for three parallel processes. The transition t<sup>1</sup> launches the execution of the processes in parallel. Each process runs freely until they end its activities. In this design, the transition t<sup>5</sup> synchronizes the end of the processes. That is, if one process ends its activities, then it must wait the others to end. Once all the processes have finished, the loop repeats infinitely. The transitions t2, t3, and t<sup>4</sup> represent the activity load of each process. There are different approaches to add an amount of time to these transitions [13–15]. Within a suitable simulation process, this allows to investigate the performance of the system under different work load conditions, which is a must in the development of real world solutions. Once the parameters of the model have been tuned and its performance evaluated, the next step consists on the synthesis of the code in a target programming language for a specific

Figure 11. A Petri net model representing three parallel threads. The threads are launched in parallel by the firing of t1. Each thread runs free to complete its activity. In this design, the end of the threads is synchronized at t5. That is, if one thread finishes its work before the others, it must wait until the other threads end its activities. Once all the threads have

Introductory Chapter: Petri Nets in Science and Engineering

http://dx.doi.org/10.5772/intechopen.79309

11

For example, Figure 12 shows a section of code in C/C++ implemented from the model in Figure 11. The code implements a set of joinable posix threads. A for loop launches a number of threads defined by the global constant NUM\_THREADS. Other for loop waits for the end of the threads. Once all the threads have finished, the loop repeats indefinitely. The automatic code generation from Petri net models has recently been investigated with promissory results

platform.

finished, they are reinitialized to repeat the loop.

[19, 20].

Other important area of the engineering where the Petri nets have been successfully used is in the automatic code generation. The exponential growth of the cloud computing and proliferation of solutions based on the Internet of Things have made the design of the system software supporting them become more challenging. The set of requirements that this type of systems must address includes the sensing of signals in soft and hard real-time and the traditional support for media-reach services. This mixture of requirements turns the design of a correct and efficient system of this type a whole challenge. Approaches based on model-based design promise useful solutions for these challenges. The complex behavior and set of conditions that this class of software must address can be well represented with Petri net patterns. Synchronization mechanisms, message passing, rise conditions, critical sections, parallel and concurrent process, task activation conditions, and user interactions, to mention a few, could be easily represented with intuitive Petri net blocks. Then, a simulation process may allow the study of the performance of the solution and the adjustment of parameters for a fine-tuning process.

Figure 11. A Petri net model representing three parallel threads. The threads are launched in parallel by the firing of t1. Each thread runs free to complete its activity. In this design, the end of the threads is synchronized at t5. That is, if one thread finishes its work before the others, it must wait until the other threads end its activities. Once all the threads have finished, they are reinitialized to repeat the loop.

statistical learning mechanisms, guards for the transitions b and c are constructed. The guards allow deciding when it is more convenient to execute an in-deep examination process or a casual examination process. On the one hand, it saves time by executing a casual examination when the guard determines that it is more likely that the characteristics of the request are that of a genuine customer request. On the other hand, it saves money by executing a thoroughly examination process when the guard determines that the current request is more likely to be a

where either a compensation payment, a request rejection, or a request reinitiating may apply.

Figure 10. A Petri net model for a workflow pattern of a customer request. The customer may initiate a new request at any time. Two activities are launched in parallel for every request. One activity is to check the ticket. The other is to examine the request. At this point, a decision is made about how deep to examine the request. At this point, a guard based on the machine learning and data analytics is constructed for the transitions b and c. A decision process then comes,

Other important area of the engineering where the Petri nets have been successfully used is in the automatic code generation. The exponential growth of the cloud computing and proliferation of solutions based on the Internet of Things have made the design of the system software supporting them become more challenging. The set of requirements that this type of systems must address includes the sensing of signals in soft and hard real-time and the traditional support for media-reach services. This mixture of requirements turns the design of a correct and efficient system of this type a whole challenge. Approaches based on model-based design promise useful solutions for these challenges. The complex behavior and set of conditions that this class of software must address can be well represented with Petri net patterns. Synchronization mechanisms, message passing, rise conditions, critical sections, parallel and concurrent process, task activation conditions, and user interactions, to mention a few, could be easily represented with intuitive Petri net blocks. Then, a simulation process may allow the study of the performance of the solution and the adjustment of parameters for a fine-tuning process.

fraudulent request.

10 Petri Nets in Science and Engineering

Figure 11 represents a Petri net model for three parallel processes. The transition t<sup>1</sup> launches the execution of the processes in parallel. Each process runs freely until they end its activities. In this design, the transition t<sup>5</sup> synchronizes the end of the processes. That is, if one process ends its activities, then it must wait the others to end. Once all the processes have finished, the loop repeats infinitely. The transitions t2, t3, and t<sup>4</sup> represent the activity load of each process. There are different approaches to add an amount of time to these transitions [13–15]. Within a suitable simulation process, this allows to investigate the performance of the system under different work load conditions, which is a must in the development of real world solutions. Once the parameters of the model have been tuned and its performance evaluated, the next step consists on the synthesis of the code in a target programming language for a specific platform.

For example, Figure 12 shows a section of code in C/C++ implemented from the model in Figure 11. The code implements a set of joinable posix threads. A for loop launches a number of threads defined by the global constant NUM\_THREADS. Other for loop waits for the end of the threads. Once all the threads have finished, the loop repeats indefinitely. The automatic code generation from Petri net models has recently been investigated with promissory results [19, 20].

Acknowledgements

Author details

References

Media; 2012

77(4):541-580

Business Media; 2013

2000:33(13):313-318

Wiley & Sons; 2011

Science & Business Media; 2009

Raul Campos-Rodriguez<sup>1</sup>

Tlaquepaque, Jalisco, Mexico

Machine Learning and Data Analytics.

The authors want to thank Jose Valerio, from Oracle Guadalajara Development Center, for his valuable comments in the review of this chapter and for his experience and comments in

Introductory Chapter: Petri Nets in Science and Engineering

http://dx.doi.org/10.5772/intechopen.79309

13

\* and Mildreth Alcaraz-Mejia<sup>2</sup>

1 Monterrey Institute of Technology and Higher Education, Guadalajara Campus,

[1] Reisig W. Petri Nets: An Introduction. Vol. 4. Luxemburgo: Springer Science & Business

[2] Murata T. Petri nets: Properties, analysis and applications. Proceedings of the IEEE. 1989;

[3] Mac Lane S. Categories for the Working Mathematician. Vol. 5. Berlin: Springer Science &

[5] Cassandras CG. Discrete Event Systems: Modeling and Performance Analysis. Aksen Associates Series in Electrical and Computer Engineering, IFAC Proceedings Volumes.

[6] Cassandras CG, Lafortune S. Introduction to Discrete Event Systems. Berlin: Springer

[7] Farina L, Rinaldi S. Positive Linear Systems: Theory and Applications. New York: John

[8] Viswanadham N, Narahari Y. Performance Modeling of Automated Manufacturing Sys-

[4] Roxin EO. Control Theory and its Applications. Gordon and Breach; 1997

tems. Englewood Cliffs, NJ: Prentice Hall; 1992. pp. 497-508

\*Address all correspondence to: rr\_campos@hotmail.com

2 ITESO University, Tlaquepaque, Jalisco, Mexico

Figure 12. A section of code in C/C++ implemented from the Petri net in the figure above. An infinite loop initializes a set of joinable threads. A for loop launches the number of threads specified by the constant NUM\_THREADS. A for loop waits for the end of all the launched threads. This cycle repeats forever.
