## 3 GA Hybrid-Fog Model
### GA Hybrid-Fog Formulation
* GA Hybrid-Fog Algorithm  
The proposed GA Hybrid-Fog algorithm, outlined in Algorithm 1, is executed by the UAV when offloading tasks to a set of FBSs or FUAVs. Before generating the population of individuals (SP), Step 1 involves defining the problem by establishing a fitness function. This function evaluates the total offloading delay for each FBS and FUAV, which is calculated using Algorithm 2. Following this, in Step 2.1, each individual in the population is encoded as a binary chromosome, representing the allocation of tasks to either FBSs or FUAVs. After that, Step 2.2 initializes a vector of SP individuals, each containing a fitness value calculated by the fitness function in Algorithm 2. Step 3 selects a subset of the individuals in the population with the highest fitness values. Step 4 applies the crossover function of the heuristic GA as follows:  
* Step 4.1: Choose two chromosomes \(j\) and \(j+1\) when the generated random value r is lower than the crossover probability (PC). * Step 4.2: Randomly select a crossover point that represents the order of the crossed bits of chromosome \(j\) and chromosome \(j+1\). * Step 4.3: Cross the two bits of these chromosomes. Step 5 applies the mutation function of the GA heuristic as follows:
* Step 5.1: Select one chromosome \(j\) when the regenerated random value r is lower than mutation probability (PM). * Step 5.2: Randomly select a mutation point that represents the order of the mutated bit of chromosome \(j\). * Step 5.3: Change the value of the selected bit of chromosome \(j\). Finally, Steps 6 and 7 generate the minimal delay for all offloading tasks to all FBSs and FUAVs. Algorithm 2 provides the pseudo-code used for calculating the total delay involved in offloading tasks according to the proposed GA Hybrid-Fog algorithm. This algorithm is specifically applied during Step 2.2 and Step 6 of Algorithm 1 to calculate the transmission delay and fog computing delay for all tasks offloaded to FBSs and FUAVs. In Step 1, the algorithm calculates the data rate based on Equations (1)-(3). Subsequently, Step 2 computes both the transmission delay and the computing delay for each offloading task based on Equations (4) and (5). Finally, the algorithm determines the total task-offloading delay, which is the maximum delay among all the individual task-offloading delays. ```
Inputs: Number of fog base stations (NFBSs), number of fog UAVs (NFUAVs), number of offloading tasks (NTasks), number of generations (NG), population size (SP), chromosome length (LC), mutation probability (PM), crossover probability (PC). Outputs: Optimized task-offloading total delay for all fog base stations and all fog UAVs (Best_Cost). Step 1: Problem Definition Step 1.1: Define the problem as minimizing the total delay for all fog base stations and all fog UAVs. Step 1.2: The Fitness_Function is defined as the total delay. Step 2: Initialization Step 2.1: Encode each individual as a chromosome of LC bits for the initial population \(P_{0}\). Step 2.2: Create a vector \(VF_{0}\) of SP individuals containing initialized fitness values. For\(i=1:\) NG Step 3: Selection Select a sub-vector individuals \(VF_{i}\) from \(VF_{i-1}\) with the maximum fitness values. For\(j=1\) to \(\text{length}(VF_{i})-1\) Step 4: Crossover Function Generate the random variable \(r\). If\(r<PC\) Step 4.1: Select two individuals from \(VF_{i}\), chromosome \(j\) and chromosome \(j+1\). Step 4.2: Choose a crossover point (the order of chromosome \(j\) bit and of chromosome \(j+1\) that will be crossed). Step 4.3: Apply the crossover function on chromosome \(j\) and \(j+1\). end Step 5: Mutation Function Generate a random variable \(r\). If\(r<PM\) Step 5.1: Select an individual \(VF_{i}\), chromosome \(j\). Step 5.2: Choose mutation point (the order of chromosome \(j\) that will be changed). Step 5.3: Apply the mutation function on chromosome \(j_{in}\) selected mutation point. end Step 6: Evaluation Evaluate the Fitness_Function for each individual in population \(i\).