optapy / optapy-quickstarts

OptaPy quick starts for AI optimization: showcases many different use cases.
Apache License 2.0
19 stars 13 forks source link

The calculation of constraint at least 10 hours between two shifts #25

Open AybukeAk opened 1 year ago

AybukeAk commented 1 year ago

Hello!

Could there be an error when calculating the constraint that we specified should not be less than 10 hours between two shifts? Although 10 hours are calculated in seconds, why do we divide by 60 again after the total_seconds() method in line 68, where we get the difference between the 2nd shift and the 1st shift? Could you please explain that part to me?

Thanks in advance!

https://github.com/optapy/optapy-quickstarts/blob/4bdf9cce4a5e1ed4ffb3691b940abb0168251d63/employee-scheduling/constraints.py#L68

Christopher-Chianelli commented 1 year ago

That line is in the penalty, and thus controls how much each violation penalizes by. In this case, we penalize by how many minutes are between the current break end and the 10 hour minimum. The reason we do it in minutes is to match the penalty of the corresponding OptaPlanner quickstart, which uses minutes: https://github.com/kiegroup/optaplanner-quickstarts/blob/b1f4adbde452f93c7d23a8822527c7b7fad66717/use-cases/employee-scheduling/src/main/java/org/acme/employeescheduling/solver/EmployeeSchedulingConstraintProvider.java#L68-L69