feat: compute resource ceilings only for objective resources
Modify solve() to only compute ceilings (_ceiling solver calls) for resources that appear in the objective function (where obj_factors[k] != 0). This avoids unnecessary 20s ceiling solves for resources not contributing to the maximize criterion. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ead700adf4
commit
43636d330e
1 changed files with 12 additions and 7 deletions
19
solve.py
19
solve.py
|
|
@ -1582,12 +1582,16 @@ def solve(
|
||||||
else max_res
|
else max_res
|
||||||
)
|
)
|
||||||
|
|
||||||
capE = _ceiling(finalE)
|
finals = {"E": finalE, "B": finalB, "S": finalS, "C": C[NUM_STEPS + 1]}
|
||||||
capB = _ceiling(finalB)
|
|
||||||
capS = _ceiling(finalS)
|
# Ceilings only for resources that appear in the objective: each
|
||||||
m.Add(finalE <= capE)
|
# ceiling solve costs up to 20s, and only objective resources need
|
||||||
m.Add(finalB <= capB)
|
# bounds (product mode) / benefit from the redundant cap constraint.
|
||||||
m.Add(finalS <= capS)
|
caps = {}
|
||||||
|
for k, var in finals.items():
|
||||||
|
if obj_factors[k] != 0:
|
||||||
|
caps[k] = _ceiling(var)
|
||||||
|
m.Add(var <= caps[k])
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
# OBJECTIVE IS SET HERE
|
# OBJECTIVE IS SET HERE
|
||||||
|
|
@ -1629,7 +1633,8 @@ def solve(
|
||||||
status = solver.Solve(m)
|
status = solver.Solve(m)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"(resource ceilings used: E<={capE} B<={capB} S<={capS})")
|
caps_str = " ".join(f"{k}<={v}" for k, v in caps.items())
|
||||||
|
print(f"(resource ceilings used: {caps_str})")
|
||||||
_report(
|
_report(
|
||||||
solver,
|
solver,
|
||||||
status,
|
status,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue