Abstract
In this paper, we present a novel learning framework for finding shortest paths in graphs utilizing Generative Flow Networks (GFlowNets). First, we examine theoretical properties of GFlowNets in non-acyclic environments in relation to shortest paths. We prove that, if the total flow is minimized, forward and backward policies traverse the environment graph exclusively along shortest paths between the initial and terminal states. Building on this result, we show that the pathfinding problem in an arbitrary graph can be solved by training a non-acyclic GFlowNet with flow regularization. We experimentally demonstrate the performance of our method in pathfinding in permutation environments and in solving Rubik's Cubes. For the latter problem, our approach shows competitive results with state-of-the-art machine learning approaches designed specifically for this task in terms of the solution length, while requiring smaller search budget at test-time.
Introduction
Finding the shortest path between two nodes is a fundamental challenge in artificial intelligence. In combinatorial state spaces, such as the configurations of a Rubik’s Cube, the state space grows factorially, rendering classical algorithms like A* or Dijkstra’s impractical due to memory and exploration constraints. Modern machine learning techniques often rely on learning "distance-to-goal" heuristics to guide search algorithms. However, these heuristics are frequently noisy and necessitate large search budgets at test time. This research explores whether a generative model can directly learn a policy that follows the shortest path, bypassing the need for extensive search.
Methodology: GFlowNets for Pathfinding
The core of this approach lies in Generative Flow Networks (GFlowNets), which are typically used to sample diverse objects with probabilities proportional to a reward.
Theoretical Foundation
The authors establish a formal link between GFlowNets and shortest paths. In a non-acyclic environment, minimizing the expected trajectory length (total flow) forces the resulting policy to assign zero probability to any path that is not a shortest path.
Problem Reduction
To find shortest paths to a goal state $v_g$, the problem is framed as a GFlowNet where the goal state acts as the initial state, and transitions are the reversed edges of the original graph. Every state is treated as a terminal state with a uniform reward. Training utilizes a regularized version of the Trajectory Balance (TB) objective, which facilitates better credit assignment by evaluating entire paths rather than isolated steps.
Inference
At test time, the learned backward policy guides a Beam Search to find the solution. Unlike traditional methods that require a neural network forward pass for every neighbor of a state, this GFlowNet approach outputs a distribution over all possible moves in a single pass, significantly enhancing search efficiency.
Experimental Evaluation
The framework was evaluated on Swap Puzzles ($n=15, 20$) and Rubik's Cubes (2x2x2 and 3x3x3).
Results and Discussion
On the Swap Puzzle, the model successfully recovered exact shortest paths. For the Rubik's Cube, the GFlowNet approach demonstrated superior search efficiency compared to the state-of-the-art CayleyPy Cube baseline.
As shown in the table above, for the 2x2x2 cube, the model achieves the optimal average length of 10.64 with much smaller beam sizes than the baseline. On the 3x3x3 cube, the model was approximately 3.5x faster than the baseline per solve, despite having a larger parameter count, due to the more efficient move-selection process.
Conclusion
This work demonstrates that pathfinding can be effectively reframed as a probabilistic flow problem. By minimizing total flow in a GFlowNet, we can learn policies that naturally gravitate toward shortest paths. Future work will focus on scaling this approach to larger, more complex graphs and extending the framework to handle weighted graphs where actions have varying costs.
Summary updated