## 4 Proposed Algorithm (NCRA-DP-ACO)
### Pheromone Management
#### 4.2.7 Algorithm
This ensures the algorithm continuously improves its findings throughout the iterations (Best Solution Update). After all ants have completed their exploration, the pheromone levels on PMs are updated. This update mechanism strengthens trails associated with the best solutions and weakens those linked to less successful ones, guiding future ants towards promising directions (Pheromone Updates). By running through these steps repeatedly, the algorithm gradually converges towards a near-optimal placement of VMs across the available PMs, balancing individual VM requirements with overall system efficiency. The time complexity of the proposed ACO algorithm can be derived by analyzing its nested loop structure. For each of the iterations, the algorithm launches \(N^{\text{ants}}\) ants. Each ant constructs a complete placement solution by iterating over the set of \(VM_{\text{new}}\). For every VM, the algorithm evaluates a subset of available PMs, which in the worst case includes all \(|PM|\) servers. Within this process, heuristic information is computed, and server selection is performed based on a probabilistic rule. Therefore, the overall time complexity is expressed as in Equation (27). \[O\big{(}I\cdot N^{\text{ants}}\cdot n\cdot m\big{)} \tag{27}\]

where \(n\) is the number of requested VMs, and \(m\) is the total number of PMs. ```
Input: D Compute:  While (true) do \(|\) For (each datacenter \(d\) in \(D\)) do \(|\) vmlistToMigrate = new List() \(|\) For (each \(PM_{i}\) in getAvailableServers(d)) do \(|\) \(|\) \(|\) If \(\big{(}PM_{i,u}^{CPU}>Th^{\text{ocr}}\big{)}\) then \(|\) \(|\) \(|\) vmlList = getMigrationVMs(\(PM_{i}\)) \(|\) \(|\) \(|\) \(|\) vmlistToMigrate.addAll(vmList) \(|\) \(|\) \(|\) End \(|\) \(|\) \(|\) If \(\big{(}PM_{i,u}^{CPU}\leq Th^{\text{uncr}}\big{)}\) then \(|\) \(|\) \(|\) \(|\) vmlist = getAllVMs(\(PM_{i}\)) \(|\) \(|\) \(|\) \(|\) \(|\) vmlistToMigrate.addAll(vmList) \(|\) \(|\) End \(|\) \(|\) End \(|\) \(|\) If (vmlistToMigrate is not empty) then \(|\) \(|\) \(|\) \(S_{a}\) = runACO(\(PM\), vmlistToMigrate) \(|\) \(|\) \(|\) If (\(S_{a}\
eq\emptyset\)) then \(|\) \(|\) \(|\) \(|\) MigrateVMs(\(S_{a}\)) \(|\) \(|\) \(|\) End \(|\) End End
```

**Algorithm 3**Dynamic Placement

This dynamic VM placement algorithm is designed to continuously monitor and optimize the placement of VMs across multiple datacenters, with the goal of achieving balanced resource utilization and preventing server over- or underutilization. Algorithm 3 iterates through each datacenter in the system. For each datacenter, the algorithm initializes an empty list called vmlistToMigrate. This list will be used to store VMs that need to be migrated for optimization purposes. Next, the algorithm iterates through each PM within the datacenter that is allowed for VM placement. It evaluates the CPU utilization of each PM and performs the following checks:

If the CPU utilization of the PM exceeds a certain threshold (\(Th^{order}\)), it indicates that the server is overloaded. In this case, the algorithm retrieves a list of VMs that can be migrated from the PM using the getMigrationVms() function. The VMs obtained from getMigrationVms(\(PM_{i}\)) are then added to the vmlistToMigrate. If the CPU utilization of the PM falls below another threshold, (\(Th^{under}\)), it suggests that the server is underloaded. The algorithm retrieves all the _VMs_ placed on that PM using the getAllVms() function and adds them to the vmlistToMigrate. After evaluating all the PMs within the datacenter, the algorithm checks if the vmlistToMigrate is empty. If there are VMs on the list, it proceeds to optimize the placement. The optimization attempt involves leveraging the ACO algorithm. If the ACO algorithm generates a non-empty solution (\(Sa\)), it means that an optimization opportunity has been identified. The algorithm then executes the recommended VM migrations using the MigrateVMs() function, effectively moving the VMs to their new optimized placements and turning PMs into standby mode wherever necessary.