Skip to content

Commit 2ab8f57

Browse files
committed
doc
1 parent 8f55468 commit 2ab8f57

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

prtpy/partitioning/integer_programming_avg.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
def optimal(
1818
binner: Binner, numbins: int, items: List[any], entitlements: List[any] = None,
1919
copies=1,
20-
time_limit=inf,
20+
time_limit=inf, # time limit in seconds
2121
verbose=0,
22-
solver_name=mip.CBC, # passed to MIP. See https://docs.python-mip.com/en/latest/quickstart.html#creating-models.
23-
# solver_name = mip.GRB, # passed to MIP. See https://docs.python-mip.com/en/latest/quickstart.html#creating-models.
22+
solver_name=mip.CBC, # [or mip.GRB] passed to MIP. See https://docs.python-mip.com/en/latest/quickstart.html#creating-models.
2423
model_filename = None,
2524
solution_filename = None,
2625
):
@@ -83,7 +82,7 @@ def optimal(
8382
iitems = range(len(items))
8483
if isinstance(copies, Number):
8584
copies = {iitem: copies for iitem in iitems}
86-
model = mip.Model(name = '', solver_name=solver_name)
85+
model = mip.Model(name='', sense='MIN', solver_name=solver_name)
8786
counts: dict = {
8887
iitem: [model.add_var(var_type=mip.INTEGER) for ibin in ibins]
8988
for iitem in iitems
@@ -132,8 +131,15 @@ def optimal(
132131
model.write(model_filename)
133132
# logger.info("MIP model: %s", model)
134133
status = model.optimize(max_seconds=time_limit)
135-
if status != mip.OptimizationStatus.OPTIMAL:
136-
raise ValueError(f"Problem status is not optimal - it is {status}.")
134+
135+
# Check problem status:
136+
if time_limit == inf:
137+
if status != mip.OptimizationStatus.OPTIMAL:
138+
raise ValueError(f"Problem status is not optimal - it is {status}.")
139+
else:
140+
if status not in {mip.OptimizationStatus.OPTIMAL,mip.OptimizationStatus.FEASIBLE}:
141+
raise ValueError(f"Problem status is neither optimal nor feasible - it is {status}.")
142+
137143

138144
# Construct the output:
139145
output = binner.new_bins(numbins)

0 commit comments

Comments
 (0)