## 7 Context Generation Algorithm  
Generation of contextual information takes place after the negotiation process of multi-level contract net protocol is finished and the proposals submitted by relevant process agents have been accepted. Note that only a process agent that has found a feasible solution for Problem 3 will create a PRO message and submit it to the downstream process agent. If the PRO is accepted by the downstream process agent, the context generation algorithm will be invoked to generate the contextual information based on the solution found by the process agent. That is, only the set of process agents with their PRO message being accepted will enter the step of context generation.  
Based on the models and theory developed in the previous section, the context generation algorithm will be proposed in this section.  
For a process agent that has found a feasible solution for Problem 3 and submitted a proposal that has been accepted by the downstream process agent, the solution found in the course of solving Problem 3 will be used as the input to the context generation algorithm. The context generation algorithm extracts the information to generate the calendars for relevant resource agents from the solution, including start transition/end transition and timing information, etc. The information generated by the context generation algorithm is formatted in XML. Algorithms 2 shows the context generation algorithm.  
```
Input : \(T\), \(K_{n}\), \(A_{n}^{k}\), the solution \(h_{nkt}\), \(w_{nkt}\) and \(l_{nt}\) found based on \(DG_{n}(V_{n},E_{n})\) Output : Context Information, XML\(\_\)Calendar\({}_{a}\), for each resource Step 1 : For each \(t\in\{1,2,\ldots,T\}\)  For each \(k\in\{1,2,\ldots,K_{n}\}\)  If \(w_{nkt}>0\) \(t_{ns}^{k}\leftarrow\) Start transition of \(A_{nn}^{k}\) \(t_{ne}^{k}\leftarrow\) End transition of \(A_{nn}^{k}\)  Assign time slot \([t\)\(t+\mu_{n}^{r}(t_{sk})+\mu_{n}^{r}(t_{ek})]\) to calendar of agent \(a\) \(Activity.Workflow1D\gets n\) \(Activity.StartTransition\gets t_{ns}^{k}\) \(Activity.EndTransition\gets t_{ns}^{k}\) \(Activity.StartTime\gets t\) \(Activity.EndTime\gets t+\mu_{n}^{r}(t_{sk})+\mu_{n}^{r}(t_{ek})\) \(Calendar_{a}\gets Calendar_{a}\cup Activity\) End If End For End For Step 2 : For each \(t\in\{1,2,\ldots,T\}\)  For each resource agent \(a\)  If \(Calendar_{a}\
eq\Phi\)  Create XML file \(XML\_\)Calendar\({}_{a}\)  End If End For End For
```  
**Algorithm 2 Context Generation Algorithm**  
Although the XML includes the contextual information for guiding resource agents, it is not suitable for providing information to users. These xml files must be transformed into other formats to provide proper GUI for users. Therefore, a GUI transformation procedure is developed to transform the contextual information in XML format to present the information to users. Table 2 shows the two steps to transform the contextual information into GUI. In this paper, we apply eXtensible Stylesheet Language (XSL) Transformations (XSLT) to transform XML files into html files to present the contextual information to users. XSL is a styling language for XML which can be applied to design GUI [44]. The GUI transformation procedure shown in the Table 2 consists of two steps. The first step is done off-line whereas the second step is done on-line. For the first step, the XSLT code mustbe designed. For the second step, we will illustrate the XSLT code by an example in the next section.