A Program Model of Fuzzy Interpreted Petri Net to Control Discrete Event Systems

: Using Petri nets (PNs) to control discrete event systems (DES) has many beneﬁts, because of their graphical representations, the possibility of parallel process control, and their formal descriptions. Amongst the different PNs that are applied for this purpose, most have some limitations for visualization. For many of these PNs, another restriction is the length of time between the creation of the control algorithm in the form of a graph and its practical implementation. These two issues can be resolved with one solution called fuzzy interpreted PN (FIPN). This article proposes the use of a program model based on FIPN to control DES and the method for generation of this model using the graphical representation of the net. FIPN offers a better visualization in comparison to discrete PNs and it allows for the quick creation of program code through the application of a simulator called FIPN-SML. This computer tool implements a method that transforms the graphical form of FIPN into Structured Text (ST) language supported by the IEC 61131-3.


Introduction
Although a finite state machine and a finitely recursive process can be used to model discrete event systems (DES) [1,2], researchers began to use Petri nets (PNs).The reasons for this are the graphical representation of PNs, the possibility of parallel process control, the formal description of PNs, increasing complexity of DES, and greater expectations for the analysis and the modelling of DES [3][4][5].This led to the creation of many classes of PNs [6].Additionally, many software programs [7] that enable the analysis of various net properties were created.These tools can be applied to simulate the operations of systems based on PNs and to find their properties automatically.They usually permit the modelling of specific classes of nets.Research on the modelling, simulation, operation, and control of DES through the application of PNs can be divided into two trends.The first is related to the development of the formal methods that refer to general models.The second is also associated with the formal methods, but they refer to the specific programming languages.
Amongst the papers that consider the first trend, some are related to supervisory control that can be based on structural reasoning [8], applied with the use of the hybrid net [9], and used for a system with uncontrollable and unobservable transitions [10].Others are associated with the validation of DES, which includes: diagnosis of an asynchronous system [11]; detecting and isolating fault events [12]; fault online detection [13]; fault diagnosis with unobservable transition [14]; model checking based on user specification [15]; formal verification with the use of structural reasoning and general unary hypothesis automaton (GUHA) methods [16].Other research concerns the application of PNs to specific problems, e.g., to model flexible manufacturing systems (FMS) [17][18][19][20][21][22] or to model an emergency vehicle preemption system [23].Different models and problems related to DES can be also found in [4][5][6][24][25][26].
The second trend refers mostly to programmable logic controllers (PLCs).For more than two decades, because of their many undeniable advantages, PLCs have become good platforms for the implementation of DES based on PNs [27].One of the first solutions was Grafcet [28], which is currently available as the international standard IEC 60848:2013 [29].Next, the Sequential Function Chart (SFC) was created based on Grafcet in IEC 1131-3:1992 (currently IEC 61131:2013 [30]).Many software tools of different manufacturers enable the use of Grafcet and SFC.Both nets allow the application of transitions, to which some two-state conditions can be assigned, which are usually linked to the binary sensors or the outputs of timers.Some areas of application and ways to use Grafcet and SFC are also presented in [6,[31][32][33].
For industrial approaches, Ladder Diagram (LD) language is more often applied than the other languages supported by the IEC 61131-3.This tendency can also be seen in methods that combine PLC programming with PNs [34][35][36][37][38][39][40][41][42][43].However, languages other than LD are also used.In [34], the conversion of automation PN into LD using the token passing logic methodology is described.Signal interpreted PN (SIPN), which can be implemented in LD or Instruction List (IL), is shown in [35][36][37].For IL, the PLC program can be generated automatically using a computer tool for the graphical modelling of SIPN.In [38], the method to generate LD code based on control Petri net (CPN), and the specification for the creation of DES through the application of this net is presented.A summary of some solutions combining LD with PNs is presented in [39].PNs can also be used to validate programs in LD [40] after some conversions from the LD metamodel to time Petri net.In turn, other methods that link PNs to function block diagram (FBD), IL, and LD are proposed in [41][42][43].
An important aspect related to the design of control systems, especially those that are complex, is performance evaluation.Within this area of science, PNs based on stochastic modelling (stochastic PNs) can be used.The application of Generalized Stochastic Petri Nets (GSPNs) to distributed systems, e.g., flexible manufacturing systems, is proposed in [44].GSPNs enable performance evaluation by using simulation or numerical methods.A software tool based on GSPN called GreatSPN is presented in [45,46].Another tool to model stochastic Petri nets is Mobius Framework [47,48].This framework supports multiple modelling formalisms and modularity.It is based on the so-called atomic model which is composed of state variables, properties, and actions.Another solution supporting multi-formalism modelling and modularity is SIMTHESys [49], which enables the application of the product-form solution theory to multi-formalism compositional modelling techniques.Stochastic Preemptive Time Petri Net (SPTPN) is proposed in [50].This net is used to validate and conduct a performance analysis of real-time systems, e.g., a digital control system.The formal model of SPTPN is constructed using step semantics.
All solutions presented that combine PLC programs with PNs can be very valuable.However, the discrete PNs are mainly applied.One of the few fuzzy PNs that can be used directly to control DES is fuzzy interpreted Petri net (FIPN) [51].This net enables the use of analogue and binary signals of processes for diagnosis and control of these processes.It also allows quantitative changes of the resources to be modelled, and the natural interpretation of the fuzzy tokens' position to be maintained.In comparison to discrete PNs, which are usually used to create control systems, the graphic representation of FIPN more precisely shows the dynamics of the net through the possibility of using analogue sensors.To validate and analyse the properties of the net, e.g., liveness and deadlock, the coverability graph can be applied [52].The algebraic representation [51] and the reachability graph can also be used to investigate the properties.When applying a reachability graph for a net with analogue sensors, it needs to be considered as a net with binary sensors to avoid a state-explosion problem.The computer tool called FIPN-SML facilitates the application of FIPN [53].This simulator can be used to create a graph of FIPN and to generate program code for PLCs in ST language based on this graph.
As a continuation of [53], which lacked a formal description of the proposed solution, this article may be included in the second trend of dealing with DES.The previous work generally outlines the concept of this solution and gives an example of using it.Thus, this paper proposes a formal description of the PLC program and the method to create this program based on the graphical representation of FIPN.The aim is to describe how this program and method works by giving general formalisms and an illustrative example.The paper is organised as follows.Firstly, comparison to similar works is presented (Section 2).Secondly, the formal description and the conception of FIPN (Section 3) are shown.Next, the formal program model based on FIPN (Section 4) and the method which allows its creation based on the FIPN's diagram (Section 5.1) are described.Finally, the example of program generation in ST language through using FIPN-SML (Section 5.2) is discussed and a brief summary of the results and possible directions of future developments are given (Section 6).

Comparison to Related Works
In this section, the authors want to raise the issue related to executable specification [54][55][56][57][58][59][60].A graphical representation based on FIPN created in FIPN-SML allows the presentation of the control system behaviour, validation of this system before it is implemented, and clarification of the requirements (that may be initially unclear).This solution enables the automatic construction of executable code and offers a higher abstraction of the designed system.It also reduces the costs and the time needed to develop control systems.All of these advantages are analogical to the cited executable specifications.Moreover, there are some similar approaches to the one proposed in this work [28][29][30][31][32][33][34][35][36][37][38][39]41].Implementation of some of them can also be seen as a programming language.They all have unquestionable benefits.Nevertheless, the authors believe that their solution can be characterized by some unique advantages.Based on [51], in literature, fuzzy nets are mainly used to create expert systems, but few deal with the direct application to control [61][62][63].These approaches do not have software tool support, do not permit modelling of resources using the net structure, nor do they generate executable code automatically.
When compared to other mentioned solutions [28][29][30][31][32][33][34][35][36][37][38][39]41], the main advantage of the program model based on FIPN is the possibility of using analogue sensors for the direct control of DES.Contrary to Grafcet and SFC [28][29][30][31][32][33], FIPN allows resources modelling in the structure of a net, because the weight of arcs and the places capacity can be greater than one, while Grafcet and SFC are based on binary net.Both Grafcet and SFC have similar features to FIPN.They both enable simulation of the created system before it is implemented in PLC and automatic executable code generation based on the simulation model (the graphical representation).However, Grafcet and SFC have some advantages compared to FIPN.Their main advantage is the use of a modularity/hierarchical structure.The authors are aware of this limitation of FIPN and their work related to this subject is currently under consideration by another journal.
Another solution is SIPN [35][36][37], a binary net, with a formal description.Transformation of the graphical representation to executable code is informal in the examples (IL and LD).As with FIPN, SIPN permits automatic generation of executable code.The main advantages in comparison with FIPN are the automatic investigation of properties through application of the SIPN editor and the possibility of using modularity.Apart from the three solutions mentioned, which seem complete because of software tools, there are some others which propose the conversion of PNs to LD [34,38,39,41].They have many advantages and they do not take into consideration only binary nets, (e.g., [34]).However, they do not allow automatic generation of executable code based on the graphical representation of a net using a software tool.
To conclude this section, it can be observed that there is no other solution that combines PNs and PLC programming to create control systems and offer the possibility of using analogue sensors, software tool support, resources modelling by the structure of the net, and automatic generation of executable code.However, some new functionalities need to be implemented to see FIPN-SML as a complete solution.

The Formal Basis and the Conception of FIPN
Three definitions describe the formal basis of FIPN.The first shows the construction of the net.Definition 1.The fuzzy interpreted Petri net is the system [51]: FIPN = (P, T, Ω, Ψ, R, ∆, K, W, Γ, Θ, M 0 , e), where: P = P ∪ P -is a nonempty finite set of places, where: P = {p 1 , p 2 , . . . ,p a }-is a set of places for processes modelling, and P = {p 1 , p 2 , . . . ,p a }-a set of places for resources modelling; T = {t 1 , t 2 , . . . ,t b }-is a nonempty finite set of transitions; Ω= {ω 1 , ω 2 , . . . ,ω a +a }-is a nonempty finite set of statements; Ψ = {ψ 1 , ψ 2 , . . . ,ψ b }-is a nonempty finite set of conditions; P, T, Ω, Ψ-where none of these sets have common elements; R ⊆ (P × T) ∪ (T × P)-is the incidence relation that assigns a place to each transition t i ∈ T(1 ≤ i ≤ b) , where there is the place p ∈ P such that (p , t i ) ∈ R or (t i , p ) ∈ R ; ∆: P → Ω-is the function that assigns a statement to each place; K : P → 1 and P → ℵ{1} -is the function that assigns a capacity to each place, where: ℵ = {1, 2, . . .}; Γ: T Ψ-is the function that assigns a condition to each transition; Θ: T → [0, 1]-is the function that defines the degree to which the conditions corresponding to the transitions t are satisfied; W: R → ℵ-is the weight function that meets two conditions, where: W(p, t) ≤ K(p), and W(t, p) ≤ K(p) (p means p' or p"); M 0 : P → {0, 1} and P → W + -is the initial marking function, where: M 0 (p j ) = z j /K(p j ), z j ∈ ℵ ∪ {0}, z j ≤ K(p j ), j = 1, 2, . . ., a , and W + -is a set of non-negative rational numbers; e-is an event that synchronizes the work of all transitions.
FIPN can be represented as a bipartite graph.An exemplary net is shown in Figure 1.There are two types of places in the net: p -type (for processes modelling) and p -type (for resources modelling).They are drawn as circles.For both types, the marking is a real number from the range [0, 1] located inside the circle.However, the marking of p -type places is presented as a fraction and can store a number of tokens greater than one.The capacity of these places K (p) > 1 arranged in the denominator is a normalization coefficient by which the marking value is bounded into the interval [0, 1].Moreover, statements can be assigned to p -type places to set a value of output variables.Transitions are represented by rectangles, and can be related to binary and analogue sensors.Additionally, some logic conditions can be assigned to synchronized transitions and the arcs which link places with transitions are labelled with weighting factors.The conception of using statements, sensors, and logic conditions is presented at the end of this section and in Section 4.2.
The transfer of markers from input to output places across the transition can begin when the conditions (1) and ( 2) of Definition 2 are satisfied and ends when conditions (3) and ( 4) are fulfilled., t  which is assigned to the transition, is greater than zero and the following conditions are satisfied [51]: to the moment at which: where: is the set of input places of the transition t, and is the set of its output places.
In FIPN, an analogue signal can be assigned to a transition and its value is normalized into the range [0,1].The transfer of a marker across the fired transition is a process whose duration is longer than one clock cycle that synchronizes the net operation.This duration depends on the increment of the sensor value.Such work of transitions permits more precise observation of changes in the controlled system.
The change of the marking for places connected to the enabled transition depends on the increment of the degree to which the condition corresponding to the transition is satisfied.The method that calculates the new marking is described by Definition 3. The transition remains active until the markers are transferred from the input places to the output places of the transition.

Definition 3. Let M be the marking for which the transition
which the condition corresponding to the enabled transition is satisfied will be changed by 0  and there will be an event e which synchronizes the work of all transitions.The new marking of the net M' is computed by the following rule [51]: ( The increment 0  does not introduce any changes in marking of the net.Definition 2. The transition t ∈ T with marking M:P → [0, 1] is enabled from the moment in which the degree to fulfil the condition Θ(t) = ϑ, which is assigned to the transition, is greater than zero and the following conditions are satisfied [51]: to the moment at which: where: • t = {p ∈ P|(p, t) ∈ R} is the set of input places of the transition t, and t • = {p ∈ P|(t, p) ∈ R} is the set of its output places.
In FIPN, an analogue signal can be assigned to a transition and its value is normalized into the range [0, 1].The transfer of a marker across the fired transition is a process whose duration is longer than one clock cycle that synchronizes the net operation.This duration depends on the increment of the sensor value.Such work of transitions permits more precise observation of changes in the controlled system.
The change of the marking for places connected to the enabled transition depends on the increment of the degree to which the condition corresponding to the transition is satisfied.The method that calculates the new marking is described by Definition 3. The transition remains active until the markers are transferred from the input places to the output places of the transition.Definition 3. Let M be the marking for which the transition t ∈ T is enabled.The degree Θ(t) = ϑ ∈ [0, 1] to which the condition corresponding to the enabled transition is satisfied will be changed by ∆ϑ ≥ 0 and there will be an event e which synchronizes the work of all transitions.The new marking of the net M' is computed by the following rule [51]: = which is assigned to the transition, is greater than zero and the following conditions are satisfied [51]: to the moment at which: where: is the set of input places of the transition t, and is the set of its output places.
In FIPN, an analogue signal can be assigned to a transition and its value is normalized into the range [0,1].The transfer of a marker across the fired transition is a process whose duration is longer than one clock cycle that synchronizes the net operation.This duration depends on the increment of the sensor value.Such work of transitions permits more precise observation of changes in the controlled system.
The change of the marking for places connected to the enabled transition depends on the increment of the degree to which the condition corresponding to the transition is satisfied.The method that calculates the new marking is described by Definition 3. The transition remains active until the markers are transferred from the input places to the output places of the transition.

Definition 3. Let M be the marking for which the transition
which the condition corresponding to the enabled transition is satisfied will be changed by 0 Δϑ³ and there will be an event e which synchronizes the work of all transitions.The new marking of the net M' is computed by the following rule [51]: The increment 0 Δ ϑ < does not introduce any changes in marking of the net.
The increment ∆ϑ < 0 does not introduce any changes in marking of the net.
Figure 2 shows the exemplary change of the marking for places connected to the active transition t 1.The increment of the degree to which the condition corresponding to the transition t 1 is satisfied has the value of ∆ϑ = 0.2 at the time when the synchronization signal arrives.Such a change of the marking gives a more precise visualization in comparison to discrete PNs and enables the monitoring of progress in the movement of tokens between the input and output places across the transition.At the end of this section, a simple example is shown to clarify the main advantage of FIPN in comparison to classic Petri nets.In Figure 3a-d, the tank TK1 that can be filled using the valve V1 is presented, and two different graphs as control systems to fill TK1 are proposed.The first is created using SFC, and the second is based on FIPN.Different levels of liquid in TK1 and corresponding to the states of both systems are also shown.In general, the systems operate in a similar manner.First, the filling of TK1 is started by active step S1/ the place p1 which opens the valve V1 (variable V1 is set to true).Next, when the tank TK1 is completely filled, active step S2/place p2 closes the valve (variable V1 is set to false).However, both systems differ in one important aspect.While in the system based on SFC a binary sensor to monitor the level of liquid is used (LLS1), the system based on FIPN allows the application of an analogue sensor (the same name LLS1 is used to facilitate a comparison of both systems).First, the filling process of TK1 begins, as shown in Figure 3a.Then, different levels of liquid in TK1 during filling process are presented in Figure 3b.Finally, TK1 is completely filled (see Figure 3d).The control system based on SFC enables only the display of two states: if the tank TK1 is being filled (Figure 3a-c) or is completely filled (Figure 3d), whereas the system based on FIPN shows the actual level of liquid all the time.In addition, FIPN allows actions to be performed based on the actual level of liquid (the current marking of places), e.g., while a mixer is being filled with two liquids stored in tanks, and one of the tanks is being emptied too fast/slow compared to the other one, the mixing time can be increased.Hence, FIPN offers a more precise visualization and control of DES than classic Petri nets.

The Program Model of the FIPN
In this section, the program model based on FIPN (called FIPN P ) is described.Before it is discussed, the conception of using this model through FIPN-SML to control DES is shown (Figure 4).The graph of FIPN can be created in the simulator.Based on this graph, the program in ST language At the end of this section, a simple example is shown to clarify the main advantage of FIPN in comparison to classic Petri nets.In Figure 3a-d, the tank TK 1 that can be filled using the valve V 1 is presented, and two different graphs as control systems to fill TK 1 are proposed.The first is created using SFC, and the second is based on FIPN.Different levels of liquid in TK 1 and corresponding to the states of both systems are also shown.In general, the systems operate in a similar manner.First, the filling of TK 1 is started by active step S 1 / the place p 1 which opens the valve V 1 (variable V 1 is set to true).Next, when the tank TK 1 is completely filled, active step S 2 /place p 2 closes the valve (variable V 1 is set to false).However, both systems differ in one important aspect.While in the system based on SFC a binary sensor to monitor the level of liquid is used (LLS 1 ), the system based on FIPN allows the application of an analogue sensor (the same name LLS 1 is used to facilitate a comparison of both systems).First, the filling process of TK 1 begins, as shown in Figure 3a.Then, different levels of liquid in TK 1 during filling process are presented in Figure 3b.Finally, TK 1 is completely filled (see Figure 3d).The control system based on SFC enables only the display of two states: if the tank TK 1 is being filled (Figure 3a-c) or is completely filled (Figure 3d), whereas the system based on FIPN shows the actual level of liquid all the time.In addition, FIPN allows actions to be performed based on the actual level of liquid (the current marking of places), e.g., while a mixer is being filled with two liquids stored in tanks, and one of the tanks is being emptied too fast/slow compared to the other one, the mixing time can be increased.Hence, FIPN offers a more precise visualization and control of DES than classic Petri nets.At the end of this section, a simple example is shown to clarify the main advantage of FIPN in comparison to classic Petri nets.In Figure 3a-d, the tank TK1 that can be filled using the valve V1 is presented, and two different graphs as control systems to fill TK1 are proposed.The first is created using SFC, and the second is based on FIPN.Different levels of liquid in TK1 and corresponding to the states of both systems are also shown.In general, the systems operate in a similar manner.First, the filling of TK1 is started by active step S1/ the place p1 which opens the valve V1 (variable V1 is set to true).Next, when the tank TK1 is completely filled, active step S2/place p2 closes the valve (variable V1 is set to false).However, both systems differ in one important aspect.While in the system based on SFC a binary sensor to monitor the level of liquid is used (LLS1), the system based on FIPN allows the application of an analogue sensor (the same name LLS1 is used to facilitate a comparison of both systems).First, the filling process of TK1 begins, as shown in Figure 3a.Then, different levels of liquid in TK1 during filling process are presented in Figure 3b.Finally, TK1 is completely filled (see Figure 3d).The control system based on SFC enables only the display of two states: if the tank TK1 is being filled (Figure 3a-c) or is completely filled (Figure 3d), whereas the system based on FIPN shows the actual level of liquid all the time.In addition, FIPN allows actions to be performed based on the actual level of liquid (the current marking of places), e.g., while a mixer is being filled with two liquids stored in tanks, and one of the tanks is being emptied too fast/slow compared to the other one, the mixing time can be increased.Hence, FIPN offers a more precise visualization and control of DES than classic Petri nets.

The Program Model of the FIPN
In this section, the program model based on FIPN (called FIPN P ) is described.Before it is discussed, the conception of using this model through FIPN-SML to control DES is shown (Figure 4).The graph of FIPN can be created in the simulator.Based on this graph, the program in ST language

The Program Model of the FIPN
In this section, the program model based on FIPN (called FIPN P ) is described.Before it is discussed, the conception of using this model through FIPN-SML to control DES is shown (Figure 4).The graph of FIPN can be created in the simulator.Based on this graph, the program in ST language can be generated and applied to PLC.The important part of the conception is the method of the automatic code generation presented in the next section.The model FIPN P is divided into two parts: a set of variables and the functions that operate on these variables.These parts are described below in the separate subsections.

The Program Model of the FIPN-Variables
In this subsection, the variables set for the program model based on FIPN is presented.The definition of this set is as follows.

Definition 4. The variables in the program model based on FIPN are the system
V P = {M P , Mn P , K P , A P , Tet P , Dtet P , W P , Out P  ) is represented by variables ak, tetk, dtetk that refer respectively to the state of the transition activation, the degree to which the condition corresponding to the transition is satisfied, and the increment of the degree tetk.The set of variables V P from Definition 4 can be considered as the program implementation of Definition 1. Functions which operate on places and transitions from Definition 1 are replaced by appropriate variables from Definition 4. The model FIPN P is divided into two parts: a set of variables and the functions that operate on these variables.These parts are described below in the separate subsections.

The Program Model of the FIPN-Variables
In this subsection, the variables set for the program model based on FIPN is presented.The definition of this set is as follows.
Definition 4. The variables in the program model based on FIPN are the system V P = {M P , Mn P , K P , A P , Tet P , Dtet P , W P , Out P , In P }, where: M P = {m 1 , m 2 , . . . ,m a +a }-the set of variables that ∀p ∈ P stores the current marking M(p) of the place; Mn P = {mn 1 , mn 2 , . . . ,mn a +a }-the set of variables that ∀p ∈ P stores the new marking M (p) of the place; K P = {k 1 , k 2 , . . . ,k a +a }-the set of variables that ∀p ∈ P stores the capacity K(p) of the place; A P = {a 1 , a 2 , . . . ,a b }-the set of variables that ∀t ∈ Tstores the state of the transition activation; Tet P = {tet 1 , tet 2 , . . . ,tet b }-the set of variables that ∀t ∈ T stores the degreesΘ(t) = ϑ ∈ [0, 1] to which the conditions corresponding to the transitions are satisfied; Dtet P = {dtet 1 , dtet 2 , . . . ,dtet b }-the set of variables that ∀t ∈ T stores the increments of the degrees ∆ϑ to which the conditions corresponding to the transitions are satisfied; W P -the set of variables that store the weights of arcs: ∀(p i , t k ) ∈ R the variable p i _t k is created with the value W(p i , t k ), while ∀(t k , p i ) ∈ R the variable t k _p i is created with the value W(t k , p i ), where i = 1, 2, . . ., a + a and k = 1, 2, . . ., b; Out P -the set of output variables that are set through appropriate changes of the marking; In P -the set of input variables that represent sensors related to transitions.All variables are of real type apart from sets A P and Out P , which include Boolean variables.
According to Definition 4, each place p i ∈ P (i = 1, 2, . . ., a + a ) is represented by three variables in the program model based on FIPN which are: m i , mn i , and k i (the current marking, the new marking, and the capacity of the place, respectively).While each transition t k ∈ T (k = 1, 2, . . ., b) is represented by variables a k , tet k , dtet k that refer respectively to the state of the transition activation, the degree to which the condition corresponding to the transition is satisfied, and the increment of the degree tet k .The set of variables V P from Definition 4 can be considered as the program implementation of Definition 1. Functions which operate on places and transitions from Definition 1 are replaced by appropriate variables from Definition 4.

The Program Model of the FIPN-Functions
In this subsection, all functions that belong to the program model of the FIPN are presented.These functions are created based on Definitions 2 and 3.They specify some principles of model operation and can be divided into four groups: • the functions that calculate the increment of the degree to which the condition corresponding to the transition is satisfied; • the functions that check if the transitions are granted to be fired or lose the concession; • the functions that calculate the new marking of places; • the functions that set output variables based on the new marking of places.
All functions are more clearly described below.

The Calculation of the Degree to which the Condition Corresponding to the Transition Is Satisfied
To limit the values from sensors, the function Bound is used.This function changes each value to the range [0, 1].The limit of each input variable in i ∈ In P , that represents the value from the sensor corresponding to the transition t i ∈ T is as follows: Based on (9), the function CalcDtet is implemented.This function calculates the increment dtet i of the degree to which the condition corresponding to the transition t i ∈ T is satisfied (in two subsequent cycles).It is implemented in the following way: where: tet i (tet i ∈ Tet P ) denotes the variable that stores the degree to which the condition corresponding to the transition is satisfied.

The Checking of the Conditions for the Activation or the Loss of a Concession by a Transition
To check the loss of activation by each transition of t i ∈ T, the function LAIn or LAOut is applied.These functions detect the loss of a concession by the transition using one of its input or output p -type places.If the transition has at least one input place of this type, the function LAIn is used pursuant to (3): where: a i (a i ∈ A P ) is a variable that stores the state of the transition activation, m in(i) (m in(i) ∈ M P ) denotes the variable that stores the current marking for the transition's input place that is p -type.
On the other hand, if the transition t i does not have any input places of p -type, it has at least one output place of this type according to the definition of incidence relation (Definition 1).In this case, the function LAOut is used and implemented pursuant to (4) in the following manner: where: m out(i) (m out(i) ∈ M P ) denotes the variable that stores the current marking for the transition's output place that is p -type.
Moreover, the functions ( 11) and ( 12) set the degree to which the condition corresponding to the transition is satisfied when the transition loses the concession.The variable tet i is set to zero.
To examine if the inactive transition t i can be activated through its c i (c i = card( • t i )) input places, the function AIn c i is used.This function is implemented based on (1) as follows: where: m in(1) , m in(2) , . . ., m in(c i ) (m in(j) ∈ M P ) denote the variables that store the current marking for all input places of the transition t i ( , k in(2) , . . . ,k in(c i ) (k in(j) ∈ K P ) denote the variables that store the capacity of • t i , p in(1) _t i , p in(2) _t i , . . . ,p in(c i ) _t i (p in(j) _t i ∈ W P ) denote the variables that store the weights of all arcs from • t i to the transition t i .
To check if the transition t i can be activated through its d i (d i = card(t i • )) output places, the function ActOut d i is used.This function is implemented based on (2) as follows: AOut d i (a i , m out(1) , t i _p out(1) , k out(1) , m out(2) , t i _p out(2) , k out(2) , . . . ,m out(d i ) , t i _p out(d i ) , k out(d i ) ) = true for ¬a i ∧ (∀j ∈ {1, 2, . . . ,d i } : m out(j) ≤ 1 − t i _p out(j) /k out(j) ) a i in other case (14) where: m out(1) , m out(2) , . . ., m out(d i ) (m out(j) ∈ M P ) denote the variables that store the current marking for all output places of the transition t i (t i • ); k out(1) , k out(2) , . . . ,k out(d i ) (k out(j) ∈ K P ) denote the variables that store the capacity of t i • ; t i _p out(1) , t i _p out(2) , . . . ,t i _p out(d i ) (t i _p out(j) ∈ W P ) denote the variables that store the weights of all arcs from the transition t i to the t i • .
If the activation of the transition t i requires an additional logic condition, the function LC is used to avoid conflicts between transitions in the net.This function is implemented in the following manner: LC(a i , lc i ) = lc i for ¬a i true in other case (15) where: lc i denotes the logic condition assigned to the transition t i .

The Calculation of the New Marking
The new marking of the c i input places of each transition t i ∈ T is calculated using the function InM c i implemented based on (5): (1) , p in(1) _t i , k in (1) , mn in (2) , p in (2) mn in(j) := mn in(j) − , ∀j ∈ {1, 2, . . ., c i } } } (16) where: mn in (1) , mn in(2) , . . ., mn in(c i ) (mn in(j) ∈ Mn P ) denote the variables that store the new marking for all input places of the transition t i ( • t i ).
Whereas, the new marking of d i output places of the transition t i is computed using the function OutMn d i created based on (6): mn out(j) := mn out(j) + , ∀j ∈ {1, 2, . . ., d i } } } (17) where: mn out(1) , mn out(2) , . . ., mn out(d i ) (mn out(j) ∈ Mn P ) denote the variables that store the new marking for all output places of the transition t i (t i • ).
Moreover, in (17) the degree to which the condition corresponding to the transition is satisfied is updated (tet i ).

The Setting of Output Variables
At the end of each PLC cycle, the output variables from the statement of each p -type place p i ∈ P are set to true or false, if the new marking of p i is updated to one.The function MChg n i is used to set the output variables as follows: , ∀k ∈ {1, 2, . . . ,n i } } m i := mn i } } (18) where: out i(1) , out i(2) , . . ., out i(n i ) denote the output variables related to the place p i , lv i(1) , lv i(2) , . . ., lv i(n i ) denote the logic values (true or false).Moreover, the function MChg n i () updates the variable of the current marking m i based on the variable of the new marking mn i .The variables of the current marking for all p -type places that are not linked to any output variables and for all p"-type places are updated by MChg 0 ().

The Method of Automatic Program Generation Using ST Language
In this section, the method of program generation based on FIPN and the implementation of this method for an exemplary net are presented.In the first subsection, the algorithms that create the declaration of variables and the part of the program executed in the cycles are described.The second presents the use of these algorithms in FIPN-SML, which allows automatic generation of the most significant part of the program in ST language.

Algorithms of the Program Generation Based on FIPN
The method of program generation based on FIPN is divided into two algorithms.The first creates the declaration of variables.At the beginning, an empty buffer is created.Next, for each of the place declarations of the current marking, the new marking and the capacity along with their initial values are added to the text buffer.Then, for each transition, declarations of the following variables are added to the text buffer: degree to which the condition corresponding to the transition is satisfied with an initial value of zero; the increment of this degree has an initial value of zero if the transition is synchronised by a sensor, otherwise it has an initial value of one; the activation of the transition has an initial value of false.Finally, the declarations of output variables related to places and input variables related to transitions are inserted into the text buffer.However, before the addition, it is checked to determine whether a declaration of an input or output variable has already been added (by another transition or place) to the text buffer to avoid duplication.Output variables should be initialized with true if the initial marking of the place is equal to one and this output variable is set to true in the statement assigned to the place.Otherwise it should be initialized with false.The first algorithm (Algorithm 1) is as follows: Algorithm 1. Create the declaration of variables 1: Create empty text buffers bt 1 , bt 2 , bt 3 , bt 4 and empty lists l 1 , l 2 .2: for each place p i ∈ P do 3: Add the declaration of the variable m i with the initial value M 0 (p i ) to bt 2 4: Add the declaration of the variable mn i with the initial value M 0 (p i ) to bt 3 .

5:
Add the declaration of the variable k i with the value K(p i ) to bt 4 .6: end for 7: Add bt 2 , bt 3 , bt 4 to bt 1 , and then clear bt 2 , bt 3 , bt 4 .8: for each transition t i ∈ T do 9: Add the declaration of the variable tet i with the initial value zero to bt 2 .10: if the condition ψ i = Γ(t i ) assigned to t i is related to a sensor variable in i then 11: Add the declaration of the variable dtet i to bt 3 with the initial value zero.12: else 13: Add the declaration of the variable dtet i to bt 3 with the initial value one.

An Example of Program Generation in ST Language
In this subsection, the use of algorithms from the previous subsection is presented.The graphic diagram of FIPN is created in FIPN-SML (Figure 5).There are five places and two transitions in the diagram.To each place of p -type the statement can be assigned that sets the output variables linked to the place, e.g., for the place p 1 the variable O1 is set to true and the variable O2 to false.Output variables are set when the value of the current marking is changed to one (M(p ) = 1).Each transition can be synchronized by a sensor and activated by a logic condition.The transition t 1 is synchronized by the sensor I N 1 and the activation of the transition t 2 is subject to the logic condition M(p 1 ) < 1 (to avoid conflict with the transition t 1 ).From the moment the program is generated in FIPN-SML, it can be copied to PLC software.The basic assumption of the method is that the special library with the implemented functions ( 9)-( 18) was prepared earlier and added to the PLC software.The designer of the net must copy the generated program code and combine the physical inputs and outputs of a controller with the program variables.

An Example of Program Generation in ST Language
In this subsection, the use of algorithms from the previous subsection is presented.The graphic diagram of FIPN is created in FIPN-SML (Figure 5).There are five places and two transitions in the diagram.To each place of p′-type the statement can be assigned that sets the output variables linked to the place, e.g., for the place 1 p the variable O1 is set to true and the variable O2 to false.Output variables are set when the value of the current marking is changed to one (M(p′) = 1).Each transition can be synchronized by a sensor and activated by a logic condition.The transition 1 t is synchronized by the sensor (to avoid conflict with the transition 1 t ).From the moment the program is generated in FIPN-SML, it can be copied to PLC software.The basic assumption of the method is that the special library with the implemented functions ( 9)-( 18) was prepared earlier and added to the PLC software.The designer of the net must copy the generated program code and combine the physical inputs and outputs of a controller with the program variables.

Conclusions
In this paper, the formal description of the PLC program based on FIPN and the method to create this program are proposed.Additionally, the formal basis and conception of using FIPN, the creation of an exemplary diagram based on FIPN in FIPN-SML and the automatic code generation for this diagram are shown.The code generated is in the ST language and can be applied to PLC at low cost and with little effort.The presented approach also allows for a significant reduction of the program implementation time to control DES.The work of the control system can be better visualized using analogue sensors in comparison to the discrete PNs.The application of FIPN allows resources to be modelled by the structure of the net, offers software tool support, and

Conclusions
In this paper, the formal description of the PLC program based on FIPN and the method to create this program are proposed.Additionally, the formal basis and conception of using FIPN, the creation of an exemplary diagram based on FIPN in FIPN-SML and the automatic code generation for this diagram are shown.The code generated is in the ST language and can be applied to PLC at low cost and with little effort.The presented approach also allows for a significant reduction of the program implementation time to control DES.The work of the control system can be better visualized using analogue sensors in comparison to the discrete PNs.The application of FIPN allows resources to be modelled by the structure of the net, offers software tool support, and provides automatic generation of executable code.An additional advantage of the formal description presented in this paper is its generality.The proposed formalism does not limit the solution only to the ST language or other languages from IEC 61131:2013, but it provides the opportunity to use it beyond the PLC area.
However, some functionalities still need improvement.Apart from modularity, which is the subject of an author's article considered in another journal, the authors will: extend automatic code generation to other languages supported by the IEC 61131-3; add to the FIPN-SML a component that

Figure 1 .
Figure 1.Two different input and output places of the transition t1.

Figure 1 .
Figure 1.Two different input and output places of the transition t 1 .

18 Figure 1 .
Figure 1.Two different input and output places of the transition t1.Definition 2. The transition T t ∈ with marking M:P → [0,1] is enabled from the moment in which the degree to fulfil the condition Θ( ) , t ϑ

Figure 2
Figure2shows the exemplary change of the marking for places connected to the active transition t1.The increment of the degree to which the condition corresponding to the transition t1 is satisfied has the value of 0.2  at the time when the synchronization signal arrives.Such a change of the marking gives a more precise visualization in comparison to discrete PNs and enables the monitoring of progress in the movement of tokens between the input and output places across the transition.

Figure 2 .
Figure 2. The change of the marking for the input and output places for 0.2.

Figure 3 .
Figure 3. Different levels of liquid in the tank TK1 and corresponding to the states of control systems based on Sequential Function Chart (SFC) and fuzzy interpreted PN (FIPN).

Figure 2 .
Figure 2. The change of the marking for the input and output places for ∆ϑ = 0.2.

Figure 2
Figure2shows the exemplary change of the marking for places connected to the active transition t1.The increment of the degree to which the condition corresponding to the transition t1 is satisfied has the value of 0.2  at the time when the synchronization signal arrives.Such a change of the marking gives a more precise visualization in comparison to discrete PNs and enables the monitoring of progress in the movement of tokens between the input and output places across the transition.

Figure 2 .
Figure 2. The change of the marking for the input and output places for 0.2.

Figure 3 .
Figure 3. Different levels of liquid in the tank TK1 and corresponding to the states of control systems based on Sequential Function Chart (SFC) and fuzzy interpreted PN (FIPN).

Figure 3 .
Figure 3. Different levels of liquid in the tank TK 1 and corresponding to the states of control systems based on Sequential Function Chart (SFC) and fuzzy interpreted PN (FIPN).
Appl.Sci.2017, 7, 422 7 of 18 can be generated and applied to PLC.The important part of the conception is the method of the automatic code generation presented in the next section.

Figure 4 .
Figure 4.The conception of using FIPN to model discrete event systems (DES).

Figure 4 .
Figure 4.The conception of using FIPN to model discrete event systems (DES).

1 IN
and the activation of the transition 2 t is subject to the logic condition
Add the declaration of the variable a i to bt 4 with the initial value false.16:endfor17:Addbt 2 , bt 3 and bt 4 to bt 1 .18:foreachplacepi∈Pdo19:foreach output variable out k that is set using the statementω i = ∆(p i ) do 20:if the list l 1 does not contain the name of out k then 21:Add the name of out k to l 1 .22:ifM0(pi ) > 0 and out k is set to true in the statement ω i then 23:Add the declaration of out k to bt 1 with the initial value true.=Γ(t i ) assigned to t i is related to a sensor variable in i and the list l 2 does not contain the name of in i then 32:Add the name of in i to l 2 .33:Add the declaration of in i to bt 1 with the initial value zero.Return the result of the algorithm: bt 1 .