## 4 Proposed Algorithm (NCRA-DP-ACO)
### Pheromone Management
#### 4.2.7 Algorithm
The time complexity of Algorithm 1, which performs initial virtual machine placement across multiple datacenters, is primarily governed by three components: the server availability assessment, execution of the ACO algorithm, and evaluation of candidate placement solutions. For each decision interval across \(D\) datacenters, the algorithm first identifies available PMs, with a worst-case complexity of \(O(m\cdot VM_{max})\), where \(m\) is the number of servers and \(VM_{max}\) is the maximum number of VMs hosted on a single server. It then invokes the ACO algorithm in each datacenter to determine a candidate VM-to-PM mapping, with complexity \(O(ACO(m,n))\), where \(n\) is the number of VMs to be placed. Finally, the algorithm computes the cost of each solution based on the number of servers used (\(m^{\prime}\)) and selects the best-performing datacenter, contributing an additional \(O(m^{\prime})\) and \(O(D)\), respectively. Combining these, the overall time complexity is

\[O\big{(}D\cdot\big{(}m\cdot VM_{max}+ACO(m,n)+m^{\prime}\big{)}\big{)} \tag{26}\]

where \(O(ACO(m,n))\) is defined in Equation (27) and further detailed in Algorithm 2. This algorithm aims to find the optimal placement of VMs on PMs within a distributed computing environment. It utilizes the ACO approach inspired by the foraging behavior of ants. Each PM is initialized with a pheromone value indicating its VM hosting potential. It also establishes an empty \"best solution\" placeholder (Initialization). The algorithm then runs through a predefined number of iterations. In each iteration, several \"ants\" explore the solution space by individually trying to assign VMs to PMs. They consider both the pheromone trails on each PM and their own heuristic preferences (Iterative Improvement). For each VM, an ant finds the most suitable PM based on a combination of pheromone levels and its specific requirements. This process builds a candidate solution for that ant (Solution Construction). If an ant manages to place all VMs onto PMs successfully, its solution is evaluated using an objective function. This function measures the quality of the solution based on desired criteria (Fitness Evaluation). ```
Input:\(PM\),\(VM\) Output:\(S^{best}\) Initialize: \(\tau_{0}=\frac{1}{|PM|}\) \(S^{best}=\emptyset\) I = 1 Compute:  While (\(i<I\)) do \(\mid a=1\) \(\mid\) While (\(a\leq N^{mts}\)) do \(\mid\)\(VM_{new}\) = shuffleList(\(VM_{new}\)) \(\mid\)\(S_{a}=\emptyset\) \(\mid\) For (each \(VM_{j}\) in \(VM_{new}\)) do \(\mid\)\(\mid\)\(PM_{j}^{available}\)= getAvailableServerisforVm(\(VM_{j}\)) \(\mid\)\(\mid\)\(\mid\) If (\(PM_{j}^{available}\) is empty) then \(\mid\)\(\mid\)\(\mid\)\(\mid\) Continue \(\mid\)\(\mid\)\(\mid\)\(\mid\) End \(\mid\)\(\mid\)\(\mid\) For (each \(PM_{i}\) in \(PM_{j}^{available}\)) do \(\mid\)\(\mid\)\(\mid\)\(\mid\) Calculate heuristic information (Equation (14)) \(\mid\)\(\mid\)\(\mid\) End \(\mid\)\(\mid\)\(\mid\) Generate a random number \(q\in[0,1]\) \(\mid\)\(\mid\) If (\(q\leq q_{0}\)) then \(\mid\)\(\mid\)\(\mid\)\(\mid\) Select server \(PM_{i}\) for \(VM_{j}\) (Equation (18)) \(\mid\)\(\mid\)\(\mid\) Else \(\mid\)\(\mid\)\(\mid\)\(\mid\)\(\mid\) Select server \(PM_{i}\) for \(VM_{j}\) (Equation (19)) \(\mid\)\(\mid\)\(\mid\) End \(\mid\)\(\mid\)\(\mid\) If (\(S_{a}\) contains all \(VM_{s}\) in \(VM_{new}\)) then \(\mid\)\(\mid\)\(S_{a}\).objective_value = calculateObjectiveFunctionValue(\(S_{a}\)) \(\mid\)\(\mid\)\(\mid\) If (\(S^{best}==\emptyset\) or \(S_{a}\).objective_value < \(S^{best}\).objective_value) then \(\mid\)\(\mid\)\(\mid\)\(\mid\)\(\mid\) End \(\mid\)\(\mid\)\(\mid\) Do local pheromone updating (Equation (8)) \(\mid\)\(\mid\)\(a=a+1\) \(\mid\) End \(\mid\) If (\(S^{best}\
eq\emptyset\)) then \(\mid\) Do global pheromone update (Equation (9)) \(\mid\) End \(\mid\)\(i=i+1\)  End Return \(S^{best}\)
```
**Algorithm 2**Ant Colony Optimization for VMP

The best solution is to be updated if a superior one is found.