# A Program Model of Fuzzy Interpreted Petri Net to Control Discrete Event Systems
## 3 The Formal Basis and the Conception of FIPN
### 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:  
```
1: Create empty text buffers \(ht_{1}\), \(ht_{2}\), \(ht_{3}\), \(ht_{4}\) and empty lists \(l_{1}\), \(l_{2}\).
2:for each place \(p_{i}\in P\)do
3: Add the declaration of the variable \(m_{i}\) with the initial value \(M_{0}(p_{i})\) to \(ht_{2}\)
4: Add the declaration of the variable \(mn_{i}\) with the initial value \(M_{0}(p_{i})\) to \(ht_{3}\).
5: Add the declaration of the variable \(k_{i}\) with the value \(K(p_{i})\) to \(ht_{4}\).
6:endfor
7: Add \(ht_{2}\), \(ht_{3}\), \(ht_{4}\) to \(bt_{1}\), and then clear \(ht_{2}\), \(ht_{3}\), \(bt_{4}\).
8:for each transition \(t_{i}\in T\)do
9: Add the declaration of the variable \(tet_{i}\) with the initial value zero to \(bt_{2}\).
10:if the condition \(\psi_{i}=\Gamma(t_{i})\) assigned to \(t_{i}\) is related to a sensor variable \(in_{i}\)then
11: Add the declaration of the variable \(det_{i}\) to \(bt_{3}\) with the initial value zero.
12:else
13: Add the declaration of the variable \(det_{i}\) to \(bt_{3}\) with the initial value one.
14:endif
15: Add the declaration of the variable \(a_{i}\) to \(bt_{4}\) with the initial value _false_.
16:endfor
17: Add \(ht_{2}\), \(ht_{3}\) and \(ht_{4}\) to \(bt_{1}\).
18:for each place \(p_{i}\in P\)do
19:for each output variable \(out_{k}\) that is set using the statement \(\omega_{i}=\Delta(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:if\(M_{0}(p_{i})>0\)and\(out_{k}\) is set to _true_ in the statement \(\omega_{i}\)then
23: Add the declaration of \(out_{k}\) to \(bt_{1}\) with the initial value _true_.
24:else
25: Add the declaration of \(out_{k}\) to \(bt_{1}\) with the initial value _false_.
26:endif
27:endif
28:endfor
29:endfor
30:for each transition \(t_{i}\in T\)do
31:if the condition \(\psi_{i}=\Gamma(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.
34:endif
35:endfor
36: Return the result of the algorithm: \(bt_{1}\).
```  
**Algorithm 1**Create the declaration of variables