*3.2. MEC Computation Model*

Based on the objective function in Equation (16) and constraints in Equations (17) and (18), the requests of the MEC buffer M*<sup>t</sup>* can be obtained. This section describes the mathematical models used for the computation of M*<sup>t</sup>* .

To compute more bits, the MEC server increases the CPU frequency *f <sup>t</sup>* according to Equation (9). However, an increase in the amount of computation results in increased energy consumption, which affects the battery life according to Equation (13).

To maximize the profit of the EH MEC system, it needs to offload more bits. However, it is impossible to maintain the maximum CPU frequency due to constraints on the battery in the EH MEC system. Therefore, the frequency scheduling of the MEC scheduler aims to maximize both the profit and battery stability.

To model the battery stability, a virtual queue *Z<sup>t</sup>* is introduced. *Z<sup>t</sup>* represents the amount of uncharged battery. Based on the definition of *B<sup>t</sup>* , *<sup>Z</sup><sup>t</sup>* is greater than or equal to 0, i.e., 0 ≤ *<sup>Z</sup><sup>t</sup>* < +∞. Based on Equation (4), the following equation is derived:

$$Z^{t+1} = (Z^t + E\_{\text{offload}}^t - \varepsilon^t)^+, \ t \in \mathcal{T},\tag{19}$$

where

$$
\mathfrak{a}^+ \triangleq \max\left(0, \mathfrak{a}\right). \tag{20}
$$

Note that the battery should always be stable. Therefore, one constraint on the battery stability can be derived as follows:

$$\lim\_{t \to \infty} \frac{1}{t} \sum\_{\tau=0}^{t-1} \mathbb{E}[Z^{\tau}] < +\infty \tag{21}$$

The number of CPU cycles needed to execute *x<sup>t</sup> <sup>i</sup>* successfully is denoted as *W*M,*i*, and it can be obtained in a similar manner as that in Equation (8). Accordingly, the required number of execution instructions at the MEC server at time *t*, which is denoted as *I<sup>t</sup>* , can be obtained as follows:

$$I^t = \sum\_{i=1}^{M} W\_{\mathcal{M}, i\prime} \tag{22}$$

where 0 ≤ *<sup>I</sup><sup>t</sup>* ≤ *<sup>f</sup>*max.

Based on the defined notations, the number of execution cycles from the MEC buffer at time *t* can be obtained as

$$Q^t = \min(I^t, f^t). \tag{23}$$

A mathematical approach for maximizing the time-averaged expected number of execution cycles from the MEC buffer can be obtained as follows:

$$\text{maximize} \lim\_{t \to \infty} \frac{1}{t} \sum\_{\tau=0}^{t-1} Q^{\tau}. \tag{24}$$

Assuming that the computation frequency of the MEC server can be changed dynamically, the frequency scheduling vector can be defined as

$$\overrightarrow{f}^{t} = [f\_1^t, f\_2^t \cdot \cdots \cdot f\_k^t]\_\prime \tag{25}$$

where *k* is the number of frequency selections and *f <sup>t</sup> <sup>i</sup>* is an indicator function: if its frequency is selected, *f <sup>t</sup> <sup>i</sup>* = 1; otherwise, *<sup>f</sup> <sup>t</sup> <sup>i</sup>* = 0. Since the MEC should select only one frequency at *t*, the following constraints are derived:

$$\forall t \in \{0, \dots, \infty\}, \tag{26}$$

$$\sum\_{i=1}^{k} f\_i^t = 1,\tag{27}$$

$$f\_i^t \in \{0, 1\}. \tag{28}$$

Moreover, the selected frequency should guarantee the request deadline. Therefore, the minimum frequency scheduling vector required to guarantee all the request deadlines is denoted as *kth*, and the following constraints can be derived:

$$\sum\_{i=1}^{k^{th}-1} f\_i^t = 0,\tag{29}$$

$$\sum\_{i=k^{\text{th}}}^{k} f\_i^t = \mathbf{1}\_{\text{'}} \tag{30}$$

and Equation (27) can be replaced by Equations (29) and (30).

To change −→*<sup>f</sup> <sup>t</sup>* into a scalar value, this paper introduces the frequency selectable vector −→*<sup>F</sup>* , which is defined as follows: −→*<sup>F</sup>* = [*F*1, *<sup>F</sup>*2, *<sup>F</sup>*3, ···, *Fk*]. (31)

$$
\overrightarrow{F} = [F\_1, F\_2, F\_3, \dots, F\_k].\tag{31}
$$

Then, *f <sup>t</sup>* can be calculated as

$$f^t = \overrightarrow{f}^t \cdot (\overrightarrow{F})^T.\tag{32}$$

Accordingly, Equations (20) and (24) are, respectively, modified as follows:

$$Z^{t+1} = Z^t + E^t\_{\text{offload}}[f^t] - e^t, t \in \mathcal{T},\tag{33}$$

$$\text{maximize } \lim\_{t \to \infty} \frac{1}{t} \sum\_{\tau=0}^{t-1} Q^{\tau}[f^{\tau}]. \tag{34}$$

Finally, the objective function, considering both the MEC buffer and battery stability, can be obtained as follows:

$$\text{maximize } \lim\_{t \to \infty} \frac{1}{t} \sum\_{\tau=0}^{t-1} Q^{\tau}[f^{\tau}]\_{\tau} \tag{35}$$

subject to

$$\lim\_{t \to \infty} \frac{1}{t} \sum\_{\tau=0}^{t-1} \mathbb{E}[Z^{\tau}] < +\infty. \tag{36}$$

#### **4. Proposed Scheduling Algorithm**

#### *4.1. Computation Offloading Scheduling*

In Section 3.1, the mathematical models and optimization problem are designed. As shown in Equation (11), *D<sup>t</sup> schedule* is a function of *<sup>s</sup><sup>t</sup> <sup>r</sup>*. The constraint of the task deadline in Equation (12) is non-convex since there exists a multiplication of the function *D<sup>t</sup> schedule* by *<sup>s</sup><sup>t</sup> <sup>r</sup>*. Therefore, the proposed optimization problem for offloading scheduling is NP-hard and cannot be solved in non-deterministic polynomial time. To solve this problem, this paper presents a novel greedy scheduling algorithm for obtaining approximate solutions.

Algorithm 1 presents the proposed greedy algorithm for offloading scheduling. The greedy algorithm consists of offloading request sorting and offloading request scheduling. First, the sequence of offloading request scheduling based on offloading request sorting is determined. The scheduling sequence is determined based on the deadline of the requests. From Equations (11) and (12), it is obvious that a computation request having a longer deadline in the MEC buffer will be satisfied if a request with a shorter deadline is satisfied. Therefore, the proposed algorithm sorts R*<sup>t</sup>* in the descending order of *d<sup>t</sup> <sup>i</sup>* (Line 1 in Algorithm 1). Second, the algorithm alternatively schedules each request by checking the following constraints. If *r<sup>t</sup> <sup>i</sup>* is scheduled to the MEC server, the constraints of the delay and the battery should be satisfied (Line 4 in Algorithm 1). To check the delay, the expected delay can be modified by Equation (11) and expressed as follows:

$$\widehat{D\_{\text{schedulle}}^{t}} = \sum\_{m=1}^{M} D\_{\mathcal{M},m}^{t} + D\_{\mathcal{R},i\prime}^{t} \tag{37}$$

Of course, the expected delay should satisfy the execution deadline as follows:

$$
\widehat{D\_{schedulle}^{t}} \le d\_i^t. \tag{38}
$$

To check the battery SoC, Equation (18) can be modified as follows:

$$E^t\_{\mathcal{R},i} + \sum\_{m=1}^M E^t\_{\mathcal{M},m} \le B^t,\tag{39}$$

i.e., the sum of energy consumption for the MEC tasks and the request should not be larger than the current battery capacity.

**Algorithm 1** The Greedy Algorithm.


3: **for** *i* = 1 → *N* **do** 4: Determine if *r<sup>t</sup> <sup>i</sup>* satisfies both Equations (38) and (39). 5: **if** *r<sup>t</sup> <sup>i</sup>* satisfies the both Equations **then** 6: Update M*<sup>t</sup>* 7: **else** 8: Update C*<sup>t</sup>* 9: **end if** 10: **end for**

If *r<sup>t</sup> <sup>i</sup>* is suitable for allocation to the MEC, it is transferred to the MEC buffer and M*<sup>t</sup>* is updated (Lines 5 and 6 in Algorithm 1). Otherwise, *r<sup>t</sup> <sup>i</sup>* is transferred to the cloud buffer and C*<sup>t</sup>* is updated (Lines 7 and 8 in Algorithm 1).
