## 4 Proposed Algorithm (NCRA-DP-ACO)
### Pheromone Management
#### 4.2.7 Algorithm  
ACO is deployed in this work to solve the problem of VMP across geographically distributed datacenters. Algorithm 1 describes the initial placement strategy, in which ACO selects an appropriate set of PMs for new VMs depending on server availability and cost estimation. The core iterative optimization process is then provided in Algorithm 2, whereby artificial ants investigate and refine placement solutions through pheromone updating and heuristic-guided search. Algorithm 3 monitors each datacenter's hostsand--when utilization thresholds are crossed--collects the VMs to migrate, invokes the ACO-based placement on that set, and issues live migrations to re-optimize the system. ```
Input:\(D\), \(VM_{new}\) Output: Deployment or Failure of VMs Compute:  While (true) do | If (\(VM_{new}\) is not empty) then | solList = new List() // Initialize solution list | | For (each datacenter \(d\) in \(D\)) do | | | \(PM\) = getAvailableServers(\(d\)) // (Equation (12)) | | | \(S_{a}\) = runACO(\(PM\), \(VM_{new}\)) | | | solList = solList.add(\(S_{a}\)) // Combine solutions from all datacenters | | End | If (solList is not empty) then | | | // Step 1: Calculate costs for each solution | | | solutionCostMap = new Map() | | | | For (each solution \(S_{a}\) in solList) do | | | | solutionCost = calculateSolutionCost(\(S_{a}\)) // (Equation (21)) | | | | solutionCostMap.put(\(S_{a}\), solutionCost) | | | | End | | | | // Step 2: Find the best solution | | | | | \(S^{bat}\) = null | | | maxGreenEnergy = \(-1\) | | | solTotalCost = infinity | | | | For (each entry in solutionCostMap) do | | | | \(S_{a}\) = entry.key | | | | | cost = entry.value | | | | | If (cost.usedGreenEnergy > maxGreenEnergy) then | | | | | maxGreenEnergy = cost.usedGreenEnergy | | | | | | | | | | | | | | | | | | | | solTotalCost = cost.totalCost | | | | | | | Else if (cost.usedGreenEnergy == maxGreenEnergy and cost.totalCost < solTotalCost) then | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | End



is initialized to hold the potential placement configurations found during the operations. Then, it goes through each datacenter (\(D\)). For each datacenter, it will obtain the allowable server list (\(PM\)) and apply the ACO algorithm (runACO) to provide a solution (\(S_{a}\)) for placing those VMs on those PMs. The solution \(S_{a}\) is then added to the solList, and this repeats for all datacenters. After all datacenters have given solutions, the algorithm checks whether any solutions have been discovered (\(solList.isNotEmpty()\)). If so, it will calculate the cost for every solution, which includes the green energy used and the total cost. It initializes a solution-CostMap, which is meant to store these costs, and iterates through each solution in solList. For each of the solutions \(S_{a}\), it will calculate its cost in terms of calculateSolutionCost(\(S_{a}\)) and thereafter insert the solution and its cost into solutionCostMap. Then, the algorithm obtains the best solution. It initializes \(S^{best}\), maxGreenEnergy, and solTotalCost. It runs an iteration on each of the entries within solutionCostMap. For each entry, it fetches the solution \(S_{a}\) and its corresponding cost. It prioritizes solutions based on higher green energy usage. Multiple solutions that have the same condition concerning green energy usage will have the total least-cost solution run. After obtaining the best solution (\(S^{best}\)), the algorithm will then create the corresponding VMs based on that solution via createVMsAccordingTo(\(S^{best}\)). For failures in the result, the algorithm would conduct this via failVms(\(VM_{new}\)) if no appropriate solutions occur (\(solList.isEmpty()\)) or if there are no VMs to begin with (\(VM_{new}.isEmpty()\)). The entire process will repeat cyclically.