## 4 Proposed Resource Allocation Scheme
### Tradeoff between Customer Satisfaction and Service Provider Profit
#### 4.3.2 Profit Optimization Under a Satisfaction Target  
This strategy is for service providers who aim to maximize profit while maintaining a minimal satisfaction level that is the QoS of the request, \(q_{r}\). Among all incoming requests from the RRHS to a BBU pool, that request will be scheduled or executed on the BBU \(b\in B\) that ensures the maximum profit by using the computational resources available to the service provider by maintaining a minimum user satisfaction level.  
In Algorithm 2, the incoming requests are sorted according to their priorities. After that, each request is assigned to the BBU, focusing on minimizing the cost and maximizing the profit. For that, to reduce the BBU rental cost in the current scheduling interval, this algorithm calculates the remaining time of a BBU to become free after processing the request which was scheduled on the most recent scheduling interval. So, the total time to get a response from a BBU \(b\in B\) after executing a currently scheduled request, \(r\in R\), on that BBU is enumerated as the time required by BBU to become free plus the execution time to execute that request. The time required a BBU to become free after finishing the execution of a running request is calculated as:  
\[t_{f}^{b}=t_{r-1}^{a}+\zeta_{(r-1),b}-t^{c}, \tag{15}\]where \(t_{r-1}^{a}\) denotes the time when the currently running request arrives, \(\zeta_{(r-1),b}\) is the required time to process the request, and \(t^{c}\) represents the current time. If a BBU, \(b\in B\), currently does not process any request, then the value of \(t_{f}^{b}\) is considered to be 0. As a consequence, the total time to get a response from a BBU is represented as:  
\[\zeta_{r,b}^{*}=t_{f}^{b}+\frac{d_{r}}{\eta_{b}} \tag{16}\]  
where \(d_{r}\) is the request data to be processed, and \(\eta_{b}\) is the processing capacity of the BBU \(b\in B\). If the value of \(\zeta_{b,r}^{*}\) is less than or equal to the corresponding requests QoS requirement, \(q\)\(\alpha\)\(s_{r}\), then the request \(r\in R\) is assigned to BBU \(b\in B\) rather than renting another BBU. As a result, the BBU renting cost of BBU for this request \(r\in R\), \(\mu_{r,b}\) becomes 0. After that, using Equation (4), the profit gain from a particular request for executing on a BBU \(b\in B\) is calculated. Therefore, the request providing highest profit to be executed on BBU \(b\in B\) is selected to be provisioned.  
```
1:Weighted priority of each incoming request, \(w_{r}\in B\), processing capacity of all BBUs, \(\eta_{b},\forall b\in B\).
2:Sort the incoming requests in decreasing order according to the value of \(w_{r}\)
3:for each request \(r\in R\) in the sorted array of requests do
4:\(\rho_{r}=0\) and \(\Upsilon_{b}=0\)
5:for each BBU \(b\in B\) in the sorted array do
6:\(h_{b}\) is the corresponding rental cost of the BBU, \(b\)
7: Calculate \(t_{f}^{b}\) and \(\zeta_{r,b}^{*}\) using Equation (15) and Equation (16), respectively
8:if\(\zeta_{r,b}^{*}\leq q_{r}\)then
9:\(\xi_{r}=\zeta_{r,b}^{*}\) and \(h_{b}=0\)
10:else
11:\(\zeta_{r}=\frac{d_{r}}{\eta_{b}}\)
12:endif
13: Calculate the profit \(\rho_{r,b}\) using Equation (4)
14:if\(\rho_{r,b}\geq\rho_{r}\)then
15:\(\rho_{r}=\rho_{r,b}\)
16:\(\Upsilon_{b}=b\)
17:endif
18:endfor
19: Select request \(r\in R\) to be executed on the BBU, \(\Upsilon_{b}\)
20:endfor
```  
**Algorithm 2** First Fit Profit Algorithm for Maximizing Service Provider Profit  
The complexities of the proposed algorithms are quite straightforward. Firstly, in order to sort the set of incoming resource requests \(R\) in descending order in line 2 of both Algorithms 1 and 2, we use a merge sort algorithm which has the worst-case complexity of \(O(|R|\log|R|)\). The statements in lines 5-12 in Algorithm 1 and lines 5-14 in Algorithm 2 are enclosed in a loop that iterates \(|B|\) times. The rest of the statements have constant unit time complexities. Therefore, the worst-case computational complexity of the algorithms is \(O(|R|^{B})\).