ReLoop: Structured Modeling and Behavioral Verification for Reliable LLM-Based Optimization
Organizations: Institute of Operations Research and Analytics, National University of Singapore · McCormick School of Engineering, Northwestern University · Wenzhou Buyi Pharmacy Chain Co., Ltd. · College of Computer Science and Artificial Intelligence, Wenzhou University · Department of Decision Analytics and Operations, City University of Hong Kong
Abstract
Large language models (LLMs) can translate natural-language problem descriptions into optimization code, but the code is prone to silent failures: it executes and returns a solver-feasible solution while encoding a semantically incorrect formulation. On compositional problems, the resulting feasibility-correctness gap reaches 90 percentage points. We introduce ReLoop, which combines two mechanisms. Structured generation decomposes code production into a four-stage reasoning chain (understand, formalize, synthesize, verify) to reduce formulation errors during generation. Behavioral verification detects the errors that remain by testing whether the formulation responds correctly to solver-based parameter perturbation, a signal that comes from the solver rather than from LLM self-review and requires no ground truth. The two mechanisms address different error structures: structured generation gives the largest gain on compositional problems (+8.5pp accuracy on RetailOpt-190 with Claude Opus 4.6), and behavioral verification gives its largest gain on localized defects (+4.4pp on MAMO-ComplexLP). With diagnostic execution recovery, ReLoop reaches 100% executable code on Claude Opus 4.6, and relative to direct generation it raises or preserves every reported metric of the three chat-tuned foundation models on all three benchmarks. For the narrowly fine-tuned SFT model we test, the chain-of-thought prompt conflicts with its learned output format and lowers its accuracy on MAMO-ComplexLP; we document and analyze this interaction. We release RetailOpt-190, 190 compositional retail optimization scenarios in which several constraints interact.
Figures & tables
| Method | Detects Silent | External | No Ground | Iterative |
|---|---|---|---|---|
| Failures | Signal | Truth | Repair | |
| Solver feedback [ 10 ] | ✗ | ✓ | ✓ | ✗ |
| OptiChat [ 12 ] | ✗ | ✓ | ✓ | ✓ |
| Self-Refine [ 1 ] | ✗ | ✗ | ✓ | ✓ |
| Reflexion [ 3 ] | ✗ | ✓ | ✓ | ✓ |
| SAC-Opt [ 14 ] | ✓ | ✗ | ✓ | ✓ |
| Layer | Check | Severity | Action |
| L1: Execution (blocking) | Syntax / runtime error | Fatal | Regenerate |
| Infeasible | Fatal | Regen. (IIS) | |
| Unbounded | Fatal | Regen. (ray) | |
| Duality gap † | Info | None | |
| L2: CPT (diagnostic) | Missing ( ) | Warning | Repair |
| Uncertain ( ) † | Info | None |
| Defect | L2 behavior |
|---|---|
| Missing parameter-governed constraint | Detected (CPT) |
| Missing objective term | Detected (OPT) |
| Present-but-wrong constraint reusing the same parameters | Partial / not detected |
| Coefficient-magnitude errors | Not detected |
| Equivalent-looking but structurally different decompositions | Not detected |
| Errors inducing infeasibility or unboundedness | Handled by L1 (IIS / rays) |
| Benchmark | Domain | Inst. | Multi-period | Compositional | Data-Code Sep. |
|---|---|---|---|---|---|
| NL4Opt [ 22 ] | Generic | 289 | Few | ✗ | ✗ |
| MAMO [ 23 ] | Generic | 800 | Some | ✗ | ✗ |
| IndustryOR [ 7 ] | Mixed | 100 | Some | ✗ | ✗ |
| OptMATH [ 9 ] | Mixed | 360 | Some | ✗ | ✗ |
| RetailOpt-190 | Retail | 190 | All | ✓ | ✓ |
| ID | Family | Arch. | Key Mechanisms |
|---|---|---|---|
| F1 | Core Operations | 4 | Multi-period inventory, perishability, lost sales |
| F2 | Assortment & Substitution | 6 | Product substitution, promotions, price bands |
| F3 | Resource Constraints | 4 | Storage bottleneck, supply limits, volumetric |
| F4 | Demand Dynamics | 6 | Demand surge, supply risk, quality holds |
| F5 | Feasibility Stress | 4 | Impossible demand, storage overflow, service traps |
| F6 | Discrete Logistics | 4 | Lead time, MOQ, pack size, fixed order cost |
| Exec% | Acc%( ) | Acc%( ) | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Type | Model | Base | CoT | ReLoop | Base | CoT | ReLoop | Base | CoT | ReLoop |
| Foundation | Claude Opus 4.6 | 72.1 | 93.7 | 100.0 | 22.6 | 31.1 | 31.1 | 26.8 | 34.7 | 35.3 |
| DeepSeek-V3.2 | 91.1 | 53.2 | 97.4 | 0.5 | 3.7 | 5.8 | 3.7 | 5.8 | 11.1 | |
| Qwen3-32B | 0.0 | 0.0 | 2.1 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | |
| Offline SFT | OptMATH-32B | 2.6 | 2.6 | 17.9 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.5 |
| Online RL | SIRL-32B | 0.0 | 0.0 | 1.6 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| MAMO-ComplexLP | IndustryOR | ||||||
|---|---|---|---|---|---|---|---|
| Type | Model | Base | CoT | +ReLoop | Base | CoT | +ReLoop |
| Foundation | Claude Opus 4.6 | 70.4 | 73.9 | 79.8 | 66.0 | 66.0 | 68.0 |
| DeepSeek-V3.2 | 60.1 | 59.6 | 62.6 | 50.0 | 54.0 | 62.0 | |
| Qwen3-32B | 40.4 | 37.4 | 46.3 | 43.0 | 43.0 | 46.0 | |
| Offline SFT | OptMATH-32B | 56.2 | 30.0 | 31.0 | 34.0 | 31.0 | 34.0 |
| Online RL | SIRL-32B | 53.2 | 46.8 | 54.2 | 40.0 | 40.0 | 43.0 |
| RetailOpt-190 | MAMO-ComplexLP ( ) | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Claude Opus 4.6 | DeepSeek-V3.2 | Claude Opus 4.6 | DeepSeek-V3.2 | |||||||
| Config | Exec | Acc | Acc | Exec | Acc | Acc | Exec | Acc | Exec | Acc |
| Direct | 72.1 | 22.6 | 26.8 | 91.1 | 0.5 | 3.7 | 94.1 | 70.4 | 93.6 | 60.1 |
| +CoT | 93.7 | 31.1 | 34.7 | 53.2 | 3.7 | 5.8 | 95.6 | 73.9 | 87.7 | 59.6 |
| +CoT+L1 | 99.5 | 31.1 | 35.3 | 97.4 | 5.8 | 10.5 | 98.0 | 75.4 | 88.7 | 60.6 |
| +CoT+L1+L2 | 100.0 | 31.1 | 35.3 | 97.4 | 5.8 | 11.1 | 98.0 | 79.8 | 88.7 | 62.6 |
Appendix figures & tables17 assets
Supplementary material from the paper’s appendix.
Appendix
| Variable | Domain | Interpretation |
|---|---|---|
| Start-of-period inventory of product at location | ||
| in period with periods of remaining life | ||
| Sales from remaining-life bucket in period | ||
| Order quantity placed for product at location in period | ||
| Waste (expired units) at end of period | ||
| Lost sales (unmet demand) in period |
| Family | Constraint | Design Rationale |
|---|---|---|
| C1. Initialization | Without zero initialization for non-fresh buckets, unbounded phantom inventory yields objective (D1). | |
| C2. Fresh inflow | where if , else ; ; if , else . | Fresh inventory enters only via ordering, transshipment, and returns. LLMs that subtract sales in this equation effectively double-count demand fulfillment. |
| C3. Aging dynamics | Remaining life decrements each period: bucket today becomes bucket tomorrow, minus sales. Incrementing instead causes fresh stock to expire immediately (D2). | |
| C4. Expiration | Only bucket can expire. Unsold units from the oldest bucket become waste; waste is not carried forward. | |
| C5. Sales availability | Cannot sell more than on-hand inventory in each remaining-life bucket. Without this, the solver can create phantom sales. | |
| C6. Demand conservation | with , , (demand-route bound), and (inventory-backed substitution). | Reversing edge direction is a common modeling mistake (D4): means ’s demand exported to ’s inventory, not the reverse. The demand-route and inventory-backed bounds together prevent unbounded substitution flow. |
| ID | Family | #Arc. | Perish. | Capacity | Subst. | Discrete | Network | Primary Test |
|---|---|---|---|---|---|---|---|---|
| F1 | Core Operations | 4 | ✓ | – | – | Aging dynamics | ||
| F2 | Assortment | 6 | ✓ | ✓ | ✓ | – | Substitution capacity | |
| F3 | Resources | 4 | ✓ | ✓ | – | – | Multi-resource coupling | |
| F4 | Dynamics | 6 | ✓ | ✓ | – | – | Temporal propagation | |
| F5 | Feasibility Stress | 4 | ✓ | ✓ | – | – | – | Stress robustness |
| F6 | Discrete Logistics | 4 | ✓ | ✓ | – | Integer constraints |
| Family | Archetype ID | Modification from Base Scenario |
| F1 | f1_base | Baseline: 20 periods, 3 SKUs, 5 DCs, seasonal Gaussian demand |
| f1_high_waste | Waste cost for all products | |
| f1_jit_logic | Holding cost for all products | |
| f1_52_weeks | Horizon extended to (demand/capacity arrays tiled from base) | |
| F2 | f2_no_substitution | Substitution edges removed ( ) |
| f2_circular_sub | Circular substitution ring: Basic Premium ShortLife Basic |
| Parameter | Value | Description |
| 20 | Planning periods | |
| 3 | SKU_Basic, SKU_Premium, SKU_ShortLife | |
| 5 | DC1 through DC5 | |
| Shelf life | Periods remaining at production | |
| Lead time | Same-period arrival (default) | |
| Demand curve | Gaussian: | Seasonal peak at mid-horizon ( is 0-indexed); SKU_Premium , SKU_ShortLife ; values cast to int in generator |
| Format | Data Location | Content | Use Case | File Suffix |
|---|---|---|---|---|
| Schema-based | External (runtime) | Narrative + JSON schema (types only) | Scalability, production | .scenario.txt |
| Data-embedded | In prompt | Narrative + full JSON data | Benchmark comparison | .full.txt |
| Provided in Prompt | Left for LLM to Derive |
|---|---|
| Business narrative with structure cues | Complete formulation (variables, objective, constraints) |
| Data schema (field names, types) | Capacity, demand, and budget constraints |
| Data access patterns (indexing, nesting) | Substitution and inventory dynamics constraints |
| Output format specification (GurobiPy) | Boundary conditions / edge cases |
| Inventory inflow accounting (URS-aligned) | Common error warnings |
| Field | Type | Example | Semantics |
| periods | int | 20 | Number of planning periods |
| products | [str] | ["SKU_Basic",...] | Product identifiers |
| locations | [str] | ["DC1",...] | Location identifiers |
| shelf_life | {str:int} | {"SKU_Basic":10} | Remaining-life capacity per SKU |
| lead_time | {str:int} | {"SKU_Basic":0} | Order-to-arrival delay (periods) |
| demand_curve | {str:[float]} | [303,311,...] | Aggregate demand per SKU per period (0-indexed) |
| Prompt Section | Schema-based | Data-embedded |
| [SCENARIO] header | ✓ | ✓ |
| [BUSINESS DESCRIPTION] | ✓ | ✓ |
| [DATA SCHEMA] (types) | ✓ | – |
| [DATA ACCESS] (runtime) | ✓ | – |
| [DATA] (full JSON inline) | – | ✓ |
| [OUTPUT FORMAT] | ✓ | ✓ |
| Parameter | Value | Purpose |
|---|---|---|
| TimeLimit | 60 seconds | Prevent stalling on complex MIPs (F6/F7) |
| MIPGap | 1% | Tolerance for near-optimal solutions |
| Threads | 1 | Single-threaded for reproducibility |
| Seed | 0 | Fixed random seed |
| OutputFlag | 0 | Suppress solver output for batch processing |
| Families | Problem Type | Tolerance | Rationale |
|---|---|---|---|
| F1–F5, F7–F8 | LP / easy MIP | (strict) / (practical) | LP relaxation tight; optimal is exact |
| F6 | Hard MIP (MOQ, pack size) | (both tiers) | 60s time limit may yield near-optimal solutions; pack-size rounding creates inherent gaps |
| Layer | Parameter | Value | Description |
| L1 Execution | timeout | 60 s | Subprocess execution timeout |
| max_regenerations | 3 | Regeneration attempts on Fatal | |
| duality_gap_threshold | 0.01 | Primal–dual gap threshold (1%, Info only) | |
| L2 CPT (Constraint Presence) | missing_threshold | 0.05 | change Warning |
| uncertain_threshold | 0.30 | 5–30% change Info | |
| max_candidates | 10 | Max constraints to test per problem |
| Benchmark | Families | Problem Type | Tolerance |
|---|---|---|---|
| RetailOpt-190 | F1–F5, F7–F8 | LP | (strict) / (practical) |
| RetailOpt-190 | F6 | MIP | (both tiers) |
| MAMO-ComplexLP | – | LP | |
| IndustryOR | – | Mixed |
| Type | Model | Provider | Temp. | Max Tokens | Notes |
|---|---|---|---|---|---|
| Foundation | Claude Opus 4.6 | Anthropic API | 0.0 | 8192 | |
| Foundation | DeepSeek-V3.2 | DeepSeek API | 0.0 | 8192 | |
| Foundation | Qwen3-32B | Local (vLLM [ 27 ] ) | 0.0 | 8192 | BF16 |
| Offline SFT | OptMATH-Qwen2.5-32B | Local (vLLM) | 0.0 | 8192 | BF16 |
| Online RL | SIRL-Qwen2.5-32B | Local (vLLM) | 0.0 | 8192 | BF16 |
| Benchmark | Instances | Avg Tokens | Tolerance | Format |
|---|---|---|---|---|
| RetailOpt-190 | 190 | 2,900 | / | Data-embedded |
| MAMO-ComplexLP | 203 | 459 | Data-embedded | |
| IndustryOR | 100 | 267 | Data-embedded |
| Claude Opus 4.6 | DeepSeek V3.2 | Qwen3-32B | OptMATH-32B | SIRL-32B | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Family | # | Base | +ReLoop | Base | +ReLoop | Base | +ReLoop | Base | +ReLoop | Base | +ReLoop |
| F1 Core Ops | 20 | 55.0 | 95.0 | 5.0 | 5.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| F2 Assort & Sub | 30 | 50.0 | 53.3 | 0.0 | 3.3 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| F3 Resource | 20 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| F4 Demand Dyn | 30 | 3.3 | 20.0 | 0.0 | 10.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| F5 Feasibility | 20 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| Typed routing | Taxonomy-free | |||
|---|---|---|---|---|
| (bidirectional) | ||||
| Recall | 238/240 | 238/240 | 238/240 | 238/240 |
| Intact-code FP | 63/240 | 64/240 | 64/240 | 54/240 |