# Traffic Offloading in Unlicensed Spectrum for 5G Cellular Network: A Two-Layer Game Approach
## 4 Coalition Game
### Station Allocation Algorithm  
Firstly, we use some notations to simplify our expressions: \(n_{j,a}(j\in[1,K_{a}])\) means the number of stations which will be transferred from the overloaded \(AP_{j}\) and \(n_{w,s}(w\in[1,K_{s}])\) indicates the number of stations which could handover to the \(AP_{w}\) (the AP which only has few stations). In addition, there are \(K_{s}(K_{s}\in[1,K])\) light-loaded APs and \(K_{a}(K_{a}\in[1,K])\) APs are overloaded (\(K_{s}+K_{a}=K\)). Then, the station allocation problem is shown in Algorithm 1 when there are many APs in the coalition and have the same channel condition and priority.  
```
1:\(\overline{w}\) indicates the subscript of the AP with lightest load and \(\overline{j}\) denotes the serial number of the AP with the heaviest load in this coalition.
2:Initialization: \(\overline{w}=0\), \(\overline{j}=0\).
3:loop
4:while\(n_{w,s}<n^{*}\)do
5:\(\overline{w}=min\{n_{1,s},n_{2,s},...,n_{w,s}\}\)
6:if\(K_{a}=0\) and \(K_{s}>1\)then
7:if\(\left\lceil\frac{\Sigma_{w}n_{w,s}}{n^{*}}\right\rceil<K_{s}\)then
8: transfer stations in \(AP_{\left\lceil\frac{\Sigma_{w}n_{w,s}}{n^{*}}\right\rceil_{+1}},...,AP_{ \left\lceil\frac{\Sigma_{w}n_{w,s}}{n^{*}}\right\rceil}\)
9:else
10:if\(K_{a}>1\), \(K_{s}>1\) and \(\sum_{j}n_{j,a}>\sum_{w}n_{w,s}\)then
11:\(\overline{j}=max\{n_{1,a},n_{2,a},...,n_{j,a}\}\)
12:endif
13: transfer one station from \(AP_{\overline{j}}\) to the \(AP_{\overline{w}}\)
14:endif
15:\(n_{j,a}=n_{j,a}-1\)
16:\(n_{w,s}=n_{w,s}+1\)
17:endif
18:endwhile
19:endloop
20:Output station allocation results
```  
**Algorithm 1** Station Allocation Algorithm.  
**Theorem 2**: _If \(K_{a}>1\), \(K_{s}>1\) and \(\sum_{j}n_{j,a}>\sum_{w}n_{w,s}\), \(AP_{w}\) would help the AP which has more stations preferentially and reduce the differences in each \(AP_{j}^{\prime}s\) station number._  
If \(K_{a}>1\), \(K_{s}>1\) and \(\sum_{j}n_{j,a}>\sum_{w}n_{w,s}\), the throughput after coalition game would increase but cannot reach the optimal value. As we discussed in Section 2.2, the WiFi throughput function \(R\) is a quasi-concave function, which means when the station number is larger than \(n^{*}\), the throughput would decrease with the station number \(n\). To maximize the system performance, the station number in each AP should close to \(n^{*}\) as much as possible. Thus, \(AP_{k}\) should compare the station numbers every time when it onloads data and makes the final station number in every AP to an equal value as much as possible.  
If \(K_{a}>1\), \(K_{s}>1\) and \(\sum_{j}n_{j,a}<\sum_{w}n_{w,s}\), \(AP_{\overline{j}}\) would transfer its stations preferentially to the AP which has less stations and reduce the differences in each \(AP_{w}^{\prime}s\) station number.  
If there are both heavy-loaded APs and light-loaded APs in a coalition, when the station number is less than \(n^{*}\), the throughput function is an increasing function of the station number \(n\). Similar to the proof in Theorem 2, balancing the station numbers among \(AP_{w}s\) is the first choice of optimizing system performance.