SAC-Opt: Semantic Anchors for Iterative Correction in Optimization Modeling
Abstract
Large language models (LLMs) have opened new paradigms in optimization modeling by enabling the generation of executable solver code from natural language descriptions. Despite this promise, existing approaches typically remain solver-driven: they rely on single-pass forward generation and apply limited post-hoc fixes based on solver error messages, leaving undetected semantic errors that silently produce syntactically correct but logically flawed models. To address this challenge, we propose SAC-Opt, a backward-guided correction framework that grounds optimization modeling in problem semantics rather than solver feedback. At each step, SAC-Opt aligns the original semantic anchors with those reconstructed from the generated code and selectively corrects only the mismatched components, driving convergence toward a semantically faithful model. This anchor-driven correction enables fine-grained refinement of constraint and objective logic, enhancing both fidelity and robustness without requiring additional training or supervision. Empirical results on seven public datasets demonstrate that SAC-Opt improves average modeling accuracy by 7.7%, with gains of up to 21.9% on the ComplexLP dataset. These findings highlight the importance of semantic-anchored correction in LLM-based optimization workflows to ensure faithful translation from problem intent to solver-executable code.
Lay Summary
Optimization software can help people make better decisions in areas such as logistics, healthcare, and finance, but using it usually requires experts to turn real-world descriptions into precise solver code. Large language models can now write such code from plain language, yet current systems often treat a program as successful once it runs without errors. This misses a dangerous kind of mistake: the code may be executable but still express the wrong meaning, such as turning "at most" into "at least." SAC-Opt addresses this by checking the generated code against the original problem intent. It first identifies the key rules and goal in the problem description, then reads the generated code back into these same pieces and compares them one by one. If one piece does not match, SAC-Opt corrects only that part and repeats the check. This backward checking process helps the code gradually become faithful to the original problem, without retraining the language model. Across seven public test collections, SAC-Opt improves modeling accuracy by 7.7% on average, with gains of up to 21.9% on ComplexLP, making AI-assisted optimization modeling more reliable for non-experts.