## 5 Problem Formulation
### Problem Description  
One problem is finding out an optimal composite service of ERP on IoT-Fog-Cloud infrastructure for minimizing energy consumption while optimizing customer QoS (i.e., response time, reliability, and security). To solve the problem, we use a three stages approach. First, we generate the virtual composite service (VCS), which includes all needed functional business tasks. Secondly, a multi-agent intelligence research algorithm gives all the possible composite service chains providing VCS. The optimal composite service solution is based on multi-objective QoS and energy-saving functions. Finally, we adapt the current composite service for incoming new customer's needs and/or context changes, including device power consumption. The problem is formalized as follows:  
* The required workload \(W_{N}^{required}\) is the total energy to be consumed while \(S_{i}\) is invoked on node \(N\). \[W_{N}^{required}=W_{N}^{current}+S_{i}^{Energy}\] (4)
* The consumption rate \(R_{N}^{i}\) of service \(S_{i}\) on node \(N\) is defined as follows: \[R_{N}^{i}=\left\{\begin{array}{ccc}\frac{Capacity_{N}}{Capacity_{N}-W_{N}^{ required}}&if&Capacity_{N}>W_{N}^{required}\\ \infty&otherwise\end{array}\right.\] (5) where \(f_{energy}^{i}\) is considered a negative attribute that will be minimized and the service \(S_{i}\) on a node, \(N\) is considered infeasible when \(R_{N}^{i}=\infty\).
* The energy function of the CCS: \(f_{energy}(CCS)=agg\Big{(}f_{energy}^{i}\Big{)}\), is calculated according to Table 3 where \(i\) varies from \(1\) to \(m\). \[f_{energy}^{i}=S_{i}^{Energy}+R_{N}^{i}\] (6)
* Each CCS is evaluated by combining the normalized QoS values of IoT, Fog, and Cloud services via Table 3. The total QoS are normalized by the following equations: \[q_{j}^{\prime}(CCS)=\left\{\begin{array}{ccc}\frac{agg(q_{j})-agg\big{(}q_ {j}^{\min}\big{)}}{agg\big{(}q_{j}^{\max}\big{)}-agg\big{(}q_{j}^{\min}\big{)} }&\text{If}&agg\Big{(}q_{j}^{\max}\Big{)}\
eq agg\Big{(}q_{j}^{\min}\Big{)} \\ 1&\text{Otherwise}\end{array}\right.\] (7) \[q_{j}^{\prime}(CCS)=\left\{\begin{array}{ccc}\frac{agg\big{(}q_{j}^{\max} \big{)}-agg\big{(}q_{j}\big{)}}{agg\big{(}q_{j}^{\max}\big{)}-agg\big{(}q_{ j}^{\min}\big{)}}&\text{If}&agg\Big{(}q_{j}^{\max}\Big{)}\
eq agg\Big{(}q_{j}^{\min} \Big{)}\\ 1&\text{Otherwise}\end{array}\right.\] (8) \(agg\Big{(}q_{j}^{\max}\Big{)}\): The highest combined score of the \(j^{th}\) QoS criterion of CCS, \(agg\Big{(}q_{j}^{\min}\Big{)}\): The lowest combined score of the \(j^{th}\) QoS criterion of CCS. \(agg\big{(}q_{j}\big{)}\): The combined score of the \(j^{th}\) QoS criterion of CCS.  
We define multi-objective functions (\(f_{energy},f_{QoS}\)) to minimize the total energy and maximize the total quality of service of the CSS as follows:  
\[\text{Find }CCS\ with\left\{\begin{matrix}\min_{energy}(CCS)\\ \max f_{QoS}\ (CCS)\end{matrix}\right. \tag{9}\]  
where \(f_{energy}(CCS)\)_and \(f_{QoS}(CCS)\)_ are the energy aggregated function of the \(CCS\) and QoS aggregated function respectively.  
And \(f_{QoS}(CCS)=\sum\limits_{j=1}^{nb}w_{i}\times\text{qos}_{ccs}^{j}\) where: the dimension of QoS.  
Equation (10) defines the final score by combining the energy and QoS of each \(CCS\):  
\[score(CCS)=\sum\limits_{j=1}^{nb}w_{i}\times qos_{ccs}^{j}+w_{energy}\times energy _{ccs} \tag{10}\]