KNARsack: Teaching Neural Algorithmic Reasoners to Solve Pseudo-Polynomial Problems
Stjepan Požgaj, Dobrik Georgiev, Marin Šilić, Petar Veličković
TL;DR
This work extends Neural Algorithmic Reasoning to the Knapsack problem by formulating a two-phase NAR approach: (i) DP-table construction and (ii) solution reconstruction, within the CLRS-30 framework. It introduces edge-length encoding and a homogeneous processor to stabilize training and improve out-of-distribution generalization, achieving superior DP-table properties and reconstruction performance in many OOD regimes compared to baselines and Tropical Attention. The findings demonstrate that modeling intermediate DP states, rather than direct input-output mappings, yields better extrapolation to larger pseudo-polynomial instances, and the approach is readily transferable to other pseudo-polynomial problems. The work also outlines limitations—such as instability of deterministic reconstruction—and proposes concrete directions for extending pseudo-polynomial NAR to additional problems and architectures.
Abstract
Neural algorithmic reasoning (NAR) is a growing field that aims to embed algorithmic logic into neural networks by imitating classical algorithms. In this extended abstract, we detail our attempt to build a neural algorithmic reasoner that can solve Knapsack, a pseudo-polynomial problem bridging classical algorithms and combinatorial optimisation, but omitted in standard NAR benchmarks. Our neural algorithmic reasoner is designed to closely follow the two-phase pipeline for the Knapsack problem, which involves first constructing the dynamic programming table and then reconstructing the solution from it. The approach, which models intermediate states through dynamic programming supervision, achieves better generalization to larger problem instances than a direct-prediction baseline that attempts to select the optimal subset only from the problem inputs.
