MrFly
Programmer
- May 15, 2009
- 2
Hi, I have an exam on prolog next week and currently going over past papers. However I am struggling to get the program working. Below is the questions:
% The structure of a media production team takes the form
% team(Producer, Core_team, Production_assistant).
% Core_team is an arbitrarily long list of staff structures,
% but excludes the staff structures for Producer and
% and Production_assistant.
% staff structures represent employees and take the form
% staff(Surname,Initial,file(Speciality,Grade,CV)).
% CV is an arbitrarily long list of titles of media %productions.
team(staff(lyttleton,h,file(music,3,[my_music,best_tunes,showtime])),
[staff(garden,g,file(musical_comedy,2,[on_the_town,my_music])),
staff(crier,b,file(musical_comedy,2,[on_the_town,best_tunes]))],
staff(brooke-taylor,t,file(music,2,[my_music,best_tunes]))).
team(staff(wise,e,file(science,3,[horizon,frontiers,insight])),
[staff(morcambe,e,file(science,3,[horizon,leading_edge]))],
staff(o_connor,d,file(documentary,2,[horizon,insight]))).
team(staff(merton,p,file(variety,2,[showtime,dance,circus])),
[staff(smith,p,file(variety,1,[showtime,dance,circus,my_music])),
staff(hamilton,a,file(variety,1,[dance,best_tunes]))],
staff(steaffel,s,file(comedy,2,[comedians,my_music]))).
team(staff(chaplin,c,file(economics,3,[business_review,stock_show])),
[staff(keaton,b,file(documentary,3,[business_review,insight])),
staff(hardy,o,file(news,3,[news-report,stock_show,target,now])),
staff(laurel,s,file(economics,3,[news_report,stock_show,now]))],
staff(senate,m,file(news,3,[business_review]))).
Given this information, write rules (and any additional predicates required) that can be used to return the following:
(i)
the initial and surname of any employee whose grade is 1. [2 marks]
(ii)
the initial and surname of any producer whose team includes 2 employees whose CVs include a production entitled ‘Now’. [3 marks]
(iii)
the initial and surname of the production assistant in a team whose employees’ grades total 15 or more. [4 marks]
(iv)
the surnames of employee A and employee B, where employee A and employee B are in different teams, each have ‘Insight’ in their CV, and each have ‘documentary’ as their specialism. [4 marks]
I have got part (i) working through this:
q1(Name,Inital):-
exists(staff(Name,Inital,_(_,Grade,_))),Grade=1.
producer(X):- team(X,_,_).
production_assistant(X):- team(_,_,X).
core_team(X):-
team(_,Staff,_),
member(X,Staff).
exists(X):-
producer(X);
core_team(X);
production_assistant(X).
I have no clue for part II or III,
For part IV I am currently using :
q4(Name1,Name2):-
team(Producer1,Core_team1,Production_ass1),
team(Producer2,Core_team2,Production_ass2),
team(Producer1,Core_team1,Production_ass1)\=team(Producer2,Core_team2,Production_ass2),
(member(staff(Name1,_,_(documentary,_,_),[Producer1,Production_ass1|Core_team1]))),
(member(staff(Name2,_,_(documentary,_,_),[Producer2,Production_ass2|Core_team2]))).
but it is not working. Any help would be greatly appreciated for any of the parts.
Many thanks, Paul
% The structure of a media production team takes the form
% team(Producer, Core_team, Production_assistant).
% Core_team is an arbitrarily long list of staff structures,
% but excludes the staff structures for Producer and
% and Production_assistant.
% staff structures represent employees and take the form
% staff(Surname,Initial,file(Speciality,Grade,CV)).
% CV is an arbitrarily long list of titles of media %productions.
team(staff(lyttleton,h,file(music,3,[my_music,best_tunes,showtime])),
[staff(garden,g,file(musical_comedy,2,[on_the_town,my_music])),
staff(crier,b,file(musical_comedy,2,[on_the_town,best_tunes]))],
staff(brooke-taylor,t,file(music,2,[my_music,best_tunes]))).
team(staff(wise,e,file(science,3,[horizon,frontiers,insight])),
[staff(morcambe,e,file(science,3,[horizon,leading_edge]))],
staff(o_connor,d,file(documentary,2,[horizon,insight]))).
team(staff(merton,p,file(variety,2,[showtime,dance,circus])),
[staff(smith,p,file(variety,1,[showtime,dance,circus,my_music])),
staff(hamilton,a,file(variety,1,[dance,best_tunes]))],
staff(steaffel,s,file(comedy,2,[comedians,my_music]))).
team(staff(chaplin,c,file(economics,3,[business_review,stock_show])),
[staff(keaton,b,file(documentary,3,[business_review,insight])),
staff(hardy,o,file(news,3,[news-report,stock_show,target,now])),
staff(laurel,s,file(economics,3,[news_report,stock_show,now]))],
staff(senate,m,file(news,3,[business_review]))).
Given this information, write rules (and any additional predicates required) that can be used to return the following:
(i)
the initial and surname of any employee whose grade is 1. [2 marks]
(ii)
the initial and surname of any producer whose team includes 2 employees whose CVs include a production entitled ‘Now’. [3 marks]
(iii)
the initial and surname of the production assistant in a team whose employees’ grades total 15 or more. [4 marks]
(iv)
the surnames of employee A and employee B, where employee A and employee B are in different teams, each have ‘Insight’ in their CV, and each have ‘documentary’ as their specialism. [4 marks]
I have got part (i) working through this:
q1(Name,Inital):-
exists(staff(Name,Inital,_(_,Grade,_))),Grade=1.
producer(X):- team(X,_,_).
production_assistant(X):- team(_,_,X).
core_team(X):-
team(_,Staff,_),
member(X,Staff).
exists(X):-
producer(X);
core_team(X);
production_assistant(X).
I have no clue for part II or III,
For part IV I am currently using :
q4(Name1,Name2):-
team(Producer1,Core_team1,Production_ass1),
team(Producer2,Core_team2,Production_ass2),
team(Producer1,Core_team1,Production_ass1)\=team(Producer2,Core_team2,Production_ass2),
(member(staff(Name1,_,_(documentary,_,_),[Producer1,Production_ass1|Core_team1]))),
(member(staff(Name2,_,_(documentary,_,_),[Producer2,Production_ass2|Core_team2]))).
but it is not working. Any help would be greatly appreciated for any of the parts.
Many thanks, Paul