做组合优化或约束求解的开发者,这篇论文用实验数据告诉你为什么别让LLM碰搜索优化——它可能让你的求解器变慢还出错。建议读读,避免踩坑。
该研究提出CP-SynC-XL基准(100个组合问题,4577个实例),评估三种求解器构建范式:原生Python算法搜索、Python+OR-Tools约束建模、MiniZinc+OR-Tools声明式建模。结果显示,Python+OR-Tools正确率最高,而原生Python易产生格式正确但验证失败的方案。提示模型进行搜索优化仅带来1.03-1.12倍的中位加速,但许多实例反而变慢,且正确率在长尾问题上显著下降。代码审计发现,优化提示会导致模型用局部近似替代完整搜索、注入未验证的边界或添加冗余声明式机制,陷入“启发式陷阱”。研究建议:LLM应主要用于形式化变量、约束和目标,而搜索优化需单独验证。
Formalize, Don't Optimize: The Heuristic Trap in LLM-Generated Combinatorial Solvers
Large Language Models (LLMs) struggle to solve complex combinatorial problems through direct reasoning, so recent neuro-symbolic systems increasingly use them to synthesize executable solvers. A central design question is how the LLM should represent the solver, and whether it should also attempt to optimize search. We introduce CP-SynC-XL, a benchmark of 100 combinatorial problems (4,577 instances), and evaluate three solver-construction paradigms: native algorithmic search (Python), constraint modeling through a Python solver API (Python + OR-Tools), and declarative constraint modeling (MiniZinc + OR-Tools). We find a consistent representational divergence: Python + OR-Tools attains the highest correctness across LLMs, while MiniZinc + OR-Tools has lower absolute coverage despite using the same OR-Tools back-end. Native Python is the most likely to return a schema-valid solution that fails verification, whereas solver-backed paths preserve higher conditional fidelity. On the heuristic axis, prompting for search optimization yields only small median speed-ups (1.03-1.12x) and a strongly bimodal effect: many instances slow down, and correctness drops sharply on a long tail of problems. A paired code-level audit traces these regressions to a recurring heuristic trap. Under an efficiency-oriented prompt, the LLM may replace complete search with local approximations (Python), inject unverified bounds (Python + OR-Tools), or add redundant declarative machinery that overwhelms or over-constrains the model (MiniZinc + OR-Tools). These findings support a conservative design principle for LLM-generated combinatorial solvers: use the LLM primarily to formalize variables, constraints, and objectives for verified solvers, and separately check any LLM-authored search optimization before use.