## 4 Configuration/Scheduling Feasibility Problem and Context Generation Problem in CPS
An algorithm to transform a DTPN \(\Psi_{n}\) to a graph \(DG_{n}(V_{n},E_{n})\) is proposed in Algorithms 1 as follows:  
```
Input : \(\Omega_{n}^{k},\,K_{n},\,A_{n\theta}^{k},\,R_{n}^{k},\,T,\,\theta,\,m_{n0}^{k} \left(p_{n}^{ki}\right)=Q,\,\Phi\), where \(\Phi\) is greater than \(0\) Output : \(DG_{n}(V_{n},E_{n})\) Step 1: Construct a source node \(S\) and a sink node \(U\) Step 2: Construct a \((K_{n}+1)\times T\) matrix of nodes, numbered from \(1\) to \((K_{n}+1)\times T\). Step 3: For \(k\in\{1,2,\ldots,K_{n}+1\}\) For \(t\in\{1,2,\ldots,T-1\}\) Add an arc connecting node \(t+(k-1)T\) to node \(t+(k-1)T+1\) Assign arc capacity \(u_{nkt}^{k}=0\) to arc \((s,1)\) Assign arc cost \(u_{nkt}^{k}=0.0\) to the arc \((t+(k-1)T,t+(k-1)T+1)\) Create a flow variable \(h_{nkt}\) for the arc \((t+(k-1)T,t+(k-1)T+1)\) End For End For Step 4 : For \(k\in\{1,2,\ldots,K_{n}\}\) For \(t\in\{1,2,\ldots,T-1\}\) Add an arc \(\left(t+(k-1)T,t+kT+p_{n}^{k}\left(t_{n}^{k}\right)+p_{n}^{k}\left(t_{n}^{k} \right)\right)\) connecting node \(t+(k-1)T\)to node \(t+kT+\mu_{n}^{k}\left(t_{n}^{k}\right)+\mu_{n}^{k}\left(t_{n}^{k}\right)\) Letadenote resource agent to perform the \(k-th\)activity Assign arc capacity \(u_{nkt}^{w}=m_{n0}^{k}(r_{nak})\) to arc \(\left(t+(k-1)T,t+kT+\mu_{n}^{k}\left(t_{n}^{k}\right)+\mu_{n}^{k}\left(t_{n}^ {k}\right)\right)\) Assign arc \(\cos\,\mathrm{t}\,c_{n0}^{w}=0.0\) to the arc \(\left(t+(k-1)T,t+kT+\mu_{n}^{k}\left(t_{n}^{k}\right)+\mu_{n}^{k}\left(t_{n}^ {k}\right)\right)\) Create a flow variable\(w_{nkt}\)for the arc \((t+(k-1)T,t+(k-1)T+1)\) End For Step 5: Add an arc from node \(S\) to node \(1\) Assign arc capacity \(u_{n0}=m_{n0}^{k}\left(p_{n}^{ki}\right)\) to arc \((s,1)\) Assign arc \(\cos\,\mathrm{t}\,c_{n0}=0.0\) to the arc \((s,1)\) Create a flow variable \(f_{n0}\) Assign flow to \(f_{n0}=m_{n0}^{k}\left(p_{n}^{ki}\right)\) Step 6 : For \(t\in\{1,2,\ldots,T\}\) Add an arc \((K_{n}T+t,U)\)connecting node \(K_{n}T+t\) to node \(U\) Assign arc capacity \(u_{nt}^{t}=m_{n0}^{k}\left(p_{n}^{ki}\right)\) to arc \((K_{n}T+t,U)\) Assign arc \(\cos\,\mathrm{t}\,c_{nt}^{l}=\Phi\) to the arc \((K_{n}T+t,U)\), where Create a flow variable \(l_{nt}\) for the arc \((K_{n}T+t,U)\) End For
```  
**Algorithm 1****DTPN to Graph Transformation (DTPN2 GT) Algorithm**  
As the tokens must conserve, the following capacity constraints (defined in (1)) and flow balance constraints (defined in (2)-(9)) must be satisfied:  
\[\sum_{\tau=t}^{t+\gamma_{nn}^{k}-1}w_{nkt}\leq m_{n0}^{k}(r_{a})\ \forall k\in\{1,\,2,\,\ldots,\,K_{n}\}\forall t\in\left\{1,\,2,\,\ldots,\,T- \gamma_{nn}^{k}\right\} \tag{1}\]  
\[h_{nk(t-1)}=h_{nkt}+w_{nkt}\quad\forall k\in\{1\}\forall t\in\{2,\,\ldots,\,T\} \tag{2}\]  
Figure 3:0Figure 3:1  
Figure 3:2  
Figure 3:3  
Figure 3:4  
Figure 3:5  
Figure 3:6  
Figure 3:7  
where \(Z\) is the set of nonnegative integers and \(\gamma_{nn}^{k}=\mu_{na}^{k}\left(t_{ns}^{k}\right)+\mu_{na}^{k}\left(t_{ne}^{k }\right)\). **Definition 6**. : \(DG_{n}(V_{n},E_{n})\) _denotes a graph model constructed by applying the D2 GT algorithm to \(\Psi_{n}\) and satisfies constraints (1) through (9)._  
Figure 11a-c show the graph models corresponding to the DTPN models in Figure 9a-c, respectively. Figure 3:8 Cont. Note that \(\Psi_{n}=\left(P_{n},T_{n},F_{n},m_{n0},\mu_{n}\right)=\|_{k\in\{1,2,\ldots,K_{n}\} }\left(\Omega_{n}^{k}\right\|_{a\in R_{n}^{k}}A_{nn}^{k}\right)\), where \(\Omega_{n}^{k}=\left(P_{n}^{k},T_{n}^{k},F_{n}^{k},m_{n0}^{k},\mu_{n}^{k}\right)\) and \(P_{n}^{k}\)=\(P_{n}^{ki}\cup\left\{P_{n}^{kb}\right\}\cup\left\{P_{n}^{kb}\right\}\). Therefore, the number of tokens, \(m_{nt}(p)\), in place \(p\in P_{n}^{ki}\) at period \(t\) can be represented by \(h_{nt}\) for \(t\in\{1,2,3,\ldots,T\}\). The number of tokens, \(m_{nt}(p)\), in place \(p\in P_{n}^{kb}\) at period \(t\) can be represented by \(w_{nt}\) for \(t\in\{1,2,3,\ldots,T\}\).