# Vehicular Edge-Computing Framework for Making Use of Parking and Charging Electric Vehicles
## 4 Problem Description and Optimal Solution
### Task Offloading Analysis Based on Starkelberg Game
#### 4.2.2 First Stage Starkelberg Game  
With the offloading strategy given by the requesting vehicle, the utility function of the edge server (Equation (11)) can be changed into (23):  
\[U_{VEC}=\sum_{i=1}^{n}\left[\left(\dfrac{Q_{i}C_{v}}{C_{je}+C_{v}}-\dfrac{C_{v} C_{je}[r_{v}r_{e}(p_{iv}-p_{ie})]}{2\omega\mu\alpha\big{  
The second derivative (29) is constantly less than zero, which means that the utility function is strictly concave, and the function has a maximum value. Let its first derivative (28) to be zero, we have the optimal price strategy for ECP as (30):  
\[\left\{\begin{array}{c}p_{ie}^{*}=\sum_{i=1}^{n}\Biggl{(}\frac{ \omega\mu\alpha Q_{i}}{C_{r}r_{v}r_{e}}+\frac{\rho(r_{v}-r_{e})}{2r_{v}r_{e}}+ \frac{\alpha(\varphi+1)}{2C_{je}}+\frac{\sigma}{2d}+\frac{p_{ip}^{*}}{2} \Biggr{)}\\ Q_{i}>q_{iv}^{*}\end{array}\right.. \tag{30}\]  
From the above analysis, it is proved that there are optimal strategies for the edge server, the ECP, and the requesting vehicle, and there is a Nash equilibrium in this Stackelberg game.  
In order to find the optimal solution, a game strategy algorithm (GSA) based on a genetic algorithm is proposed to solve the Stackelberg equilibrium problem, and the optimal strategies can be obtained by iterative crossover, mutation, selection, and reproduction in the genetic algorithm. The proposed algorithm is shown in Algorithm 1.  
```
0:\(A_{i}^{*}=\left\{Q_{i},q_{iv}^{*}q_{ie}^{*}\right\}(i\in[1,n])\), population size \(N\), cross probability \(cp\), mutation probability \(mp\), generation gap \(gap\), maximum genetic generation \(Maxgen\)
0:\(p_{iv^{\prime}}^{*},p_{iv^{\prime}}^{*}U_{VEC},U_{ECP}\)
1: iteration = 0
2:\(U_{VEC}=\sum_{i=1}^{n}\left(p_{iv}q_{iv}-\frac{q_{iv}}{C_{v}}\right)\)
3:\(U_{ECP}=\sum_{i=1}^{n}\left(p_{ie}q_{ie}-\frac{q_{iv}}{d}-p_{new}\right)\)
4:for iteration <\(Maxgen\)do
5: fit = fitness(\(U_{VEC}\))
6: offspring = select(parent, fitness, gap)
7: offspring = intersect (offspring, cp)
8: offspring = variation (offspring, mp)
9: parent = replace (offspring,\(U_{VEC}\))
10: iteration = iteration + 1
11:endfor
12:for iteration <\(Maxgen\)do
13: fit = fitness(\(U_{ECP}\))
14: offspring = select (parent, fitness, gap)
15: offspring = intersect (offspring, cp)
16: offspring = variation (offspring, mp)
17: parent = replace (offspring,\(U_{ECP}\))
18: iteration = iteration + 1
19:endfor
20:return\(p_{iv^{\prime}}^{*},p_{ie}^{*},U_{VEC},U_{ECP}\)
```  
**Algorithm 1** GSA (Game Strategy Algorithm)  
**Theorem 1**.: _The time complexity of GSA is O(Maxgen \(\cdot n^{2}\))._  
Proof of Theorem 1.: As shown in Algorithm 1, we know that both \(\frac{\partial^{2}U_{VEC}}{\partial p_{iv^{\prime}}}\) and \(\frac{\partial^{2}U_{ECP}}{\partial p_{iv^{\prime}}}\) are less than zero, \(U_{VEC}\) is a concave function about \(p_{iv}\), \(U_{ECP}\) is a concave function about \(p_{ie}\), and the optimal solutions exist for both the functions \(U_{VEC}\) and \(U_{ECP}\). Therefore, we can use the genetic algorithm to quickly get the optimal strategies for the edge server and the ECP. The core of the genetic algorithm is the dual iteration with time complexity not exceeding \(n^{2}\), and its complexity is determined by the fitness function, in addition, we set the iteration threshold \(Maxgen\). Consequently, the time complexity of the algorithm is O(\(Maxgen\cdot n^{2}\)).