skip to Main Content

I have the following set of facts:

lc('Dr. Smith', 'Algorithms').
lc('Dr. Jones', 'Models & Analysis').
lc('Dr. Smith', 'Operating Systems').
lc('Dr. Jones', 'Artificial Intelligence').
lc('Dr. Smith', 'Models of Computation').
lc('Dr. Smith', 'Discrete Math').
lc('Dr. Jones', 'Information Retrieval').
lc('Dr. Jones', 'Computer Vision').

ctl('Algorithms', 'MWF, 9:00 - 11:00 a.m.', 'McB 209').
ctl('Models & Analysis', 'MWF, 9:00 - 11:00 a.m.', 'McB 211').
ctl('Operating Systems', 'TTH, 9:00 - 11:00 a.m.', 'McB 306').
ctl('Artificial Intelligence', 'TTH, 3:00 - 5:00 p.m.', 'McB 311').
ctl('Models of Computation', 'TTH, 11:00 - 1:00 p.m.', 'McB 204').
ctl('Discrete Math', 'TTH, 3:00 - 5:00 p.m.', 'McB 204').
ctl('Information Retrieval', 'MWF, 3:00 - 5:00 p.m.', 'McB 205').
ctl('Computer Vision', 'MWF, 1:00 - 3:00 p.m.', 'NEB 2182').

And I’ve been able to write the following, that gives me the schedule for a lecturer:

schedule(Lecturer, X, Y, Z) :- ctl(X, Y, Z), lc(Lecturer, X).

But now I’m trying to write a rule to find when do Dr. Jones and Dr. Smith teach at the same time. Any ideas?

2

Answers


  1. _something like that:

    samehours(Prof1,Prof2,H) :-
       Prof1 = Prof2,
       lc(Prof1, Sub1), lc(Prof2,Sub2),
       ctl(Sub1,H,_), ctl(Sub2, H, _).
    

    result:

    H = 'MWF, 9:00 - 11:00 a.m.' ;
    H = 'TTH, 3:00 - 5:00 p.m.' ;
    
    Login or Signup to reply.
  2. You can use your own function to extend this utility, by doing:

    same_time(X, Y, R) :-
        schedule(X, _, B, _),
        schedule(Y, _, B, _),
        X = Y,
        R = B.
    

    which is simply telling you what teachers X and Y teaches both at the same time B, as returned in the list R.

    And, if you only want the times when more than one teacher co-occur in the teaching schedule, you can simply remove the initial vars X and Y, and even replace R with the final result itself, just as follows:

    same_time(B) :-
        schedule(X, _, B, _),
        schedule(Y, _, B, _),
        X = Y.
    

    The return will still be the times B when more than one teacher is giving classes.

    For the conflicts, you may keep the part of your statement that is working, and simply extend it to:

    same_teachertime(X) :-
        schedule(X, V1, B, _),
        schedule(X, V2, B, _),
        V1 = V2.
    
    schedulingconflict(X, Y, X):- ctl(X, A, B), ctl(Y, A, B), X = Y.
    schedulingconflict(_, _, X):- same_teachertime(X).
    

    This considers that being the same teacher, in the same time, teaching different subjects, is a conflict, since the room conflicts are being solved with the statement you wrote.

    Regards!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search