The application discloses a flexible online routing method and device based on a graph neural network, and belongs to the technical field of next-generation Internet
system; the method comprises the following steps: constructing an agent corresponding to a routing device in a network, and defining a first reward function and a second reward function of the agent; constructing a GNN model on a
core router, and training the GNN model by using a first
network data set to obtain a pre-trained GNN model; calculating a
reward value of a first routing scheme by using the first reward function to
train the agent to obtain a pre-trained agent; calculating a
reward value of a second routing scheme by using the second reward function, and fine-tuning parameters of the pre-trained agent according to the
reward value of the second routing scheme; updating parameters of the pre-trained GNN model according to a second
network data set, and updating a
weight coefficient of the second reward function according to a
performance index predicted by the pre-trained GNN model to
train the fine-tuned agent. The application can enable routing devices to flexibly select routing and optimize strategies.