Skip to content

Commit

Permalink
Fix IndicatorResourceIdle for resource that have less than one task a…
Browse files Browse the repository at this point in the history
…ssigned
  • Loading branch information
tpaviot committed Sep 4, 2024
1 parent 458f9da commit e694c8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions processscheduler/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ def __init__(self, **data) -> None:
for start_var, end_var in resource._busy_intervals.values():
starts.append(start_var)
ends.append(end_var)
if (
len(starts) <= 1 and len(ends) <= 1
): # only one task is assigned to this resource
continue
# sort both lists
sorted_starts, c1 = sort_no_duplicates(starts)
sorted_ends, c2 = sort_no_duplicates(ends)
Expand Down
14 changes: 14 additions & 0 deletions test/test_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,20 @@ def test_indicator_resource_idle_3() -> None:
assert solution.indicators[ind.name] == 6


def test_indicator_resource_idle_4() -> None:
"""Only 1 task, no idle time by definition"""
problem = ps.SchedulingProblem(name="IndicatorResourceIdle4")
task_1 = ps.FixedDurationTask(name="task1", duration=2)
ps.TaskStartAt(task=task_1, value=3)
worker_1 = ps.Worker(name="Machine1")
task_1.add_required_resource(worker_1)
ind = ps.IndicatorResourceIdle(list_of_resources=[worker_1])
solver = ps.SchedulingSolver(problem=problem)
solution = solver.solve()
assert solution
assert solution.indicators[ind.name] == 0


def test_optimize_indicator_multi_objective() -> None:
problem = ps.SchedulingProblem(name="OptimizeIndicatorMultiObjective", horizon=10)
task_1 = ps.FixedDurationTask(name="task1", duration=2, priority=1)
Expand Down

0 comments on commit e694c8e

Please sign in to comment.