-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resource tasks distance #87
Conversation
Codecov Report
@@ Coverage Diff @@
## master #87 +/- ##
==========================================
+ Coverage 94.96% 95.19% +0.22%
==========================================
Files 30 31 +1
Lines 3419 3643 +224
==========================================
+ Hits 3247 3468 +221
- Misses 172 175 +3
Continue to review full report at Codecov.
|
Hey Thomas, were you able to fix this issue? |
def test_resource_tasks_distance_5(self) -> None:
"""Adding one scheduled optional tasks"""
pb = ps.SchedulingProblem("ResourceTasksDistance5OptionalTasks", horizon=30)
task_1 = ps.FixedDurationTask("task1", duration=8)
task_2 = ps.FixedDurationTask("task2", duration=4)
task_3 = ps.FixedDurationTask("task3", duration=3, optional=True)
worker_1 = ps.Worker("Worker1")
task_1.add_required_resource(worker_1)
task_2.add_required_resource(worker_1)
task_3.add_required_resource(worker_1)
c1 = ps.ResourceTasksDistance(worker_1, distance=4, mode="exact")
pb.add_constraint(c1)
pb.add_constraint(ps.TaskStartAt(task_1, 1))
solver = ps.SchedulingSolver(pb)
# for optional tasks to not be scheduled
solver.add_constraint(task_3.scheduled == True)
solution = solver.solve()
self.assertTrue(solution)
t1_start = solution.tasks[task_1.name].start
t2_start = solution.tasks[task_2.name].start
t3_start = solution.tasks[task_3.name].start
t1_end = solution.tasks[task_1.name].end
t2_end = solution.tasks[task_2.name].end
t3_end = solution.tasks[task_3.name].end
self.assertEqual(t1_start, 1)
self.assertEqual(t1_end, 9)
self.assertTrue(t2_start == 13 or t3_start == 13)
if t2_start == 13:
self.assertEqual(t2_end, 17)
self.assertEqual(t3_start, 21, f'{t3_start=} {t3_end=}')
self.assertEqual(t3_end, 24)
elif t3_start == 13:
self.assertEqual(t3_end, 16)
self.assertEqual(t2_start, 20)
self.assertEqual(t2_end, 24) Testing with scheduled optional task and working as expected!! |
The next step for this constraint was to make it admit periods, so the distance is applied inside certain periods and not outside of them. Thanks! |
@dreinon Yes, it works with optional tasks as well. That should not be very hard to add a time restriction to this constraint, although I don't really understand the use case. The documentation should explicit this clearly, how to use the constraint and what kind of problem this constraint represents. |
Right, I can doc it myself. My use case is that in my problem, I have several periods that are not consecutive one from each other, for example, from 9h to 13:30h, then from 14h to 16:15h and then from 17:15h to 21h, all with 45 min task duration. This is modelled this way for 3 reasons:
Therefore, if the constraints didn't have periods, then distance wouldn't be real. Imagine now the end of a day and the start of another day of the week. They share the same integer timepoint even though they are really apart in real time. I hope I could explain my use case well and that you get what I was trying to explain :) |
ok, I will add a |
Thanks! |
19473d8
to
0aca000
Compare
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 1.67%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
I committed an update with time periods, that should work. You can have a look at the related unittest as well, see 0aca000 |
Sourcery is good, but a bit too much intrusive |
Right, I like that but I understand it's not for everybody 😄 Thanks! |
Related to #83
Please @dreinon can you test