
% 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) <-
   add_to_presentation(MustCover,MaxTime,[],Segments).

% add_to_presentation(MustCover,MaxTime,CurrentSegments,FinalSegments)
%  is true if FinalSegments contains CurrentSegments and doesn't take
%  more than MaxTime extra time, and also covers topics in MustCover.

add_to_presentation([],T,Segs,Segs) <-
   T >= 0.

add_to_presentation([Topic|OtherTopics],MaxTime,CurrentSegments,Segments) <-
   segment(Seg,Time,Tops) &
   member(Topic,Tops) &
   member(Seg,CurrentSegments) &
   add_to_presentation(OtherTopics,MaxTime,CurrentSegments,Segments).
add_to_presentation([Topic| OtherTopics],MaxTime,CurrentSegments,Segments) <-
   segment(Seg,Time,Tops) &
   member(Topic,Tops) &
   notin(Seg,CurrentSegments) &
   RemTime is MaxTime - Time &
   add_to_presentation(OtherTopics,RemTime,[Seg|CurrentSegments],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\video3.pl'.
% ask presentation([welcome,skiing,robots], 90, Segs).
