# A Program Model of Fuzzy Interpreted Petri Net to Control Discrete Event Systems
## 3 The Formal Basis and the Conception of FIPN
### Algorithm of the Program Generation Based on FIPN
8:for each transition \(t_{i}\in T\)do//clock if a transition can be fired or loses the concession
9:if\(t_{i}\) has at least one input \(p^{\prime}\)-type place \(p^{\prime}_{in(i)}\), such that \((p^{\prime}_{in(i)},t_{i})\in R\)then
10: Add to \(bt_{2}\) the following fragment of code based on (11): \(a_{i}:=LAIn(a_{i},m^{\prime}_{in(i)},tet_{i})\)
11:else
12: Find the output \(p^{\prime}\)-type place \(p^{\prime}_{out(i)}\) of \(t_{i}\), such that \((t_{i},p^{\prime}_{out(i)})\in R\), and then add to \(bt_{2}\) the following fragment of code based on (12): \(a_{i}:=LAOut(a_{i},m^{\prime}_{out(i)},tet_{i})\)
13:endif
14:if card (\({}^{\bullet}t_{i}\)) > 0 then
15: Add to \(bt_{2}\) the following fragment of code based on (13): \(\wedge\Lambda In_{c_{i}}(a_{i},m_{in(1)},p_{in(1)},-t_{i},k_{in(1)},m_{in(2)},p _{in(2)},-t_{i},k_{in(2)},\ldots,m_{in(c_{i})},P_{in(c_{i})},-t_{i},k_{in(c_{i})})\)
16:endif
17:if card (\(t_{i}\)) > 0 then
18: Add to \(bt_{2}\) the following fragment of code based on (14): \(\wedge\Lambda Out_{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)},\ldots,m_{out(d_{i})},t_{i}-p_{out(d_{i})},k_{ out(d_{i})})\)
19:endif
20:if the condition \(\psi_{i}=\Gamma(t_{i})\) assigned to \(t_{i}\) includes a logic condition \(lc_{i}\)then
21: Add to \(bt_{2}\) the following fragment of code based on (15): \(\wedge LC(a_{i},lc_{i})\)
22:endif
23: Add \(bt_{2}\) to \(bt_{1}\) and clear \(bt_{2}\). 24:endfor
25:for each transition \(t_{i}\in T\)do//compute the new marking of places connected to a transition
26:if card(\({}^{\bullet}t_{i}\)) > 0 then//input places
27: Add to \(bt_{1}\) the code based on (16): \(InMn_{c_{i}}(a_{i},det_{i},m_{in(1)},p_{in(1)}-t_{i},k_{in(1)},mn_{in(2)},P _{in(2)}-t_{i},k_{in(2)},\ldots,mn_{in(c_{i})},P_{in(c_{i})}-t_{i},k_{in(c_{i})})\)
28:endif
29:if card(\(t_{i}\)) > 0 then//output places
30: Add to \(bt_{1}\) the code based on (17): \(OutMn_{d_{i}}(a_{i},tet_{i},det_{i},m_{out(1)},t_{i}-p_{out(1)},k_{out(1)},mn_{ out(2)},t_{i}-p_{out(2)},k_{out(2)},m_{out(d_{i})},t_{i}-p_{out(d_{i})},k_{out(d_{i})})\)
31:endif
32:endfor
33:for each place\(p_{i}\in P\)do//update the current marking of places and set outputs variables
34: Take each variable \(out_{i(k)}\) and its value \(lv_{i(k)}\) from the statement \(\alpha_{i}=\Delta(p_{i})\) and add to \(bt_{1}\) the line based on (18): \(MChg_{n_{i}}(m_{i},un_{i(1)},lv_{i(1)},out_{i(2)},lv_{i(2)},\ldots,out_{(n_{i})},lv _{i(n_{i})})\)
35:endfor
36:return the result of the algorithm: \(bt_{1}\). ```

**Algorithm 2**********. Generate the part of the program that is executed repeatedly in the cycles of PLC

### 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^{\prime}\)-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^{\prime})=1\)). Each transition can be synchronized by a sensor and activated by a logic condition. The transition \(t_{1}\) is synchronized by the sensor \(IN_{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.