Joint Optimization of Computation Offloading, Data Compression, Energy Harvesting, and Application Scenarios in Fog Computing

Fog computing is considered to be an effective method to solve the problem of high latency and high energy consumption of IoT devices. A suitable computation offloading strategy can provide a low offloading cost to the user device. Most researches on computation offloading in fog computing focus on one or two targets to improve system performance, however, the actual system needs to meet a comprehensive demand. Therefore, the joint optimization of multi-objective in multiple scenarios is a very meaningful problem. Inspired by this, the paper highlights the joint optimization research for fog computing, which proposes a Joint Computation offloading, Data compression, Energy harvesting, and Application scenarios (JCDEA) algorithm. The related mathematical model is constructed and the cost expressions of local computing, fog computing, and cloud computing are derived. Through the proposed algorithm, solving the computation offloading strategy is transformed into solving the minimum cost and is simplified by controlling strategy factors. Moreover, five simulation experiments are conducted and the meaningful conclusions are drawn, which contain that (1) the cost of fog computing is lower than that of local and cloud computing in most time slots and cloud computing can compensate for fog computing in complex environments; (2) the cost increases approximately linear with the amount of offloaded data; (3) the number of user devices and the compression ratio affect the fog-to-cloud ratio (FCR), while the FCR affects the cost; and (4) the related offloading strategy distribution and the cost are obtained for different scenarios. The JCDEA algorithm always outperforms than that of the random selection algorithm in all scenarios.

which increases latency and energy consumption. Hence, the key issue is how to effectively choose the offloading strategy.
For the ability of applications to offload, applications that support code or data partitioning and parallelism (applications that can be partially offloaded) consist of two categories [5]. The first type of application is one that can be divided into multiple offloadable parts, all of which can be offloaded. In extreme cases, this type of application may be completely offloaded if the user device does not process any parts. The second type of application consists of some non-offloadable parts that cannot be offloaded (such as, user input, camera, or fetch locations that need to be performed by the user device) and other offloadable parts [5].
Meanwhile, the energy consumption of user devices is also a key factor. In many scenarios, mobile devices cannot be charged in time, and frequent linking, switching, and data transmission with base stations (BS) lead to excessive instantaneous discharge, which causes a significant decrease in the battery life of mobile devices [6]. Therefore, energy harvesting (EH) technology is seen as a possible solution for harvesting clean energy, including solar, wind, and kinetic energy, to provide computing energy for user devices [7], [8]. Advanced data compression (DC) technology is developing rapidly, and it can be used to reduce the amount of data transmitted on the link [9]. However, data compression requires additional computing resources to compress and decompress data [10]. Different application scenarios have different requirements, corresponding to different offloading strategies. If they are treated equally, higher costs will be incurred. For these purposes, joint optimization has always been a hot research field.

A. RELATED WORK
Computation offloading strategy has been extensively studied in mobile edge computing (MEC) [11] and mobile cloud computing (MCC) [12]. Most studies focus on one [13]- [15] or two [16]- [18] aspects of energy consumption and latency. In [19], the author designed a deadline and priority-aware task offloading (DPTO) strategy to schedule and process offloaded tasks to suitable computing devices. In [20], the author studied the computation offloading strategy in the fog-cloud system and proposed an energy-efficient computation offloading and resource allocation (ECORA) scheme, which jointly optimized the offloading strategy, computing resource allocation, and transmission power to minimize the system cost. In [21], the author solved the content caching strategy, computation offloading strategy, and wireless resource allocation through deep reinforcement learning at the same time, and proposed a joint optimization scheme that supports fog computing networks. In [22], the author describes the joint optimization of offloading strategy, computing resource, transmission power, and wireless bandwidth allocation in mobile cloud computing to solve computation offloading problems in mixed cloud and fog systems while ensuring user fairness and maximum tolerable latency. In [23], the author proposes an energy-optimal dynamic computation offloading scheme (EDCO) to minimize energy consumption for fog computing in the IIoT. This offloading scheme outperforms local computing, full offloading, and partial offloading in terms of energy consumption and completion time with a fixed computation speed. Research [24] proposes a learning-based channel selection framework with service reliability awareness, energy awareness, backlog awareness, and conflict awareness through a combination of machine learning, Lyapunov optimization and matching theory, which aims at maximizing long-term throughput under long-term constraints on energy and service reliability. Research [25] proposed an air-ground integrated offloading architecture for vehicular edge computing tasks, called the learning-based Intent-Aware Upper Confidence Bound (IUCB) algorithm. This algorithm enables QoE-aware, uRLLC-aware and trajectory similarityaware 3D intent awareness. In [26], the authors research the computation offloading problem for multiple tasks with different latency requirements when the user device starts one task at a time, and model the fog nodes and remote cloud selection as well as CPU computing resources and fog cloud transmission resource allocation as a Quadratically Constraint Quadratic Programming (QCQP) and provide a solution.
In the research of energy harvesting, the majority of energy harvesting equipment is based on solar energy and wind energy [27]. By photovoltaic cells, solar energy is converted into electrical energy [28]. Wind energy is converted into electrical energy by means of turbines, and the turbines move in two ways, horizontal and vertical turbine [29]. In the study of data compression in fog computing networks, Nguyen et al. [30] demonstrated that data compression has the potential to improve computation offloading performance in hierarchical fog-cloud systems, and discussed computation offloading strategy and resource allocation to determine the optimal compression ratio. The author proposed a non-linear model, describing the additional computing load caused by data compression and decompression. In [31], the author uses a mathematical algorithm called RACOS to jointly optimize edge server selection and energy harvesting in MEC.
Several key issues have not been resolved in the above researches. First of all, the author did not consider the contribution of data compression to computation offloading in joint optimization for fog computing. Secondly, the authors did not distinguish the difference between scenarios for fog computing. Finally, the authors did not consider the edge and cloud to work collaboratively.

B. MAIN CONTRIBUTION
First, a multi-layer architecture is established, including the local computing layer, the fog computing layer, and the cloud computing layer. The local computing layer includes mobile devices, such as mobile phones and wearable devices, as well as stationary devices, such as monitoring devices and smart VOLUME 9, 2021 mechanical devices. The fog computing layer contains multiple fog servers and the FSM.
Secondly, an optimization algorithm is proposed, which refers to the Joint Computation offloading, Data compression, Energy harvesting, and Application scenarios (JCDEA) algorithm. The computation offloading strategies for different parameters with the JCDEA algorithm are researched, and the related math expressions are derived in theory.
Finally, the varying of cost with the amount of offloaded data, the number of users, application scenarios, and data compression ratios is obtained and compared. Moreover, it is proved that uploading to the cloud makes up for the lack of fog computing in complex environments. Figure 1, the architecture contains K user devices, J fog servers, a fog server manager (FSM), and a cloud server. At the fog computing layer, the fog server is deployed at the gNB. If the user device decides the computation offloading strategy by itself, it needs to communicate with multiple gNBs simultaneously, which increases the energy consumption for communication. At the same time, it also increases the calculation energy consumption of the user device. If the cloud server decides the computation offloading strategy for the user devices, the transmission latency is very high when sending the offloaded data, because the user device is far away from the cloud server. In summary, a reasonable solution is selected to set up a manager at the fog computing layer, which is called the fog server manager (FSM). The FSM with a global view determines the computation offloading strategy, which is equivalent to the MNO in [31]. If the fog servers are not able to process the offloaded task for busy work in time, gNB will upload the task to the cloud server for further processing. Each user device is equipped with energy harvesting equipment, all harvested energy is converted into electrical energy. Similar to [31], the EH process is seen as a uniform process that is independently identically distributed.

As shown in
The time T is divided into multiple time slots of equal length. In each time slot t, the user device sends offloading request information including offloaded data, application scenarios, local CPU frequency, channel status, compression ratio, and other parameters about compression to the FSM. The FSM calculates the local cost k,u (t), the fog cost k,f (t), and the cloud cost k,c (t), where k represents the user device, t represents the time slot, u represents user device computing (local computing), f represents fog computing, and c represents cloud computing. Then, FSM selects the minimum cost according to k,u (t) , k,f (t) and k,c (t) to determine the offloading strategy, and delivers this strategy to the user device.
If selecting fog computing, the user device compresses the offloaded task and uploads it to the fog server. If selecting cloud computing, the user device compresses the offloaded task and uploads it to the fog servers, and the fog servers further compress the offloaded data to reduce the amount of data transferred and upload it to the cloud server. Since the computation result is much smaller than the offloaded data, the transmission time of results is ignored.
Here, the data compression and decompression model are cited as in [30], which proved the relationship between the compressed data and the CPU cycles. The Gaussian movement model is used to describe the movement of the user devices as in [31].

B. MATHEMATICAL MODEL
Assuming that the raw data is b i , and the compressed data is b o . The data compression ratio is According to [30], the CPU cycles for compression and decompression is Here, x represents 'co' or 'de', which correspond to compression or decompression respectively. γ k,0 represents the maximum CPU cycles. γ x k,1 , γ x k,2 and γ x k,3 represent the non-negative limited parameters with GZIP, BZ2, and JPEG respectively [30]. GZIP, BZ2, and JPEG are three different compression methods. GZIP is an abbreviation for file compression programs and usually refers to implementations of the GNU Project, where GZIP stands for GNU zip. BZ2 is a data compression algorithm and program developed by Julian Seward and distributed under the Free Software/Open Source Software protocol. JPEG is a compression standard for continuous-tone still images. ω k is the compression ratio, which is limited by the minimum ω u,min k and maximum ω u,max k due to the limited CPU frequency. Suppose that s u k , s f k , s c k ∈ {0, 1} are the strategy factors for local computing, fog computing, and cloud computing, respectively. s u k = 1, s f k = 1, s c k = 1 mean the offloaded task is processed at the user device, the fog servers, and the cloud server, respectively. Otherwise, the factors are zero. Since the offloaded task is processed at one location, [30]. Local CPU cycles consist of three aspects: the CPU cycles that must be executed locally, the CPU cycles that the offloaded task executes locally, and the CPU cycles for compression. The CPU cycles that must be executed locally are the CPU cycles consumed by non-offloadable applications, including cameras, voice recorders, etc. The CPU cycle that must be executed locally are related to the users' usage habits and are very random [30]. If the user device chooses the local computing, it means that the offloading failed and the offloaded task was performed locally. The CPU cycles that the offloaded task executes locally are the CPU cycles required for an offloadable application to execute locally if the user device selects local computing. If the user device does not choose the local computing, it means that the user device needs to compress the offloaded task. The CPU cycles for compression are the CPU cycles that the user device needs to compress the offloaded task if the user device does not select the local computing. The applications in the article are partially offloadable applications and are divided into two parts. The first part is that must be executed locally, and the second part is that can be offloaded, and the data amount of the first part is much smaller than that of the second part. Suppose the data size to be processed for essential local execution and offloading is b k,u and b k,o , respectively. The CPU cycles processing 1bit data are η. The CPU cycles for local execution are C k,u = ηb k,u . Assuming that the CPU cycles for compression are C co k , the local CPU cycles are Here, C k,o are the CPU cycles of the offloaded task processed locally. If local computing (s u k = 1), the local CPU cycles include the CPU cycles of essential local execution and offloading. If not local computing (s u k = 0), the local CPU cycles include the CPU cycles of essential local execution and compression. The local CPU frequency is f u k , and the local computing time is If the energy coefficient specified by the CPU model is λ, the local computing energy consumption is Let I k,j (t) be the connection indicator. I k,j (t) = 1 means that the user device k is connected to the fog server j. Otherwise, I k,j (t) = 0. The channel power gain is h k,j (t). The data transmission rate is where B represents the transmission bandwidth. p k represents the transmission power. N represents the noise. When the compression ratio is ω k,u and the offloaded data is b k,i , the transmission time is .
The formula (2-7) is composed of two parts. One is to divide the compressed data equally to J fog servers, and the other is the data transmission time between user k and fog server j. The transmission energy consumption is ε k,2 = p k t k,2 . The fog server decompression and computing time is , (2)(3)(4)(5)(6)(7)(8) where f f k is the CPU frequency of the fog servers, and C de k is the CPU cycles for decompression. If the time coordinating a fog server is ϕ, the fog server coordination time is (2-9) VOLUME 9, 2021 The fog compression ratio is ω k,f , and the transmission rate between the fog and cloud is d k . The transmission time is The computing time of the cloud server is fixed T C . The optimal energy harvesting is E k,h (t). The latency factor is α. The energy consumption factor is β. And α + β = 1. α < β means the energy consumption requirement is more stringent than the latency requirement, and the application scenario is an energy-sensitive scenario. α > β means this application scenario is a latency-sensitive scenario. α = β means this application scenario is a general scenario. Combined Formula (2-1) -(2-10), the overall cost of the user device k is It can be seen from the Formula (2-11) that the cost of the user device k consists of two parts, the latency cost and the energy consumption cost. α and β determine the application scenarios. The latency cost includes 6 parts, which are local computing and compression latency, wireless transmission latency, fog server decompression and computing latency, fog server coordination latency, fog and cloud transmission latency, and cloud server computing latency. The energy consumption cost consists of three parts: local computing and compression energy consumption, wireless transmission energy consumption, and harvested energy. After the local computing cost, fog computing cost, and cloud computing cost are respectively determined, the computation offloading strategy corresponding to the smallest cost among the three is taken as the computation offloading strategy for the user device k in the time slot t. Thus, solving suitable computation offloading strategies transforms into solving the minimum of (2-11), which is Here, τ d represents the offloading deadline which is equal to the length of the time slot. ψ max is the maximum instantaneous discharge threshold. E max k,h (t) is the maximum harvesting energy. (2)(3)(4)(5)(6)(7)(8)(9)(10)(11)(12)(13)(14)(15)(16)(17) indicates the computing time and transmission time cannot exceed a time slot. (2)(3)(4)(5)(6)(7)(8)(9)(10)(11)(12)(13)(14)(15)(16)(17)(18) indicates the offloading energy consumption cannot exceed the maximum instantaneous discharge threshold.

III. PROPOSED ALGORITHM
The variables in the cost function from t to t + 1 are I k,j (t), R k,j (t) and E k,h (t). These variables are affected by location, so that the system state of t +1 is related to that of t, but not to the system state of t − 1. This is because the state before t − 1 only affects the state of t and not the state of t +1. It is obvious that the next state of the system is only related to the current state, not to history. Hence, the joint optimization problem P 1 is a Markov process. If using traditional methods to solve the problem, we first need to discretize it. However, there are too many feasible solutions after discretizing. It is impractical to traverse all states [31]. So, we propose to simplify the P 1 by controlling strategy factors.

A. LOCAL COMPUTING
In local computing, it is seen from Section II that the strategy factors are s u k = 1, s f k = s c k = 0, and P 1 is simplified to The unique variable is E k,h (t) when other parameters (α, β, In fog computing, it is seen from section II that the strategy factors are s f k = 1, s u k = s c k = 0, and P 1 is simplified to In P 3 , there are two sub-problems, solving j I k,j (t) and E k,h (t) which are fog server selection and optimal energy harvesting. We extend the CCO algorithm in [22] to solve these two problems. Details are as follows.
If the penalty Q k is generated, D k (t) = 1, which means the offloaded task is delayed a time slot. Otherwise, D k (t) = 0. Therefore, P 3 can be transformed into Assume that which is the energy of the system. Given a set of parameters and θ k ≥ 0, a Lyapunov function is constructed, The Formula  represents that the power of the user device k is always stable near a non-negative θ k . The Lyapunov drift function is The evolution equation of energy is  According to the Formula  and , we obtain that Then, we get that (I k (t)) + C.  This can convert P 4 to Therefore, our goal is to find an asymptotically optimal solution for P 5 . P 5 can be decomposed into two parts, optimal energy harvesting and optimal fog server selection. P 6 (optimal energy harvesting) : Then, the optimal energy harvesting is P 7 (optimal fog server selection) : Then, the RACOS algorithm is used to calculate P 7 to get the fog server selection [31]. We substitute the fog server selection and the energy harvesting into P 3 to get the minimum cost of fog computing.
To the end, the problem decomposition of the JCDEA optimization algorithm in fog computing is shown in Figure 2. And the JCDEA algorithm is shown below. It is assumed that there are K user devices and T time slots.

The JCDEA Optimization Algorithm in Fog Computing
At the beginning of the time slot t, the channel state is obtained for k = 1 to K do Calculate the local cost and harvesting energy P 2 end for for k = 1 to K do Obtain the fog harvesting energy by solving P 6 Obtain the fog server election by solving P 7 if fog server selections == 0 fog cost = local cost else Obtain fog cost by solving P 3 end for for k = 1 to K do Obtain the cloud harvesting energy by solving P 8 Obtain the fog server election for communication Obtain the cloud cost by solving P 8 end for The offloading method that is the smallest cost is used as the offloading strategy for the user device in the time slot. Update the battery energy and user devices' location. end for

A. PARAMETER SETTINGS
The length of the time slot is set to 2ms. There are 50 time slots. The longest transmission distance of gNB is 400 meters. The shortest distance is 150 meters. The maximum channel power gain is 1.02 × 10 −13 . The maximum CPU cycle is γ k,0 = µb k,i . The distribution of base stations in Melbourne is used for experiments [32]. There are 80 user devices in the system, and their distribution and movement are random. The type of application offloaded in the experiment is a partially offloaded application, consisting of the parts that must be executed locally and the parts that can be offloaded. The remaining parameters are shown in Table1. The parameters related to compression in Table1 refer to [30], and the parameters related to transmission and calculation refer to [31].   Figure 3 shows the cost of local computing, fog computing, and cloud computing of the 5th user device. The cost of local computing remains constant as it is not affected by wireless communication. The cost of fog computing is lower than that of local and cloud computing in most time slots. Only in the two time slots, the cost of fog computing is equal to that of local computing and higher than that of cloud computing. This is due to the fact that in both time slots, the user device does not find suitable fog servers to offload the task, and it uploads to the cloud server. It can be seen that cloud computing makes up for the lack of fog computing in the complex environment. The reason for the small proportion of local computing is that local computing is suitable for applications that must be executed locally, including cameras, voice recorders, etc. So for applications that can be offloaded, local computing is not practical.

B. SIMULATION RESULTS
As shown in Figure 4 shows the cost and connection distribution on the different amount of offloaded data.  When offloading less than 9000 bits, the proportion of fog computing is stable at about 61.18%. When offloading more than 12000 bits, the proportion of fog computing dropped by 7.18%. When the offloaded data increased to 15000 bits, the proportion of fog computing dropped by 13.95%. At the same time, the proportion of cloud computing increased by 13.95% and exceeded the proportion of fog computing. This is because as the amount of offloaded data increases, the CPU cycles for compression and decompression increase, resulting in increasing the cost and the proportion of cloud computing. When offloading data of 3000bit to 15000bit, the percentage of local computing is 0%. This is due to the fact that the processed data within a time slot is so large that local computing is not applicable. And the offloaded tasks are offloadable tasks in the experiment, not including tasks that must be executed locally. Besides, the random selection algorithm is a benchmarking algorithm in which a fog server is randomly selected for computation offloading or transmission [31]. The cost of the JCDEA algorithm is obviously lower than that of the random selection algorithm for different amounts of offloaded data, with the smallest difference of 0.554E-4 for 3000 bits and the largest difference of 1.048E-4 for 12,000 bits. Figure 5 shows the cost and connection distribution on the different number of user devices. When the number of user devices increases from 100 to 300 and when the number of user devices is increased by 50 at a time, the cost first increases rapidly and then slowly, increasing by 43.85%, 1.29%, 16.72%, and 5.08% respectively. When the number of user devices is 250, the proportion of cloud computing exceeded that of fog computing for the first time. With the increase of the number of user devices, the proportion of local computing also increases. This is because the increase in the number of user devices intensifies the competition between user devices, resulting in the increase of the coordination cost of fog servers. Therefore, a small part of user devices choose local computing, while another part of user devices choose cloud computing. The user devices of local computing are ignored since there are few user devices that choose local computing. And the Fog-to-Cloud Ratio (FCR) is defined, which is equal to the ratio of the number of user devices which choose fog computing to the number of user devices which choose cloud computing. Combining the cost and the FCR, we can see that the FCR is closely related to the cost, and as the FCR increases, the cost decreases. As the number of user devices increases, the cost of the random selection algorithm increases, but is higher than the cost of the JCDEA algorithm. The largest gap is 0.772E-4 when there are 200 user devices in the system, while the smallest gap is 0.635E-4 when there are 300 user devices in the system.  Figure 6 provides the cost and connection distribution on different application scenarios. Latency factor α = 0.3, α = 0.5, and α = 0.7 represent latency-sensitive scenarios, general scenarios, and energy-sensitive scenarios, respectively. The proportion of fog computing in latency-sensitive and energy-sensitive scenarios is higher than that in general scenarios. It shows that fog computing is effective in  latency-sensitive and energy-sensitive scenarios. The cost of energy-sensitive scenarios is the lowest, however, that of latency-sensitive scenarios is the highest. This is because, in energy-sensitive scenarios, it is permissible that user devices delay one or more time slots to offload the task. However, in a latency-sensitive scenario, user devices try to offload tasks in a short time, so multiple fog servers are required to jointly provide computing at the same time, and the user device spends some additional costs to select the fog servers. It can be seen that the cost of the random selection algorithm increases with increasing latency factor and is higher than the cost of the JCDEA algorithm in all three scenarios, with the largest difference of 1.136E-4 in the general scenario and the smallest difference of 0.554E-4 in the latency-sensitive scenario. Figure 7 shows the cost and connection distribution on the different compression ratios. It can be seen from Figure 7 that under the condition of offloaded 3000bits, 80 user devices, Melbourne base station distribution, and the energy-sensitive scenario, as the compression ratio increases, the cost increases on the overall trend, but it is not monotonous. The proportion of local computing is ignored as the proportion is small. The FCR is 2.06898, 1.56102, 1.37140, 2.24412, 1.47948, and 1.18575 for different compression ratios. So the average cost is negatively related to the FCR in the system. An interesting discovery is that the cost reaches the minimum when the compression ratio is 2.7, and the FCR reaches the maximum, which is 2.24412. It provides a reference application scenario in fog computing. Comparing the random selection algorithm to the JCDEA algorithm, we find that the cost trend of the random selection algorithm is similar to the cost trend of the JCDEA algorithm, but is still higher than the JCDEA algorithm at different compression ratios, with a maximum difference of 1.063E-4 at a compression ratio of 2.7 and a minimum difference of 0.413E-4 at a compression ratio of 2.8.

V. CONCLUSION
In this paper, a joint computation offloading, data compression, energy harvesting, and application scenarios optimization problem is researched in the distributed fog computing wireless network. The three-layer architecture is established, containing multiple user devices and fog servers. The JCDEA algorithm is proposed and the related math expressions are derived in theory, which is applied to several scenarios in fog computing. The JCDEA algorithm transforms solving the offloading strategy into solving the minimum cost of local computing, fog computing, and cloud computing. The experiment results suggested that when the offloaded data in each time slot exceeds 12000 bits and the number of user devices exceeds 200, the proportion of cloud computing is higher than that of fog computing. In addition, the cost of energy-sensitive scenarios is the lowest one of the three, and the proportion of fog computing in latency-sensitive scenarios is the highest. Moreover, when the number of user devices and the compression ratio increases independently, a surprising thing is that the average cost is negatively related to the FCR, and when the compression ratio is 2.7, the cost reaches the lowest. In summary, local computing is suitable for applications that cannot be offloaded. Fog computing is suitable for latency-sensitive scenarios and energy-sensitive scenarios and is suitable for the application of offloading less than 12000bits within a time slot. Cloud computing is suitable for applications that have no requirements on latency and energy consumption, and offload more than 15000bits in a time slot. The cost of the JCDEA algorithm is lower than that of the random selection algorithm for different offloading data quantities, the number of user devices, scenarios, and compression rates. In the next work, we will apply more fog server managers to the fog computing layer to obtain more general conclusions. CHENGCAI WANG received the bachelor's degree in electronic and information engineering from Hangzhou Dianzi University, Hangzhou, China, in 2013, and the master's degree in control theory and control engineering from Peking University, Beijing, China, in 2016. He is currently a Researcher with the China Academy of Electronics and Information Technology, Beijing. His current research interests include robotics and artificial intelligence. VOLUME 9, 2021