Skip to content
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

Coupling constraints are erroneously satisfied if coupling crosses a day boundary. #4

Closed
doublec opened this issue Jul 11, 2024 · 2 comments · Fixed by #5
Closed

Coupling constraints are erroneously satisfied if coupling crosses a day boundary. #4

doublec opened this issue Jul 11, 2024 · 2 comments · Fixed by #5

Comments

@doublec
Copy link
Contributor

doublec commented Jul 11, 2024

This is pulled out from issue #3 - a comment there notes that if a coupling constraint crosses a day boundary then it is still satisfied. I've pasted an example test_issue.pl at the end of this comment that contains requirements that demonstrates the issue. Tested on scryer-prolog installed from a cargo install scryer-prolog today.

Running the following:

$ scryer-prolog simsttab.pl test_issue.pl 
?- requirements_variables(Rs, Vs),
   labeling([ff], Vs),
   print_classes(Rs).

Gives the following for class 'j2':

Class: j2

  Mon     Tue     Wed     Thu     Fri   
========================================
  hcc     taa     pdd     taa     cbb   
  taa     cbb     taa     taa     cbb   
  cbb     dee     ahh     cbb     hcc   
  pdd     hcc     hff     hcc     hff   
  hff     hcc     ggg     ggg     dee   
  dee     pdd     pdd     ahh     pdd   

Notice the pdd coupling for '1' and '2' slots crosses tuesday and wednesday. These should be on the same day.

I played around with a fix. I changed slots_couplings from:

slots_couplings(Slots, F-S) :-
         nth0(F, Slots, S1),
         nth0(S, Slots, S2),
        S2 #= S1 + 1.

To:

slots_couplings(Slots, F-S) :-
        nth0(F, Slots, S1),
        nth0(S, Slots, S2),
        S2 #= S1 + 1,
        slot_quotient(S1, Q1),
        slot_quotient(S2, Q2),
        Q1 #= Q2.

This was my attempt at saying that both S1 and S2 must be in the same day by having the same slot_quotient. With this change the j2 class looks correct:

Class: j2

  Mon     Tue     Wed     Thu     Fri   
========================================
  hcc     taa     pdd     pdd     pdd   
  taa     cbb     pdd     taa     hff   
  cbb     ahh     taa     taa     ggg   
  pdd     hcc     hcc     hff     hcc   
  hff     hcc     cbb     cbb     ahh   
  dee     dee     ggg     cbb     dee 

Does the fix look correct?

% test_issue.pl
:- discontiguous(class_subject_teacher_times/4).
:- discontiguous(class_freeslot/2).
:- discontiguous(coupling/4).

slots_per_week(30).
slots_per_day(6).

class_subject_teacher_times('j1', taa, t1, 5).
class_subject_teacher_times('j1', cbb, t2, 5).
class_subject_teacher_times('j1', hcc, t3, 5).
class_subject_teacher_times('j1', pdd, t4, 5).
class_subject_teacher_times('j1', dee, t5, 3).
class_subject_teacher_times('j1', hff, t6, 3).
class_subject_teacher_times('j1', ggg, t7, 2).
class_subject_teacher_times('j1', ahh, t8, 2).
coupling('j1', taa, 3, 4).
coupling('j1', cbb, 3, 4).
coupling('j1', hcc, 1, 2).
coupling('j1', pdd, 1, 2).

class_subject_teacher_times('j2', taa, t1, 5).
class_subject_teacher_times('j2', cbb, t2, 5).
class_subject_teacher_times('j2', hcc, t3, 5).
class_subject_teacher_times('j2', pdd, t4, 5).
class_subject_teacher_times('j2', dee, t5, 3).
class_subject_teacher_times('j2', hff, t6, 3).
class_subject_teacher_times('j2', ggg, t7, 2).
class_subject_teacher_times('j2', ahh, t8, 2).
coupling('j2', taa, 3, 4).
coupling('j2', cbb, 3, 4).
coupling('j2', hcc, 1, 2).
coupling('j2', pdd, 1, 2).
@triska
Copy link
Owner

triska commented Jul 11, 2024

Awesome! That's a very elegant way to solve this issue, thank you a lot!

I think it can be stated equivalently and slightly shorter as:

        slot_quotient(S1, Q),
        slot_quotient(S2, Q),

Would you like to file a pull request for this change?

@doublec
Copy link
Contributor Author

doublec commented Jul 11, 2024

Thanks, I'll submit a pull request shortly, implementing your shorter change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants