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
_something like that:
result:
You can use your own function to extend this utility, by doing:
which is simply telling you what teachers
X
andY
teaches both at the same timeB
, as returned in the listR
.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
andY
, and even replaceR
with the final result itself, just as follows: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:
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!