LLMOPT: Learning to Define and Solve General Optimization Problems from Scratch

Caigao Jiang, Xiang Shu, Hong Qian, Xingyu Lu, Jun Zhou, Aimin Zhou, Yang Yu

TL;DR

LLMOPT is a new framework that enables Large Language Models (LLMs) to formulate and solve complex optimization problems directly from natural language descriptions. By introducing a structured "five-element" intermediate representation and a self-correction loop, it achieves an 11.08% average accuracy boost over state-of-the-art methods like GPT-4 across diverse real-world scenarios.

What Problem Does This Paper Address?

In the world of operations research, turning a business problem (e.g., "How do I schedule 500 flights with minimum fuel?") into a mathematical model is a "bottleneck" task. It requires highly specialized human experts to identify variables, constraints, and objectives from messy natural language.

While LLMs like GPT-4 are good at writing code, they suffer from poor optimization generalization. They often struggle with diverse problem types (linear vs. nonlinear) or "hallucinate" solutions—writing code that runs perfectly but solves the wrong mathematical problem because it missed an implicit constraint (like "you can't hire half a person").

Methods

The authors propose LLMOPT, a unified learning-based framework built on three pillars:

LLMOPT's Five-Element Formulation bridges the gap between natural language and correct solver code.
  1. The Five-Element Formulation: Instead of asking the LLM to jump straight from text to Python code, LLMOPT forces it to first define the problem using five universal elements: Sets, Parameters, Variables, Objective, and Constraints. This structured intermediate step acts as a "mental scaffold" that reduces logical errors.
  2. Multi-Instruction Supervised Fine-Tuning (SFT) & Alignment: The model (based on Qwen-1.5-14B) is trained on two distinct tasks: translating text to the five-element model, and translating that model into executable Pyomo code. To further reduce hallucinations, they use Kahneman-Tversky Optimization (KTO), an alignment technique that helps the model distinguish between "True" (mathematically sound) and "False" (plausible but wrong) formulations.
  3. Self-Correction Mechanism: If the generated code fails or produces an error, LLMOPT enters an automated "auto-testing" loop. It analyzes the execution logs and error messages to refine its own mathematical formulation or code until a valid solution is found.

Datasets

The researchers evaluated LLMOPT across six diverse, real-world datasets covering roughly 20 fields (health, energy, manufacturing, etc.):

  • NL4Opt: A benchmark for natural language to optimization.
  • Mamo (Easy & Complex): High-school and undergraduate-level challenges.
  • IndustryOR: A dataset of real-world industrial operations research problems.
  • NLP4LP & ComplexOR: Advanced textbook and specialist-curated scenarios.

To train the model, they performed massive data augmentation, using LLMs to transform 1,763 "seed" problems into nearly 10,000 high-quality training instances through various instruction-based modifications.

Key Insights and Ideas

  • Structure Beats Raw Power: Even a 14B parameter model (LLMOPT) can outperform a massive model like GPT-4 if it is taught to follow a structured mathematical "grammar" (the five elements).
  • The "Plausibility Trap": The authors found that LLMs often sacrifice mathematical accuracy just to make the code "runnable." The KTO alignment is critical here because it penalizes the model for these "successful-but-wrong" executions.
  • Universal Logic: The framework proves that optimization logic is remarkably consistent across fields. Whether it's a portfolio in finance or a supply chain in manufacturing, the "five-element" structure remains a valid bridge.
  • No "Seesaw Effect": Often, fine-tuning a model for a specific task makes it worse at general tasks (like basic QA or coding). LLMOPT managed to improve optimization performance without degrading the model's general capabilities.

Key Results

  • SOTA Performance: LLMOPT achieved an average 11.08% improvement in solving accuracy (SA) compared to previous state-of-the-art methods.
  • Complex Problem Solving: On the "Mamo Complex" dataset, LLMOPT improved accuracy by a staggering 30.1% over existing learning-based methods.
  • Efficiency: The self-correction mechanism significantly reduced the "Average Solving Times" (AST), meaning the model finds the correct answer in fewer iterations than GPT-4.
  • Generality: The model successfully handled linear programming, mixed-integer programming, and even complex combinatorial optimization like the Traveling Salesman Problem.

Limitations and Future Work

  • Data Scarcity: While augmentation helps, high-quality, expert-labeled optimization data remains rare and expensive to produce.
  • Large-Scale Data Structures: In real industrial settings, problem parameters aren't always in a text paragraph; they are often buried in massive databases or CSV files. The authors note that teaching LLMs to "read" these data structures directly is a necessary next step.
  • Expert Dependency: The initial labeling process still requires significant human expert intervention to ensure the "ground truth" is actually optimal.

Summary updated

BibTeX
@inproceedings{jiang2025llmopt,
  author = {Caigao JIANG and Xiang Shu and Hong Qian and Xingyu Lu and JUN ZHOU and Aimin Zhou and Yang Yu},
  title = {{LLMOPT: Learning to Define and Solve General Optimization Problems from Scratch}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=9OMvtboTJg},
}
Figure