## 6 The Framework
### Detailed Algorithms
* **Step 4. Merge and evaluate local optimal business process. ** Merging and comparing the fitness value of local BPs of each agent with the other BPs of another agent. Based on largest fitness value, the global composite service is selected. **Stage 3. Adaptive Strategy for re-composition of services:** Generally, the proposed approach is designed to be able to perform in two modes: Dynamic or Adaptive cases when context changes are present or not. We compute the adaptation cost in terms of energy and QoS difference between the current optimal \(CCS_{\_}t\) and new \(CCS_{\_}t+1\), with desired services to be added or deleted in order to manage context changes. More precisely, the list of services to be added is \(S_{\_}{add}\) and the list of services to be deleted is \(S_{\_}{del}\). The next \(CCS_{\_}t+1\) contains \(\overline{CCS_{\_}t}\cup S_{\_}{add})\cap S_{\_}{del}\). So, the multi-objective function of Equation (13) will include the third objective, which is the adaptation cost of newly added services and/or the cost of removed existing services in terms of energy and QoS. The new multi-objective function is defined in Equation (13). \[\text{Find }CCS\ with\left\{ \begin{array}{l}\min_{\_}{fengy}(CCS_{\_}t+1)\\ \max_{\_}{fQoS}(CCS_{\_}t+1)\\ \min_{\_}{fcost}(CCS_{\_}t+1-CCS_{\_}t)\end{array} \right. \tag{13}\]  
where \(CCS_{\_}t+1-CCS_{\_}t\) is the difference between the current optimal \(CCS\) and new \(CCS\) according to the same VBP, since the existing optimal VBP does not change. The detailed process is described as Algorithm 1 and illustrated in Figure 10.  
```
Inputs: agent_pop_size, max_itr, populations Outputs: P. OP: Pareto optimal solutions
```
1: Generate initial agent populations as a set of CCS;
2:P_OP \(\leftarrow\)\(\emptyset\)
3:Iteration \(\leftarrow\)0;
4:while (Iteration \(\leq\) max_itr ) do
5: Fork (agent using agent_pop in populations)
6: Evaluate the objective functions (QoS and Energy) for each individual;
7: Local Pareto optimal \(\leftarrow\) Select best individuals by agent_pop;
8:P_OP \(\leftarrow\) P_OP U Local Pareto optimal
9:s \(\gets\) 0
10:while (s \(\leq\) agent_pop/2) do
11: (P\({}_{1}\),P\({}_{2}\)) \(\leftarrow\) select two individuals parents of current agent_pop;
12: (C1,C2) \(\leftarrow\) Crossing both parents (P\({}_{1}\),P\({}_{2}\)) to obtain two children;
13: agent_pop.add(C1); agent_pop.add(C2);
14:s \(\leftarrow\) s + 1;
15:end
16:s \(\gets\) 0
17:while (s \(\leq\) agent_pop/2) do
18:new_ind \(\leftarrow\) mutate children(ind);
19:agent_pop.add(new_ind);
20:s \(\leftarrow\) s + 1;
21:end
22:end
23:P_OP \(\leftarrow\) Selection of optimal solution from all local Pareto-Optimal;
24: Update new global Pareto optimal solutions for all agents;
25:Iteration++;
26:end ```
**Algorithm 1**Parallel NSGAII strategy for dynamic Cloud services composition  
The pseudo-code of the semantic context broker algorithm in adaptive intelligent strategy is illustrated in Algorithm 2. At first, the semantic context broker keeps up with the context changes. It then calls the _SCwA-IFCCS_ Agent, which in turn calls _ERP-ICS_ and _ERP-FCS_ agents for discovering services. It ends with sending the services list to the _ERP-CCS-3S_ Agent. The _ERP-CCS-3S_ Agent selects the optimal composite service as the optimal fragment according to the customer's preferences, and then recomposes it with the current composite service, subsequently sending it to the service deployer. Finally, the optimal composite service fragment is deployed and results are returned to customer. Considering an existing production _CCS_ while monitoring services as a fragment of BP (see Figure 2) and the new monitoring IoT-BP generated by the adaptive multi-agent and NSGA-II algorithm (Figure 11), the adaptation cost is the cost of adapting existing BP to IoT-BP while considering only such a fragment. In this case, we need to add three services: new sensed temperature service (S1), receive temperature service (S1), and control temperature service (S3) of final products, and remove service monitoring (S'3).