2010年8月17日火曜日

Prologの技芸 2.2節の練習問題

サンプルデータベース
day(complexity,monday).
start_time(complexity,9).
finish_time(complexity,11).
lecturer(complexity,harel).
building(complexity,feinberg).
room(complexity,a).

(1)
location(Course,Building) :-
building(Course,Building).
busy(Lecturer,Time) :-
lecturer(Course,Lecturer),
start_time(Course,Start), finish_time(Course,Finish),
Start =< Time, Time =< Finish.
cannot_meet(Lecturer1,Lecturer2) :-
lecturer(Course1,Lecturer1), lecturer(Course2,Lecturer2),
Course1 \= Course2.

(2)
schedule_conflict(Time,Place,Course1,Course2) :-
building(Course1,Building), building(Course2,Building),
room(Course1,Room), room(Course2,Room),
start_time(Course1,Start1), finish_time(Course1,Finish1),
start_time(Course2,Start2), finish_time(Course2,Finish2).
Start1 =< Finish2, Start2 =< Finish1,
Start1 =< Time, Time =< Finish1,
Start2 =< Time, Time =< Finish2.

0 件のコメント: