tpaviot / ProcessScheduler

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

Error optional tasks #13

Closed dreinon closed 3 years ago

dreinon commented 3 years ago
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-27ce5384b228> in <module>
     13         for j in availability:
     14             av_list.append(ps.and_([ps.TaskStartAfterLax(students_tasks[-1], j[0],optional=True), ps.TaskEndBeforeLax(students_tasks[-1], j[1],optional=True)]))
---> 15         constraints.append(ps.ForceApplyNOptionalConstraints(av_list,1))
     16     for i in range(num_practices_simple):
     17         practice_num += 1

~/ProcessScheduler/processscheduler/base.py in __init__(self, list_of_optional_constraints, nb_constraints_to_apply, kind, optional)
    122         # actually optional
    123         for constraint in list_of_optional_constraints:
--> 124             if not constraint.optional:
    125                 raise TypeError('The constraint %s must explicitly be set as optional.' % constraint.name)
    126 

AttributeError: 'BoolRef' object has no attribute 'optional'

Thanks again!

dreinon commented 3 years ago

Closed by error

tpaviot commented 3 years ago

ok, reading your code I see what you want to achieve. Can you try this:


all_ctr = []
for j in availability:
    ctr1 = ps.TaskStartAfterLax(students_tasks[-1], j[0],optional=True)
    ctr2 = ps.TaskEndBeforeLax(students_tasks[-1], j[1],optional=True)
    all_ctr.append(ctr1)
    all_ctr.append(ctr2)
    av_list.append(ps.and_([ctr1, ctr2]))
    # force both ctr1 and ctr2 to be applied or not applied simultaneously
    constraints.append(ctr1.applied == ctr2.applied)  # the double equal is important
constraints.append(ps.ForceApplyNOptionalConstraints(all_ctr, 2)) # force 2 optional constraints to True
dreinon commented 3 years ago

Thanks for answering. I don't get the av_list part, I mean, where do I add the av_list to the general constraints.

tpaviot commented 3 years ago

You can do without the av_list parameter:

all_ctr = []
for j in availability:
    ctr1 = ps.TaskStartAfterLax(students_tasks[-1], j[0],optional=True)
    ctr2 = ps.TaskEndBeforeLax(students_tasks[-1], j[1],optional=True)
    all_ctr.append(ctr1)
    all_ctr.append(ctr2)
    constraints.append(ps.and_([ctr1, ctr2]))
    # force both ctr1 and ctr2 to be applied or not applied simultaneously
    constraints.append(ctr1.applied == ctr2.applied)  # the double equal is important
constraints.append(ps.ForceApplyNOptionalConstraints(all_ctr, 2)) # force 2 optional constraints to True
dreinon commented 3 years ago

My code works fine using this constraints! Now, what doesn't let my script end is usage optimization. When I add that, it takes forever and doesn't end. Nevertheless, I have used ForceScheduleNOptionalTasks a couple times and estimated the number of optional tasks to be scheduled that maximize ocupation, but this depends on the number of tasks created, and I need a general way to maximize ocupation which should be achieved with optimization.

Any thoughts of what might be causing this? Do you think this is actually due to the high computational cost?

Thank you!

tpaviot commented 3 years ago

It might come from the computational cost, yes, hard to say without a deeper look. Did you try an incremental approach? it is quite effective to estimate the computational complexity: start with 3 students and 3 buses, then 4 and 5, you may foresee the complexity for a higher number of inputs

dreinon commented 3 years ago

What do you mean with buses Thomas?

tpaviot commented 3 years ago

I mean scholar bus, it is what I understood from your problem, both scholar bus and students are to be handled

dreinon commented 3 years ago

Oh okay! Haha actually, I'm dealing with cars and students, in a driving school (where you get your driver's license) such that cars are working as much as possible and students get their practices scheduled in the time periods they specified they were available. Moreover, now I'm dealing with a unique resource, only one car, so I guess what I should do is to reduce the number of practices, try to increase this every time and see how the time scales, and hence, the computational complexity.

What I also think is that this depends a lot on the availability of the students whose practices are used in the problem. I understand that, for the same number of practices (tasks), the time would depend a lot on the constraints of those practices (availability of student), right?

dreinon commented 3 years ago

Opening a new issue to continue with this new topic.