Skip to content

Commit

Permalink
Fix #150, wrong infinite max_time
Browse files Browse the repository at this point in the history
  • Loading branch information
tpaviot committed Oct 19, 2024
1 parent 5805cb4 commit a797e79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions processscheduler/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, **data) -> None:
z3.set_option("smt.arith.random_initial_value", False)

# set timeout
if self.max_time != "inf":
if self.max_time != float("inf"):
z3.set_option("timeout", int(self.max_time * 1000)) # in milliseconds

# some flags that will be used after
Expand Down Expand Up @@ -784,7 +784,7 @@ def _solve_optimize_incremental(
print(
f"\tFound value: {current_variable_value} elapsed time:{total_time:.3f}s"
)
if self.max_time != "inf" and total_time > self.max_time:
if self.max_time != float("inf") and total_time > self.max_time:
print("Max time exceeded. Stop incremental solver.")
break

Expand All @@ -807,7 +807,7 @@ def _solve_optimize_incremental(
# Compute the expected value
a, b, c = calc_parabola_from_three_points([0, 1, 2], three_last_times)
expected_next_time = a * 9 + 3 * b + c
if self.max_time != "inf" and expected_next_time > self.max_time:
if self.max_time != float("inf") and expected_next_time > self.max_time:
print(
"Max time expected on the next iteration. Stop incremental solver."
)
Expand Down
10 changes: 10 additions & 0 deletions test/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ def test_solve_max_time():
assert not solution


def test_solve_inf_max_time():
"""just to test that setting max_time to 'inf' works"""
problem = build_complex_problem("SolveInfMaxTime", 10)
ps.ObjectiveMinimizeMakespan()
# 1s is not enough to solve this problem
max_time_solver = ps.SchedulingSolver(problem=problem, max_time=float("inf"))
solution = max_time_solver.solve()
assert solution


def test_solve_non_integer_max_time():
"""a stress test which"""
problem = build_complex_problem(name="SolveMaxTime", n=1000)
Expand Down

0 comments on commit a797e79

Please sign in to comment.