# A Dynamic-Routing Algorithm Based on a Virtual Quantum Key Distribution Network
## 3 Routing Algorithms  
### Related Definitions  
**Definition 3**: _Link weight calculation formula. The QKD dynamic routing algorithm uses weight to determine the optimal path in the network. The weight is usually expressed as a numerical value representing the path quality from the source node to the destination node. In a QKD network, each node periodically sends packets to its neighboring nodes to check the connectivity between them and exchange routing and weight information._  
In traditional networks, routing is usually selected based on distance, bandwidth and topology. In a QKD network, however, due to limited quantum key resources, there is a low utilization of network resources and uneven link load, etc. Therefore, the QKD routing algorithm evaluates the link weights and selects the best path based on the remaining quantum key resources on the link and the link congestion. Suppose there are n optional paths in the QKD dynamic routing algorithm, \(P_{ij}\) link blocking probability, and \(K_{ij}^{t}\) the number of keys in the QKP, where the coefficient factors \(\alpha\) and \(\beta\) are used to adjust the weights of the remaining quantum keys and link blocking probability and to determine their relative importance on a case-by-case basis. Thus, the values of these two factors can be flexibly adjusted according to actual requirements. \(W_{i}\) is denoted as the weight of the selected link:  
\[W_{i}=\alpha\times K_{ij}^{t}+\beta\times P_{ij} \tag{12}\]Firstly, since the calculation of link weights involves a linear combination of the remaining key quantity \(K_{ij}^{t}\) and the link-blocking probability \(P_{ij}\), both \(\alpha\) and \(\beta\) must be real numbers. Additionally, the values of \(\alpha\) and \(\beta\) must satisfy the following conditions:  
\[\begin{array}{l}0<\alpha<1\\ 0<\beta<1\\ \alpha+\beta=1\end{array} \tag{13}\]  
**Definition 4:**_Random walk modeling. The state of each node in the QKD network as a random variable, \(X_{-}t\) for the node of the \(t\)th time step, assuming \(X_{-}t=(x_{-}\hat{t},x_{-}\hat{t}2,\ldots x_{-}\hat{t}n)\), where \(n\) is the number of nodes. State transition probability matrix: defines the transition probability matrix \(P\) between node states, where \(P[i,j]\) represents the transition probability from form \(i\) to state \(j\). Value function for dynamic programming modeling: define \(V(X_{-}t)\) represents the optimal target function value at time \(t\) state \(X_{-}t\). The state transfer equation according to the state transition probability matrix \(P\) and the random walk \(V\) value function is:_  
\[V(X_{-}t)=max\big{\{}W(X_{-}t,u)+\sum\big{[}P(X_{-}t,u,X_{-}\{t+1\}\times V(X_ {-}\{t+1\}))\big{]}\big{\}} \tag{14}\]  
_where \(W(X_{-}t,u)\) represents the gain obtained from selecting operation \(u\) under state \(X_{-}t\), and \(P(X_{-}t,u,X_{-}\{t+1\})\) indicates the probability of transferring from state \(X_{-}t\) to state \(X_{-}\{t+1\}\) after operation \(u\)._  
The QKD dynamic routing algorithm uses the residual quantum key and link-blocking probability as weights and uses the value function \(V(X_{-}t)\) to optimize resource allocation and routing.  
The specific steps are described as follows:  
1. At initial time \(t\), the algorithm obtains the current network state \(X_{-}t\), including the remaining quantum key amount of each node and the blocking probability of the link.
2. The algorithm uses the value function \(V(X_{-}t)\) to calculate the corresponding expected payoff of each possible operation, that is, through the iterative calculation of all possible operations \(u\).
3. The algorithm selects the operation \(u\) with the maximum expected payoff and updates the network state to the state \(X_{-}\{t+1\}\) in the next moment.
4. Repeat steps 2 and 3 until the algorithm converges or reaches the specified number of iterations.