tpaviot / ProcessScheduler

A Python package for automatic and optimized resource scheduling
https://processscheduler.github.io/
GNU General Public License v3.0
58 stars 17 forks source link

Assertion And already added exception #106

Closed dreinon closed 2 years ago

dreinon commented 2 years ago

I'm getting the following error when executing the scheduler, when it gets to ps.ResourceTasksDistance(worker, 0, periods):

  File "/home/dani/miniconda3/envs/dribo-data-api/lib/python3.9/site-packages/processscheduler/resource_constraint.py", line 216, in __init__
    self.set_z3_assertions(c)
  File "/home/dani/miniconda3/envs/dribo-data-api/lib/python3.9/site-packages/processscheduler/constraint.py", line 62, in set_z3_assertions
    self.append_z3_assertion(list_of_z3_assertions)
  File "/home/dani/miniconda3/envs/dribo-data-api/lib/python3.9/site-packages/processscheduler/base.py", line 84, in append_z3_assertion
    raise AssertionError(
AssertionError: assertion And already added. Please report this bug at https://github.com/tpaviot/ProcessScheduler/issues

Periods variable is: [(3, 8), (17, 20), (8, 20), (28, 35), (8, 16), (28, 38), (2, 3), (0, 2), (35, 38), (24, 28), (21, 24), (20, 28), (0, 8), (16, 17), (20, 21)]

Assertion hashes since this constraint is declared are:

assertion_hash=1309420569
assertion_hash=4229562367
assertion_hash=4081975290  # Repeated
assertion_hash=815794509
assertion_hash=4081975290  # Repeated

Any ideas?

Thanks!

tpaviot commented 2 years ago

Does that occur each time you launch the script?

dreinon commented 2 years ago

Yes, but only with this worker

dreinon commented 2 years ago

It's weird because all workers have the same periods, and it only happens with this exact one worker

tpaviot commented 2 years ago

Does it have something specific compared to the other workers?

dreinon commented 2 years ago

The number of tasks assigned to it and its unavailability. These elements are different for each worker.

dreinon commented 2 years ago

Found out the reason! Since this worker only had one task assigned, it didn't make sense to create a ResourceTasksDistance constraint. Maybe we can add a corner case to the constraint to avoid this case, only letting users use it with workers who have more than one tasks assigned.

tpaviot commented 2 years ago

ok, could you contribute at most 10 lines of code so that I can reproduce the bug and add this case to the unittest suite?

dreinon commented 2 years ago
import processscheduler as ps

# Error
pb = ps.SchedulingProblem('problem', 5)
worker = ps.Worker('worker')
task = ps.FixedDurationTask('task', 1)
task.add_required_resource(worker)

ps.ResourceTasksDistance(worker, 0, [(0,5)])

solver = ps.SchedulingSolver(pb)
solver.solve()
import processscheduler as ps

# Fixed adding another task
pb = ps.SchedulingProblem('problem', 5)
worker = ps.Worker('worker')
task1 = ps.FixedDurationTask('task1', 1)
task2 = ps.FixedDurationTask('task2', 1)
task1.add_required_resource(worker)
task2.add_required_resource(worker)

ps.ResourceTasksDistance(worker, 0, [(0,5)])

solver = ps.SchedulingSolver(pb)
solver.solve()