Abstract
Combinatorial optimization (CO) is fundamental to numerous industrial and scientific domains, yet remains challenging due to the NP-hard nature of many problems. Traditional solvers rely on hand-tuned heuristics, while recent neural approaches often struggle with "one-shot" global predictions as problem scales increase. This paper presents NeuRewriter, a reinforcement learning framework that iteratively improves solutions through local rewriting. By factorizing the improvement process into "where to change" (Region-Picker) and "how to change" (Rule-Picker), NeuRewriter achieves state-of-the-art results in symbolic simplification, scheduling, and routing, often outperforming industry-standard solvers like Z3 and Google OR-tools.
Introduction
Finding optimal solutions in discrete spaces—such as logistics, job scheduling, or compiler design—is a cornerstone of computational efficiency. However, the lack of gradients in discrete combinatorial optimization (CO) makes iterative improvement difficult compared to continuous domains like robotics. Existing methods typically fall into two categories: brittle, expert-designed heuristics or neural models that attempt to predict a complete solution in a single pass. The latter approach often fails to generalize as the number of variables grows, as predicting a perfect global structure from scratch becomes exponentially difficult.
NeuRewriter bridges this gap by mimicking the iterative refinement process. Instead of constructing a solution from a blank slate, it learns a neural policy to perform local rewriting, progressively transforming a feasible (but likely sub-optimal) starting solution into a better one.
Methods: The NeuRewriter Architecture
The core innovation of NeuRewriter is a policy that transforms a solution through a sequence of local modifications. This policy is factorized into two distinct neural components:
- The Region-Picker: This component analyzes the current state (e.g., a parse tree or a schedule) and assigns scores to different local regions. A high score identifies a region where a rewrite is likely to yield the greatest improvement in the global cost function.
- The Rule-Picker: Once a region is selected, this component selects the most effective "rewriting rule" from a predefined set to apply to that specific area.
The model is trained using Advantage Actor-Critic (A2C), where the reward is defined as the cumulative improvement in the cost function (e.g., reduction in expression length or tour distance). To handle various data structures, the framework utilizes specialized encoders: Tree-LSTMs for symbolic expressions, DAG-structured LSTMs for job dependency graphs, and Bi-directional LSTMs for routing sequences.
Experimental Evaluation
NeuRewriter was evaluated across three diverse domains to test its versatility and generalization capabilities:
- Expression Simplification: Minimizing code length for 1.36M expressions generated from the Halide domain-specific language.
- Online Job Scheduling: Optimizing resource allocation for 100K job sequences based on the "DeepRM" benchmark.
- Vehicle Routing Problem (VRP): Solving capacitated VRP instances with up to 100 customer nodes.
Key Results and Insights
NeuRewriter demonstrated superior performance and efficiency across all benchmarks:
- Performance vs. Heuristics: In expression simplification, it reduced average length by 52%, significantly outperforming the
Z3-simplifytactic. In VRP20, it achieved an average tour length of 6.16, nearly matching the exact optimal of 6.10 and beating other neural baselines like the Attention Model (AM). - Computational Speed: The model was nearly 10x faster than advanced Z3 solvers and orders of magnitude faster than Google OR-tools in scheduling tasks (0.037s vs. 10s per instance).
- Structural Generalization: A key advantage of local rewriting is its ability to generalize. Models trained on small instances (e.g., short expressions) effectively simplified much larger, unseen structures by applying learned local patterns.
- Learning "Uphill" Moves: Interestingly, the model learned to apply moves that temporarily increase the cost function to escape local optima—a behavior analogous to how momentum helps in gradient descent.
Conclusion
NeuRewriter provides a robust framework for discrete optimization by learning to iteratively refine solutions. While it currently relies on predefined rule sets and may face challenges with massive top-to-bottom structural changes, its ability to outperform specialized solvers across multiple domains highlights its potential. Future work may explore extending this approach to hardware circuit design and automated theorem proving.
Summary updated