or-bench-problems / demo /src /explain.py
alirezaaminzadeh's picture
Publish ORBench 100-problem catalog and recorded results
3dfd4ca verified
Raw History Blame Contribute Delete
4.8 kB
from __future__ import annotations
from src.domain import EvalRow, SolveStatus
from src.validation import ValidationReport
def status_label(status: str, lang: str = "en") -> str:
mapping = {
"en": {
"optimal": "Proven optimal (within the model)",
"feasible": "Feasible incumbent within the time limit — not proven optimal",
"heuristic": "Heuristic feasible candidate — not a proven optimum",
"infeasible": "Proven infeasible under the stated constraints",
"timeout": "No plan found before the time limit — this is not a proof of infeasibility",
"invalid": "Invalid input or schema",
"error": "Solver error",
"not_evaluated": "Not evaluated — no run, so this is not a score of 0",
},
"fa": {
"optimal": "بهینه اثبات‌شده در مدل",
"feasible": "جواب شدنی در مهلت — بهینه بودن اثبات نشده",
"heuristic": "نامزد شدنی ابتکاری — بهینه اثبات‌شده نیست",
"infeasible": "ناممکن اثبات‌شده با قیود فعلی",
"timeout": "در مهلت جوابی پیدا نشد — این اثبات ناممکن بودن نیست",
"invalid": "ورودی یا schema نامعتبر",
"error": "خطای حل‌گر",
"not_evaluated": "ارزیابی نشده — اجرا نشده و این صفر یا رتبه نیست",
},
}
return mapping.get(lang, mapping["en"]).get(status, status)
def numeric_reasons(problem, rows: list[EvalRow], report: ValidationReport | None, lang: str = "en") -> list[str]:
lines: list[str] = []
if lang == "fa":
lines.append(
f"{problem.problem_id} خانواده {problem.family.value}، دشواری {problem.difficulty.value}، "
f"وضعیت طلایی {problem.gold_status}، هدف طلایی {problem.gold_objective}."
)
else:
lines.append(
f"{problem.problem_id} is a {problem.difficulty.value} {problem.family.value} instance. "
f"Gold status {problem.gold_status}, gold objective {problem.gold_objective}."
)
by_id = {row.method_id: row for row in rows if row.evaluated}
structured = by_id.get("structured-solver")
heuristic = by_id.get("heuristic")
if structured and heuristic and structured.objective is not None and heuristic.objective is not None:
delta = float(heuristic.objective) - float(structured.objective)
if lang == "fa":
lines.append(f"هدف ابتکاری {heuristic.objective} در برابر حل‌گر {structured.objective} (اختلاف {delta:+.3f}).")
else:
lines.append(f"Heuristic objective {heuristic.objective} vs solver {structured.objective} (delta {delta:+.3f}).")
extractor = by_id.get("template-extractor+solver")
if extractor and extractor.constraint_fidelity is not None:
if lang == "fa":
lines.append(f"وفاداری استخراج قالب {extractor.constraint_fidelity:.3f}؛ parse={'موفق' if extractor.parse_success else 'ناموفق'}.")
else:
lines.append(f"Template-extractor fidelity {extractor.constraint_fidelity:.3f}; parse={'ok' if extractor.parse_success else 'failed'}.")
naive = by_id.get("naive-direct")
if naive and naive.violated:
if lang == "fa":
lines.append(f"پاسخ مستقیم ساده‌لوح قیود را نقض کرد: {', '.join(naive.violated[:6])}.")
else:
lines.append(f"Naive direct answer violated: {', '.join(naive.violated[:6])}.")
if report and not report.ok:
codes = ", ".join(report.failed_codes()[:6])
if lang == "fa":
lines.append(f"validator مستقل قیود نقض‌شده را گزارش کرد: {codes}.")
else:
lines.append(f"Independent validator flagged: {codes}.")
if problem.gold_status == SolveStatus.INFEASIBLE.value:
if lang == "fa":
lines.append("این نمونه ناممکن طراحی شده است. خانه‌های مدل اجرا‌نشده «ارزیابی نشده» می‌مانند.")
else:
lines.append("This instance is designed to be infeasible. Unevaluated model cells stay not_evaluated.")
if lang == "fa":
lines.append("امتیاز یک مدل زبانی داور نیست؛ validator عددی مرجع است. مسیر پاسخ مستقیم فقط برای بنچمارک است.")
else:
lines.append("An LLM score is not the judge. The numeric validator is the reference. Direct answers are benchmark-only.")
return lines[:8]