feat: report prints the actually maximized objective
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
98eeb18e3c
commit
57c2157134
1 changed files with 28 additions and 1 deletions
29
solve.py
29
solve.py
|
|
@ -1682,6 +1682,8 @@ def solve(
|
||||||
capital_spent,
|
capital_spent,
|
||||||
fence_deposits,
|
fence_deposits,
|
||||||
baron_deposits,
|
baron_deposits,
|
||||||
|
obj_factors=obj_factors,
|
||||||
|
obj_mode=objective_mode,
|
||||||
)
|
)
|
||||||
return solver, status
|
return solver, status
|
||||||
|
|
||||||
|
|
@ -1736,6 +1738,8 @@ def _report(
|
||||||
capital_spent=None,
|
capital_spent=None,
|
||||||
fence_deposits=None,
|
fence_deposits=None,
|
||||||
baron_deposits=None,
|
baron_deposits=None,
|
||||||
|
obj_factors=None,
|
||||||
|
obj_mode=None,
|
||||||
):
|
):
|
||||||
print("status:", solver.StatusName(status))
|
print("status:", solver.StatusName(status))
|
||||||
if status not in (cp_model.OPTIMAL, cp_model.FEASIBLE):
|
if status not in (cp_model.OPTIMAL, cp_model.FEASIBLE):
|
||||||
|
|
@ -1890,9 +1894,32 @@ def _report(
|
||||||
)
|
)
|
||||||
|
|
||||||
fe, fb, fs = solver.Value(finalE), solver.Value(finalB), solver.Value(finalS)
|
fe, fb, fs = solver.Value(finalE), solver.Value(finalB), solver.Value(finalS)
|
||||||
|
vals = {"E": fe, "B": fb, "S": fs, "C": solver.Value(C[NUM_STEPS + 1])}
|
||||||
|
if obj_factors is None:
|
||||||
|
# Legacy fallback: old hardcoded E*B*S display.
|
||||||
|
obj_str = f"product(scaled) = {fe * fb * fs / 1000}"
|
||||||
|
elif obj_mode == "sum":
|
||||||
|
terms = [
|
||||||
|
f"{f}{k}" if abs(f) != 1 else (k if f > 0 else f"-{k}")
|
||||||
|
for k, f in obj_factors.items()
|
||||||
|
if f
|
||||||
|
]
|
||||||
|
expr = " + ".join(terms).replace("+ -", "- ")
|
||||||
|
raw = sum(f * vals[k] for k, f in obj_factors.items())
|
||||||
|
obj_str = f"objective {expr} = {raw / 10:.1f}"
|
||||||
|
else:
|
||||||
|
expr = "*".join(
|
||||||
|
k if f == 1 else f"{k}^{f}" for k, f in obj_factors.items() if f
|
||||||
|
)
|
||||||
|
raw, n = 1, 0
|
||||||
|
for k, f in obj_factors.items():
|
||||||
|
raw *= vals[k] ** f
|
||||||
|
n += f
|
||||||
|
# Resource values are x10-scaled, so descale by 10^(sum of exponents).
|
||||||
|
obj_str = f"objective {expr} = {raw / 10**n}"
|
||||||
print(
|
print(
|
||||||
f"\nFINAL E={fe / 10:.1f} B={fb / 10:.1f} S={fs / 10:.1f} "
|
f"\nFINAL E={fe / 10:.1f} B={fb / 10:.1f} S={fs / 10:.1f} "
|
||||||
f"product(scaled) = {fe * fb * fs / 1000} sum = {(fe + fb + fs) / 10:.1f}"
|
f"{obj_str} sum = {(fe + fb + fs) / 10:.1f}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue