Autoformulation of Mathematical Optimization Models Using LLMs

Nicolás Astorga, Tennison Liu, Yuanzhang Xiao, Mihaela van der Schaar

Mathematical optimization is the engine behind global logistics, healthcare scheduling, and financial portfolios. However, there is a significant "formulation bottleneck": translating a messy, unstructured business problem (e.g., "A farmer has 10 acres and a $100 budget...") into a rigorous system of variables, objectives, and constraints requires rare, specialized expertise.

While Large Language Models (LLMs) are surprisingly adept at writing code, they struggle with the precision required for optimization. They often hallucinate constraints, define redundant variables, or fail to explore the vast hypothesis space of possible formulations. This paper tackles autoformulation: the automated creation of correct, solver-ready models directly from natural language.

The researchers introduce a novel framework that combines LLMs with Monte-Carlo Tree Search (MCTS) to automate this process. By breaking the modeling process into a hierarchy and using symbolic solvers to prune redundant ideas, their method significantly outperforms existing "one-shot" or iterative LLM approaches across multiple real-world benchmarks.

Methods: The MCTS-Based Autoformulator

The authors conceptualize autoformulation as a search problem rather than a simple translation task. Their approach relies on three key pillars:

Overview of the autoformulation framework using MCTS and symbolic pruning.
  1. Hierarchical Decomposition: Instead of asking an LLM to generate a whole model at once, the process is broken into four sequential stages: (1) Parameters and Variables, (2) Objective Function, (3) Equality Constraints, and (4) Inequality Constraints. This structure turns the problem into a search tree with a depth of four.
  2. Monte-Carlo Tree Search (MCTS): The system uses MCTS to navigate this tree. LLMs act as "hypothesis generators" at each node, proposing multiple ways to define variables or constraints. The search balances exploration (trying new modeling ideas) with exploitation (refining the most promising paths).
  3. Symbolic Pruning & Evaluation: To keep the search efficient, the authors use Satisfiability Modulo Theories (SMT) solvers. These symbolic tools check if two different-looking math expressions are functionally identical (e.g., $2x + 3y \leq 10$ vs. $3y + 2x \leq 10$). If they are, the redundant branch is pruned. Additionally, LLMs are used to rank partial formulations to guide the search toward the most correct branches.

Datasets and Key Insights

The method was evaluated on four diverse benchmarks containing Linear Programming (LP) and Mixed-Integer Linear Programming (MILP) problems: NLP4OPT (244 problems), IndustryOR (100 problems), ComplexOR (37 problems), and MAMO (211 problems).

During their evaluation, the researchers uncovered several critical insights:

  • Search Beats Prompting: Systematic exploration via MCTS is far superior to simple iterative refinement (like the "Reflexion" method). By maintaining a tree of possibilities, the system can recover from early mistakes that would derail a linear conversation.
  • The Power of Symbolic Pruning: LLMs are notoriously bad at recognizing when two math expressions are equivalent. By offloading this to a symbolic SMT solver, the researchers reduced the search space by roughly 80%, making the MCTS process computationally feasible.
  • Relative Ranking > Absolute Scoring: Asking an LLM to give an absolute "score" to a model is inconsistent. However, asking it to rank several candidate formulations against a baseline provides a much more robust signal for guiding the search.

Key Results

The MCTS-based approach demonstrated a massive performance leap over standard LLM prompting and specialized fine-tuned models.

Performance comparison of the Autoformulator against baseline methods across multiple benchmarks.
  • Accuracy Gains: On the NLP4OPT benchmark, the Autoformulator achieved 92.6% accuracy, compared to just 47.3% for standard GPT-4 prompting and 78.8% for the previous state-of-the-art specialized agent (OptiMUS).
  • Efficiency: With just a single "rollout" (one path through the tree), the method matched or beat specialized models that were specifically fine-tuned on optimization data (like ORLM).
  • Robustness: The system performed consistently well across easy, medium, and hard problems, whereas baseline LLMs saw their performance crater as problem complexity increased.

Limitations and Future Work

While highly effective, the framework has room for growth. SMT Decidability is a current limitation; while symbolic pruning works perfectly for linear math, it becomes undecidable for certain complex non-linear or mixed-integer functions. The authors currently use a conservative approach here, but more advanced symbolic logic is needed.

Additionally, the current system excels at inherently convex problems but needs more "creativity" to handle complex reformulations that require clever mathematical tricks (like change of variables or semidefinite relaxation). Finally, the authors suggest that future versions should incorporate a Human-in-the-Loop design, allowing domain experts to interact with the MCTS tree and provide "nudges" to incorporate nuanced business requirements not explicitly stated in the text.

Summary updated

BibTeX
@inproceedings{astorga2025autoformulation,
  author = {Nicolás Astorga and Tennison Liu and Yuanzhang Xiao and Mihaela van der Schaar},
  title = {{Autoformulation of Mathematical Optimization Models Using LLMs}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=33YrT1j0O0},
}
Figure