
% 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([],T,[]) <-
   T >= 0.

presentation([Topic| OtherTopics],MaxTime,Segments) <-
   segment(Seg,Time,Tops) &
   member(Topic,Tops) &
   presentation(OtherTopics,MaxTime,Segments) &
   member(Seg,Segments).
presentation([Topic| OtherTopics],MaxTime,[Seg|Segments]) <-
   segment(Seg,Time,Tops) &
   Time =< MaxTime &
   member(Topic,Tops) &
   RemTime is MaxTime - Time &
   presentation(OtherTopics,RemTime,Segments) &
   notin(Seg,Segments).


member(A,[A|_]).
member(A,[_|L]) <-
   member(A,L).

notin(_,[]).
notin(A,[B|L]) <-
   A \= B &
   notin(A,L).


% load 'c:\david\teach\cs322\video2.pl'.
% ask presentation([welcome,skiing,robots], 90, Segs).
