# Mobility-Enabled Edge Server Selection for Multi-User Composite Services
## 4 Edge Server Selection Method
### Multi-User Edge Server Selection Method Based on PSO  
The quantity of alternative edge servers for users increases exponentially with the number of edge server increasing. If the enumeration method is used to select edge servers for users, the complexity is \(O(km^{n})\), where \(k\) is the number of users, \(m\) denotes the average number of candidate servers for invoking single service, and \(n\) denotes the average service number of single-user service composition. The enumeration method will not be practical with the scale of the problem increasing. Thus, a multi-user edge server selection method based on particle swarm optimization is proposed to resolve this problem, called MESP. An approximated optimal decision solution within polynomial time can be obtained by the method.  
The PSO algorithm is a population-based stochastic optimization technique inspired by social behavior or bird flocking [20; 21; 22]. Meanwhile, it has the following advantages: there are only a few parameters that need to be adjusted, which makes it easy to implement; individual local information and group global information are used to search for the optimal decision solution. Therefore, we propose the multi-user edge server selection method based on the PSO. Next, we show how the MESP algorithm is applied to the edge server selection problem.  
In this algorithm, we encode the multi-user server selection process as a particle, and all the particles form a population. The algorithm begins with computing the total waiting time generated by each particle \(x_{i}\), and the current optimal position of each particle is recorded as \(xbest_{i}\) (Lines 2-3). Then, the best swarm position is obtained, and the corresponding total waiting time can be obtained by Equation (9) (Line 5). Next, each particle velocity is updated by Equation (10), and each particle position is updated by Equation (11) (Lines 7-8). After that, if updated particle position \(x_{i}\) is not a feasible decision solution, \(x_{i}\) will be modified by Algorithm 1 (Lines 9-10). Finally, the best swarm position \(gbest\) and minimizing the total waiting time \(fgbest\) is returned.  
\[v_{i}=vw+c_{1}R_{1}(xbest_{i}-x_{i})+c_{2}R_{2}(gbest-x_{i}) \tag{10}\]  
where \(R_{1}\) and \(R_{2}\) are random numbers.  
\[x_{i}=x_{i}+v_{i} \tag{11}\]  
This proposed approach works well only when it has the known path of the mobile users, which means that we know each user's future mobile path so that we can select edge servers for the user in advance. An alternative way to get mobile users' paths is to make use of prediction methods utilized often in wireless mobile computing and communication. In addition, when the user uses the navigation function, we can also get the user's moving path.  
```
Input: original decision solution \(p_{1}\) Output: renewal decision solution \(p_{2}\) \(p_{2}=p_{1}\) while all services are not finished do for each user \(u\)do \(u\) selects edge severs \(S\) according to \(p_{1}\) for each selected server \(s\) in \(S\), do if\(s\) cannot meet the requirement from \(u\)  It randomly selects another server \(s^{\prime}\) that has sufficient remaining capacity \(p_{2}\xleftarrow{s^{\prime}}p_{1}\) endif endfor endwhile return\(p_{2}\)
```  
**Algorithm 1**Renewal algorithm.  
```
Input: iteration times \(it\), constant inertia weight \(w\), cognitive and social parameters \(c_{1},c_{2}\), quantity of particle \(xSize\), initial random particle position and velocity \(x,v\) Output: best swarm position \(gbest\) and minimizing total waiting time \(fgbest\) while not stopping for each particle \(x_{i}\), do  compute response time \(f(x_{i})\) of each particle \(x_{i}\), and set \(xbest_{i}\leftarrow\) best individual particle position endfor \(gbest\leftarrow\) best swarm position, \(fgbest=f(gbest)\) for each particle \(i\)do \(v_{i}\leftarrow\) update particle velocity \(x_{i}\leftarrow\) update particle position if\(x_{i}\) is not feasible \(x_{i}\) is modified by Algorithm 1 endif endfor endwhile return\(gbest,fgbest\)
```  
**Algorithm 2**MESP algorithm.