
% segment(SegId, Duration, Covers) specifies a video clip, where
% SegId is an identifier for the segment. 
% Duration is the time of the segment (in seconds). 
% Covers is a list of topics that is covered by the video segment. 

segment(seg0,10,[welcome]).
segment(seg1,30,[skiing,views]).
segment(seg2,50,[welcome,computational_intelligence,robots]).
segment(seg3,40,[graphics,dragons]).
segment(seg4,50,[skiing,robots]).

% presentation(MustCover, Maxtime, Segments) is true if Segments is a
%    presentation whose total running time is less than or equal to
%    Maxtime seconds, such that all of the topics in the list MustCover
%    are covered by a segment in the presentation. The aim of this
%    predicate is to design presentations that cover a certain number
%    of topics within a time limit.

presentation(MustCover, Maxtime, Segments) <-
   presentation_takes_under(Segments,Maxtime) &
   presentation_covers_all(MustCover,Segments).

% presentation_takes_under(Segments,MaxTime) is true if Segments is a
%    presentation whose total running time is less than or equal to
%    Maxtime seconds
presentation_takes_under([],T) <-
   T >= 0.

presentation_takes_under([Seg|RemSegments],MaxTime) <-
   segment(Seg,Time,_) &
   Time =< MaxTime &
   RemTime is MaxTime - Time &
   presentation_takes_under(RemSegments,RemTime) &
   notin(Seg,RemSegments).

% presentation_covers_all(MustCover,Segments) is true if Segments is a
%    presentation such that all of the topics in the list MustCover
%    are covered by a segment in the presentation.
presentation_covers_all([],Segments).
presentation_covers_all([Topic | MustCover],Segments) <-
   presentation_covers(Segments,Topic) &
   presentation_covers_all(MustCover,Segments).

% presentation_covers(Segments,Topic) is true if Segments is a
%    presentation that covers Topic
presentation_covers(Segments,Topic) <-
   member(Seg,Segments) &
   segment(Seg,_,Topics_Covered) &
   member(Topic,Topics_Covered).

member(A,[A|_]).
member(A,[_|L]) <-
   member(A,L).

notin(_,[]).
notin(A,[B|L]) <-
   A \= B &
   notin(A,L).

% load 'c:\david\teach\cs322\video4.pl'.
% ask presentation([welcome,skiing,robots], 90, Segs).
