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 with if_then_else - imply constraints #15

Closed dreinon closed 3 years ago

dreinon commented 3 years ago

Hello! I'm trying to make that if a student task is scheduled in a certain day (a day has 13 time points), then if another of his tasks is scheduled, it should be scheduled in another day. I'm using the following code:

for t1,t2 in permutations(student_tasks,2):
        constraints.append(ps.if_then_else(t1.start/13 < 1,ps.TaskStartAfterLax(t2,13),
            ps.if_then_else(t1.start/13 < 2,ps.TaskStartAfterLax(t2,13*2),
                ps.if_then_else(t1.start/13 < 3,ps.TaskStartAfterLax(t2,13*3),
                    ps.implies(t1.start/13 < 4,ps.TaskStartAfterLax(t2,13*4))
                )
            )
        ))

I'm getting the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-11-9ed050da25ac> in <module>
     46             ps.if_then_else(t1.start/13 < 2,ps.TaskStartAfterLax(t2,13*2),
     47                 ps.if_then_else(t1.start/13 < 3,ps.TaskStartAfterLax(t2,13*3),
---> 48                     ps.implies(t1.start/13 < 4,ps.TaskStartAfterLax(t2,13*4))
     49                 )
     50             )

~/ProcessScheduler/processscheduler/first_order_logic.py in implies(condition, consequence_list_of_constraints)
     94     """
     95     return Implies(And(_get_assertions(condition)),
---> 96                    And(_constraints_to_list_of_assertions(consequence_list_of_constraints)))
     97 
     98 #

~/ProcessScheduler/processscheduler/first_order_logic.py in _constraints_to_list_of_assertions(list_of_constraints)
     38     """Convert a list of constraints or assertions to a list of assertions."""
     39     list_of_boolrefs_to_return = []
---> 40     for constraint in list_of_constraints:
     41         assertions = _get_assertions(constraint)
     42         if isinstance(assertions, list):

TypeError: 'TaskStartAfterLax' object is not iterable

Any ideas?? Thanks again!

tpaviot commented 3 years ago

You must pass a list of constraints, even if there's only one constraint

ps.implies(t1.start/13 < 4,[ps.TaskStartAfterLax(t2,13*4)])
tpaviot commented 3 years ago

I'm not sure that you can nest if_then_else and implies, let me know

dreinon commented 3 years ago

I don't get an error using this notation: for t1,t2 in permutations(student_tasks,2): constraints.append(ps.if_then_else(t1.start/13 < 1,[ps.TaskStartAfterLax(t2,13)], [ps.if_then_else(t1.start/13 < 2,[ps.TaskStartAfterLax(t2,13*2)], [ps.if_then_else(t1.start/13 < 3,[ps.TaskStartAfterLax(t2,13*3)], [ps.implies(t1.start/13 < 4,[ps.TaskStartAfterLax(t2,13*4)]) ]) ]) ]))

However, I get directly no solution. I'll make some unit tests later.

dreinon commented 3 years ago

Any other idea about how to constraint a maximum of n tasks (no minimum) from a list of tasks to be scheduled between a certain interval of time.

For instance, such that a person can do a maximum of 3 tasks between the periods 5-15, and a maximum of 4 between the periods 15-30.

Thanks!

tpaviot commented 3 years ago

yes, that's planned. What do you exactly mean with "do a max of 3 tasks"? From the periods 5-15, 3 tasks max are started, processed, and completed, right?

dreinon commented 3 years ago

Exactly. 3 tasks maximum FROM A LIST OF TASKS. This doesn't mean that there couldn't be more tasks that aren't in that list between this periods,

tpaviot commented 3 years ago

ok, can you please open a dedicated issue?

dreinon commented 3 years ago

Sure. I commented it here since that's what I was trying to do concatenating if-else statements

dreinon commented 3 years ago

Addressed at #20