Abstract
Optimization problems are prevalent across various scenarios. Formulating and then solving optimization problems described by natural language often requires highly specialized human expertise, which could block the widespread application of optimization-based decision making. To make problem formulating and solving automated, leveraging large language models (LLMs) has emerged as a potential way. However, this kind of way suffers from the issue of optimization generalization. Namely, the accuracy of most current LLM-based methods and the generality of optimization problem types that they can model are still limited. In this paper, we propose a unified learning-based framework called LLMOPT to boost optimization generalization. Starting from the natural language descriptions of optimization problems and a pre-trained LLM, LLMOPT constructs the introduced five-element formulation as a universal model for learning to define diverse optimization problem types. Then, LLMOPT employs the multi-instruction tuning to enhance both problem formalization and solver code generation accuracy and generality. After that, to prevent hallucinations in LLMs, such as sacrificing solving accuracy to avoid execution errors, model alignment and self-correction mechanism are adopted in LLMOPT. We evaluate the optimization generalization ability of LLMOPT and compared methods across six real-world datasets covering roughly 20 fields such as health, environment, energy and manufacturing, etc. Extensive experiment results show that LLMOPT is able to model various optimization problem types such as linear/nonlinear programming, mixed integer programming and combinatorial optimization, and achieves a notable 11.08% average solving accuracy improvement compared with the state-of-the-art methods.
Introduction
Translating real-world problems described in natural language into executable solver code (e.g., Python's Pyomo) is a significant challenge in operations research. This process typically requires a rare combination of domain expertise and mathematical modeling skills. While Large Language Models (LLMs) offer a path toward automation, they frequently encounter two major hurdles: accuracy (hallucinating or missing subtle constraints) and generality (struggling with non-linear or combinatorial problems).
LLMOPT addresses these issues by creating a system capable of defining and solving general optimization problems "from scratch" with high reliability, bridging the gap between natural language descriptions and mathematical optimization solvers.
The LLMOPT Framework
The LLMOPT framework is built upon three core pillars designed to enhance both the precision and the breadth of optimization modeling:
- The Five-Element Formulation: Instead of direct code generation, LLMOPT first produces a structured intermediate representation. This "blueprint" explicitly defines Sets, Parameters, Variables, Objective, and Constraints. This step forces the model to formalize the mathematical logic before writing code.
- Multi-Instruction Learning & Alignment: The model (based on Qwen1.5-14B) undergoes Supervised Fine-Tuning (SFT) on a diverse dataset of formulations and code. To further reduce hallucinations, Kahneman-Tversky Optimization (KTO) is employed. KTO uses binary "desirability" labels to align the model with expert-validated solutions, proving more robust than standard ranking-based methods.
- Auto-Testing with Self-Correction: LLMOPT incorporates a feedback loop. If the generated code fails execution or produces errors, the model analyzes the logs to determine if the error lies in the mathematical formulation or the code itself, and then attempts a correction.
Evaluation and Datasets
LLMOPT was evaluated across six real-world datasets spanning 20 fields, including agriculture, energy, and healthcare. Key benchmarks included:
- NL4Opt: Standard linear programming word problems.
- Mamo (Easy & Complex): Academic challenges ranging from high school to undergraduate levels.
- IndustryOR: A difficult dataset covering 13 different industrial sectors.
- NLP4LP & ComplexOR: Highly complex problems sourced from textbooks and expert practitioners.
Key Insights and Results
Structure Prevents Hallucination
A primary insight of this work is that the "Five-Element" approach significantly reduces modeling errors. By requiring the model to explicitly list variables and constraints before coding, it is much less likely to miss implicit requirements, such as positive integer constraints.
Performance Benchmarks
- State-of-the-Art Accuracy: LLMOPT achieved an 11.08% average improvement in solving accuracy over previous leading methods like ORLM and OptiMUS.
- Handling Complexity: On the "Mamo Complex" dataset, LLMOPT saw a 30.1% accuracy boost compared to prior learning-based models.
- Efficiency and Generalization: The model maintained its general language capabilities (with only a 0.3% performance change on non-optimization tasks) while outperforming much larger models like GPT-4o in specialized engineering tasks.
Limitations and Future Work
Despite its success, LLMOPT faces challenges in scaling the initial expert labeling required for "seed" data. Furthermore, while it excels at natural language descriptions, many industrial problems are defined by data in databases or spreadsheets; future iterations will need to address direct data ingestion. Finally, performance on highly complex industrial datasets like IndustryOR (46% accuracy) indicates room for further refinement in handling intricate, real-world constraints.
Summary updated