## 3 The Proposed Resource Consolidation Algorithm  
In this section, we detail the proposed resource consolidation algorithm for nanoscale computing environments. The proposed algorithm is based on the hidden Markov model to predict devices' stability. In other words, when the edge server and the user's device is stable, it determines to use the edge server, while when the edge server or the user's device is unstable, it determines to use the cloud server without edge servers in the system. Algorithm 1 shows the proposed resource consolidation algorithm. The input of the algorithm is the edge server list, the types of services for users' requests, and users' requests. After performing the resource consolidation algorithm, users' requests are allocated to the edge servers or the central cloud server according to the specification of the algorithm. For the initialization, two Boolean variables (_isAllocated_ and _allocateEdge_) are set to false. Then, all the edge servers are also initialized by having no users' requests. Of the two functions (_checkRequests_() and _allocateRequests_(), the _checkRequests_() function is performed first. Inside the function, all the users' requests are checked and counted for the service types and frequency (lines 9-12). This procedure is necessary for the _allocateRequests_() function to allocate requests. Then, the requests are forwarded to the hidden Markov model process (line 11). In the _allocateRequests_() function, the algorithm traverses each element of the users' requests, then performs the treatment of less frequent requests, i.e., the frequency of the service type is counted as one (lines 15-17). For the less frequent services, the proposed resource consolidation algorithm allocates to the central cloud server. This is because, when it is allocated to the edge server, the algorithm introduces additional overheads by downloading appropriate data from the central cloud server. For the frequent services, it first checks the edge servers that are holding the same type of services (lines 19-25). In other words, when an edge server (\(ES_{A}\)) is running a healthcare service and the upcoming request's service type is also the healthcare service, our resource consolidation algorithm allocates the upcoming request to \(ES_{A}\) so that no additional overheads are introduced. Next, the _countrequest_ variable for the edge servers is incremented by 1, and the _isAllocated_ variable is set to true; these two variables are used when the algorithm cannot find the edge server holding the same type of service. If the _isAllocated_ variable is false after performing the procedure of lines 19-25 (it cannot find the edge server holding the same type of service), the _checkHMM_() function is called (lines 26-27). The _checkHMM_() function returns true if its hidden Markov model's maximum probability of \(O\) is to allocate the edge servers. Otherwise, the function returns false (the maximum probability of \(O\) is to allocate the central cloud server). When the _allocateEdge_ variable is true, then it allocates the request to the edge server whose \(count_{request}\) is lowest (lines 28-29). Note that this statement is useful since our resource consolidation algorithm can achieve the load balancing by allocating the request to the low-loaded edge server. Then, its \(count_{request}\) is incremented by one. Otherwise, (_allocateEdge_ is false); it allocates the request to the central cloud server.