TL;DR
Large Language Models (LLMs) often fail to write correct solver code for complex Vehicle Routing Problems (VRPs) due to a lack of specialized knowledge about intricate constraints. This paper introduces Decomposed Retrieval of Constraints (DRoC), a novel Retrieval-Augmented Generation (RAG) framework that breaks down complex VRPs into individual constraints, retrieves targeted documentation for each, and dynamically routes between self-debugging and external retrieval. DRoC more than doubles the accuracy of GPT-4o on complex routing tasks, paving the way for automated, expert-level optimization in logistics.
The Challenge of Complex Routing
Vehicle Routing Problems (VRPs) are classic NP-hard optimization challenges crucial for logistics, transportation, and operations research. While powerful solvers like OR-Tools and Gurobi exist, they require expert domain knowledge to program. This difficulty scales exponentially when dealing with "composite constraints"—for example, a route that must simultaneously respect vehicle capacity, customer time windows, and multiple starting depots.
Recently, researchers have tried using LLMs to automate the writing of this solver code. However, while LLMs can handle simple VRPs, they frequently hallucinate or write syntactically incorrect API calls when faced with complex, multi-constraint variants. Their training data simply lacks sufficient examples of these niche solver APIs. The authors tackle this gap by finding a way to effectively inject external solver documentation into the LLM's context without overwhelming it with irrelevant information.
Methods: Decomposed Retrieval of Constraints (DRoC)
Instead of using standard RAG—which might retrieve a generic VRP example that misses specific constraints—the authors propose the DRoC framework.
The DRoC pipeline operates through a systematic, multi-step process:
- Direct Generation & Check: The LLM first attempts to write the solver code using its internal knowledge. The code is executed, and if it fails, the Python traceback is captured.
- Dynamic Routing: An LLM "router" analyzes the error. It decides whether to self-debug (if it's a simple syntax or import error) or trigger RAG (if it's an API or logic error).
- Decomposed Retrieval: If RAG is triggered, an LLM breaks the target VRP down into individual constraints (e.g., "Capacity", "Time Windows"). The system then queries the external knowledge base (solver documentation and example code) for each constraint separately.
- Two-Stage Filtering & Merging: Because search results can be noisy, an LLM filters out irrelevant documents and summarizes the useful ones. These single-constraint contexts are merged into one comprehensive prompt, guiding the LLM to generate the final corrected code.
Datasets and Evaluation
To rigorously test the framework, the authors created a custom dataset of 48 distinct VRP variants by combining 9 different real-world constraints (e.g., Pickup and Delivery, Open Route, Prize Collecting, Service Time). They crafted simple, verifiable instances for each variant, establishing ground truth optimal solutions using the Hybrid Genetic Search (HGS) solver or OR-Tools with extended search times. To prove the framework isn't limited to VRPs, they also evaluated DRoC on Facility Location Problems (FLPs) and Worker Assignment Problems.
Key Insights
- Vanilla RAG can hurt performance: Standard RAG sometimes degrades performance, especially on models like GPT-3.5. Retrieving a single monolithic document for a multi-constraint problem often introduces irrelevant or conflicting code patterns that confuse the LLM.
- Decomposition is the secret to complex coding: By retrieving knowledge for constraints individually and stitching the context together, the LLM learns to compose complex solutions from modular building blocks.
- Execution feedback + Docs = Synergy: Combining Python interpreter tracebacks with official solver documentation allows the LLM to precisely pinpoint why an API call failed and how to fix it, mimicking how a human developer reads docs after hitting an error.
- Efficiency over Evolution: Compared to recent LLM+Evolutionary Computation (EC) methods that require hundreds of thousands of tokens to iteratively evolve heuristics, DRoC achieves better objective values with a fraction of the compute by directly writing deterministic solver API code.
Key Results
DRoC demonstrated substantial improvements across multiple state-of-the-art models.
- Massive Accuracy Boost: DRoC boosted GPT-4o's Accuracy Rate (AR) from 20.83% (Standard Prompting) to 45.83% across the 48 VRP variants.
- Fewer Errors: The Runtime Error Rate (RER) dropped significantly, from 58.33% to 20.83% with GPT-4o.
- Model & Solver Agnostic: The framework consistently improved performance across multiple LLMs (GPT-3.5, GPT-4o, Claude 3.5 Sonnet, Llama 3.1 70B) and successfully generated code for both OR-Tools (API-based) and Gurobi (Mixed-Integer Programming based).
- Bootstrap Optimization: By feeding successful DRoC-generated solutions back into its own knowledge base (using its own correct outputs as future examples), the system's accuracy exceeded 50%.
Limitations and Future Work
The framework currently relies on static external knowledge sources, such as the OR-Tools documentation repository. If a highly specific constraint isn't covered in the docs, the retrieval step cannot magically invent the API logic.
Looking ahead, the authors plan to integrate DRoC with automated solver selection, allowing the LLM to choose the best underlying solver for a specific problem. They also aim to expand the external knowledge sources and integrate mathematical modeling functions directly into the framework to handle an even wider array of optimization tasks.
Summary updated