Skip to content

Commit

Permalink
Fix test_cost, blackify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tpaviot committed Sep 10, 2022
1 parent d66fcef commit fb279da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
27 changes: 7 additions & 20 deletions test/test_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_cost_polynomial_1(self) -> None:
ps.SchedulingProblem("PolynomialCost1", horizon=12)

def c(t):
return 0.5 * t ** 2 + 50
return 0.5 * t * t + 50

ress_cost = ps.PolynomialCostFunction(c)
ps.Worker("Worker1", cost=ress_cost)
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_quadratic_cost_1(self) -> None:
t_1 = ps.FixedDurationTask("t1", duration=17)

def int_cost_function(t):
return 23 * t ** 2 - 13 * t + 513
return 23 * t * t - 13 * t + 513

worker_1 = ps.Worker(
"Worker1", cost=ps.PolynomialCostFunction(int_cost_function)
Expand Down Expand Up @@ -226,9 +226,9 @@ def test_optimize_quadratic_cost_2(self) -> None:
t_1 = ps.FixedDurationTask("t1", duration=4)

# we chosse a function where we know the minimum is
# let's imagine the minimum is at t=37
# let's imagine the minimum is at t=8
def int_cost_function(t):
return (t - 8) ** 2 + 100
return (t - 8) * (t - 8) + 100

worker_1 = ps.Worker(
"Worker1", cost=ps.PolynomialCostFunction(int_cost_function)
Expand All @@ -241,25 +241,12 @@ def int_cost_function(t):
solution = ps.SchedulingSolver(problem).solve()

self.assertTrue(solution)
# TODO: to be fixed; Non linear solver gives weirf results.
# This was repored to z3 team see
# https://github.com/Z3Prover/z3/issues/5254
# Fix to be released in the next z3 version 4.8.11.0
# sometimes it's 6, sometime it's 7 TODO weird
# self.assertTrue(solution.tasks[t_1.name].start in [6, 7])

# sometimes it's 416, sometimes 420 TODO
# self.assertTrue(solution.indicators[cost_ind.name] in [416, 420])
self.assertEqual(solution.tasks[t_1.name].start, 6)
self.assertEqual(solution.indicators[cost_ind.name], 416)

def test_plot_cost_function(self) -> None:
# TODO: add an horizon, it should return the expected result
# but there's an issue, see
# https://github.com/Z3Prover/z3/issues/5254

# we chosse a function where we know the minimum is
# let's imagine the minimum is at t=37
def int_cost_function(t):
return (t - 37) ** 2 + 513
return (t - 8) * (t - 8) + 513

cost = ps.PolynomialCostFunction(int_cost_function)

Expand Down
7 changes: 5 additions & 2 deletions test/test_group_of_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ def test_ordered_group_task_1(self) -> None:
task_2 = ps.FixedDurationTask("task2", duration=7)
task_3 = ps.FixedDurationTask("task3", duration=2)
task_4 = ps.FixedDurationTask("task4", duration=2)
group1 = ps.OrderedTaskGroup([task_1, task_2, task_3, task_4], kind="tight", time_interval = [23, 39])

group1 = ps.OrderedTaskGroup(
[task_1, task_2, task_3, task_4], kind="tight", time_interval=[23, 39]
)

solver = ps.SchedulingSolver(pb)
solution = solver.solve()
self.assertTrue(solution)
Expand All @@ -107,5 +109,6 @@ def test_ordered_group_task_1(self) -> None:
self.assertTrue(s_1 >= 23)
self.assertTrue(s_4 <= 39)


if __name__ == "__main__":
unittest.main()

0 comments on commit fb279da

Please sign in to comment.