TL;DR
Latent Heuristic Search (LHS) moves automated algorithm design out of the messy, discrete world of code mutations and into a smooth, continuous latent space. By combining code embeddings, normalizing flows, and gradient-based optimization, LHS efficiently navigates the space of possible heuristics to generate state-of-the-art combinatorial optimization algorithms via a frozen Large Language Model (LLM).
What Problem Does This Paper Address?
Designing effective heuristic algorithms for NP-hard combinatorial optimization problems—like vehicle routing or bin packing—traditionally requires immense human expertise and iterative trial-and-error. Recently, LLM-based evolutionary frameworks (such as FunSearch) have automated this process by treating code generation as a search-and-evaluate loop.
However, these methods operate directly on the discrete syntax of code, relying on stochastic mutations, crossovers, and token sampling. This creates a highly non-convex, rugged optimization landscape where a single character change can cause a program to catastrophically fail. As a result, these algorithms require thousands of expensive code executions to find meaningful improvements. LHS aims to fix this by shifting the search from discrete token space to a continuous, learnable mathematical manifold.
Methods
The authors introduce Latent Heuristic Search (LHS), a framework that transforms discrete program search into a continuous optimization problem. The process is split into two primary phases:
- Latent Space Learning: Discrete heuristic programs are mapped into continuous vectors using a code encoder (
Qwen3-Embedding-0.6B), compressed to 128 dimensions. To fix the "anisotropy problem" (where raw embeddings cluster irregularly), an invertible Normalizing Flow (RealNVP) maps these embeddings into a well-behaved, smooth standard Gaussian prior space. Concurrently, a Performance Surrogate model is trained using a pairwise ranking loss (RankNet) to predict which latent vector represents a better-performing heuristic. Finally, a Latent-to-Prompt Mapper learns to translate these continuous vectors into soft prompts (prefixes) that condition a frozen LLM. - Continuous Search & Heuristic Generation: Instead of randomly mutating code strings, LHS selects a high-performing seed program, maps it to the smooth prior space, and performs gradient ascent directly on the performance surrogate to maximize predicted performance. The optimized latent vector is then passed back through the inverse normalizing flow, converted into a soft prompt by the mapper, and fed into a frozen LLM (
Qwen3-4B-Instruct) to synthesize a brand-new, executable heuristic.
Datasets
To train and evaluate the global components of LHS, the authors constructed a dataset of 4,624 valid heuristic programs distributed across 10 combinatorial domains (e.g., Job Shop Scheduling, Set Cover, Quadratic Assignment).
- Data Generation: Initial seeds (~100 per task) were generated via GPT-5.2 and expanded using a lightweight model (GPT-OSS-20B) through three augmentation strategies: syntactic rewriting, parametric tuning, and semantic-preserving behavioral variations.
- Evaluation Benchmarks: The final framework was evaluated on four classic NP-hard problems: the Traveling Salesperson Problem (TSP), the Capacitated Vehicle Routing Problem (CVRP), Online Bin Packing (OBP), and the Knapsack Problem (KSP).
Key Insights and Ideas
- The Necessity of the Flow Prior: Directly performing gradient ascent in the raw embedding space ($Z$) fails because the space is full of low-density regions where the LLM decoder becomes unreliable. Mapping embeddings to a standard Gaussian prior ($U$) ensures that gradient steps stay on the manifold of plausible, executable program structures.
- Ranking Over Regression: Training the surrogate model to regress absolute performance scores (via MSE) is brittle due to noisy evaluations and scale differences across problem instances. Training it to predict relative preference (pairwise ranking) provides a much more stable and scalable learning signal, expanding $N$ evaluations into up to $O(N^2)$ training comparisons.
- Smooth Topology: t-SNE visualizations of the latent space reveal that the encoder naturally clusters semantically similar heuristics into nearby neighborhoods based on performance, proving that continuous optimization can effectively exploit this underlying geometric structure.
Key Results
LHS was benchmarked against top discrete evolutionary baselines, including FunSearch, EoH, ReEvo, and MCTS-AHD, under a strict budget of 100 LLM inference calls.
- Routing Tasks: On TSP-50, TSP-100, and TSP-200, LHS achieved the lowest objective costs (e.g., an objective score of 12.49 on TSP-200 compared to FunSearch's 13.18). It similarly achieved the best average objectives on CVRP-50 and CVRP-100.
- Ablation Success: In an ablation study on TSP, omitting the normalizing flow (searching directly in the raw embedding space $Z$) caused the program execution success rate to drop from 74% to 61%, validating the critical role of the structured prior space.
Limitations and Future Work
- Upfront Data Cost: LHS requires a pre-existing corpus of diverse heuristics to train the normalizing flow, mapper, and surrogate. While the flow and mapper learn general properties of program syntax and can be amortized across tasks, it is less ideal for entirely novel problems with zero training data.
- Surrogate Distribution Shift: As gradient ascent pushes latents far from the initial training distribution, the surrogate can suffer from distribution shift, leading to "false ascents" where predicted improvements do not manifest in actual execution.
- Hybridization: The authors note that a promising future direction is hybridizing LHS with discrete evolutionary operators (like mutation and crossover) to combine global discrete exploration with precise local gradient-based refinement.
Summary updated