Learning Shortest Paths with Generative Flow Networks

Nikita Morozov, Ian Maksimov, Daniil Tiapkin, Sergey Samsonov

TL;DR

This paper establishes a formal theoretical link between Generative Flow Networks (GFlowNets) and the classic problem of finding shortest paths in large graphs. The authors prove that minimizing the "total flow" in a non-acyclic GFlowNet forces the model to traverse only shortest paths, and they leverage this to solve complex combinatorial puzzles like the Rubik's Cube with significantly higher search efficiency than current state-of-the-art methods.

What Problem Does This Paper Address?

Finding the shortest path between two nodes is a cornerstone of AI, but in "combinatorial" state spaces—like the configurations of a Rubik’s Cube—the number of possible states grows factorially. Classical algorithms like A* or Dijkstra’s are unusable because the graph is too large to store or explore fully.

Modern machine learning approaches usually try to learn a "distance-to-goal" heuristic to guide a search algorithm. However, these heuristics can be noisy and often require massive "search budgets" (evaluating thousands of states) at test time to find a good solution. The authors ask: Can we train a generative model to directly learn the policy that follows the shortest path?

Methods

The researchers utilize GFlowNets, a framework typically used to sample diverse objects with probabilities proportional to a reward.

  1. The Theoretical Breakthrough: The authors prove that in a non-acyclic environment (where you can revisit states or undo actions), if you minimize the expected trajectory length, the resulting policy must assign zero probability to any path that isn't a shortest path.
  2. The Reduction: To find shortest paths to a goal state ($v_g$) in any graph, they construct a GFlowNet where:
  3. The "initial state" is the goal ($v_g$).
  4. Transitions are the original graph's edges reversed.
  5. Every state is a "terminal state" with a uniform reward.
  6. Training Objective: They use a regularized version of the Trajectory Balance (TB) objective. While GFlowNets usually use "Detailed Balance," the authors found that Trajectory Balance provides better "credit assignment"—essentially, the model learns faster because it looks at entire paths rather than just isolated steps.
  7. Inference: At test time, they use Beam Search guided by the learned backward policy to find the solution.

Datasets

The method was evaluated on three challenging discrete domains:

  • Swap Puzzle ($n=15, 20$): A synthetic permutation puzzle where the goal is to sort a sequence by swapping adjacent elements. The state space for $n=20$ is roughly $2.4 \times 10^{18}$ states.
  • 2x2x2 Rubik’s Cube: A smaller cube used to verify that the model can reach the theoretical optimal solution (10.64 moves on average).
  • 3x3x3 Rubik’s Cube: The standard puzzle, tested against the state-of-the-art CayleyPy Cube baseline.

Key Insights and Ideas

  • Flow Minimization = Shortest Paths: The most elegant "aha moment" is the proof that the global minimum of a specific GFlowNet loss corresponds exactly to the shortest-path policy. This reframes pathfinding as a probabilistic flow problem.
  • Scrambling as Training: In this framework, the "forward policy" effectively learns how to scramble the puzzle optimally, while the "backward policy" learns how to solve it.
  • Efficiency through Logits: Unlike previous methods that must run a neural network forward pass for every single neighbor of a state during search, this GFlowNet approach outputs a distribution over all possible moves in a single pass. This makes the search significantly faster per step.

Key Results

  • Exact Solutions: On the Swap Puzzle, the model successfully recovered the exact shortest paths for every test case after sufficient training.
  • Search Efficiency: For the 2x2x2 Rubik's Cube, the GFlowNet approach found optimal solutions with a beam width 16 times smaller than the baseline. Even with a "greedy" search (beam width of 1), it solved 100% of the test cases, whereas the baseline failed completely.
  • Speedup: On the 3x3x3 Cube, the model was roughly 3.5x faster than the CayleyPy baseline (1.74s vs 6.19s per solve) despite using a much larger neural network (25M vs 4M parameters), thanks to the more efficient move-selection process.

Limitations and Future Work

  • Regularization Sensitivity: The performance depends on a regularization coefficient ($\lambda$). If $\lambda$ is too high, the model fails to find the goal; if it's too low, it might not converge to the shortest path. The authors suggest a "rule of thumb" for tuning, but it remains a hyperparameter.
  • Scaling: While successful on Rubik's Cubes, the authors note that scaling to even larger, more complex graphs (like those found in logistics or robotics) is the next major hurdle.
  • Cost-Sensitive Paths: The current work focuses on "unweighted" graphs (where every move costs 1). Extending this to weighted graphs where different actions have different costs is a clear path for future research.

Summary updated

BibTeX
@inproceedings{morozov2026learning,
  author = {Nikita Morozov and Ian Maksimov and Daniil Tiapkin and Sergey Samsonov},
  title = {{Learning Shortest Paths with Generative Flow Networks}},
  booktitle = {SPIGM @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=zFrmHWzEnL},
}
Figure