저는 프롤로그를 처음 사용하며이 과제를 완료해야합니다. 나는 가지고있는 사실과 내가 직접 만든 결론과 어떻게 관계를 맺는 지 매우 혼란 스럽다. 이 질문의 코드 섹션에는 주어진 정보 목록과 데이터에서 얻은 결론이 나와 있습니다. 과제를 완료하기 위해 올바른 방향으로 안내 할 수 있다면 감사하게 생각합니다. 미리 감사드립니다. 원래의 질문 TO프롤로그 잡동사니 퍼즐
%There are three people: John, Jim, and Mary and each has two jobs.
%The jobs are gardener, veterinarian's assistant, dishwasher, nurse,
%high school math teacher, and biology tutor.
%You are given the following information:
%1) The nurse went out with the veterinarian's assistant last night.
%2) Mary is friends with the biology tutor but she stayed home last night.
%3) Jim likes animals but he failed math and had to drop out of college.
%4) Jim does not know the gardener.
%5) Mary and the biology tutor used to be married.
%My Conclusions from Facts:
%6) Mary is not the biologyTutor because she did not go out with the
% biologyTutor and she was married to the biology tutor (2&5)
%7) Jim is not the highSchoolMathTeacher because he failed math (3)
%8) Jim is not the gardener because he does not know the gardener (4)
%9) Mary is not the nurse/vetAssistant because she did not go out (1&2)
%10) The biologyTutor went out last night (1&2)
%Who holds which jobs? Include a report explaining your strategy.
%Exepcted Answers:
%Mary: gardener, highSchoolMathTeacher
%Jim: vetAssistant, dishWasher
%John: nurse, biologyTutor
%Given Information, aka FACTS:
%person(Name).
person(mary).
person(jim).
person(john).
%job(JobName).
job(gardener).
job(vetAssistant).
job(dishWasher).
job(nurse).
job(highSchoolMathTeacher).
job(biologyTutor).
went_Out(nurse,vetAssistant).
friends(mary,biologyTutor).
likes(jim,animals).
unknown(jim,gardener).
divorced(mary,biologyTutor).
UPDATE : 그래서 여기
내가 가진 무엇 나는 매우 이상한 오류 받고 있어요 : 내가 쉼표를 꺼내 기간으로 교체 할 경우
%list of people
person(mary).
person(jim).
person(john).
%list of jobs
job(gardener).
job(vetAssistant).
job(dishWasher).
job(nurse).
job(highSchoolMathTeacher).
job(biologyTutor).
%length of variables are 2 &
%Solution is person and corresponding variables
length(MaryJobs,2),
length(JimJobs,2),
length(JohnJobs,2),
Solution = [mary-MaryJobs,jim-JimJobs,john-JohnJobs],
%query to find the jobs AllJobs is a list containing variables of the jobs
findAll(Jobs,job(Job),AllJobs),
AllJobs = [Gardener,VetAssistant,DishWasher,Nurse,MathTeacher,BioTutor],
%Note: im not sure about flatten
flatten([MaryJobs,JimJobs,JohnJobs],Jobs),
permutation(Jobs,AllJobs),
% 6 & 9; Mary is not the Nurse, VetAssistant, or BioTutor
\+ member(Nurse,MaryJobs),
\+ member(VetAssistant,MaryJobs),
\+ member(BioTutor, MaryJobs),
% 7 & 8 & 3 ; Jim is not the MathTeacher or Gardener
\+ member(MathTeacher,JimJobs),
\+ member(Gardener, JimJobs),
%Mary is the Gardener because Jim does not know the
%Gardener, therefore he cannot have gone out with the Gardener.
\+ member(Gardener, JohnJobs),
%Jim must not KNOW Mary because she is the Gardener
%John and Mary must have been married
%Conclusion: Jim is not the Bio Tutor
\+ member(BioTutor, JimJobs),
%logically, since Jim likes animals, it would make sense if he
%were the VetAssistant and since this is true, John is the nurse
\+ member(VetAssistant, JohnJobs),
\+ member(Nurse, JimJobs),
%logically since jim dropped out of college, it would make sense
%if he were to be the dishwasher
\+ member(DishWasher, MaryJobs),
\+ member(DishWasher, JohnJobs).
%Automatically this is should conclude that Mary is the MathTeacher
을, 나는 오류가 발생합니다.
length(MaryJobs,2),
length(JimJobs,2),
length(JohnJobs,2),
Solution = [mary-MaryJobs,jim-JimJobs,john-JohnJobs],
내가 받고 오전 오류 메시지는 다음과 같습니다 :
Warning: /Users/KaitlynChait/Desktop/School/CCNY/Summer 2016/Artificial Intelligence/CSC448_program_2/program2.pl:16:
Singleton variables: [Solution,Job]
ERROR: /Users/KaitlynChait/Desktop/School/CCNY/Summer 2016/Artificial Intelligence/CSC448_program_2/program2.pl:16:
Full stop in clause-body? Cannot redefine ,/2
% /Users/KaitlynChait/Desktop/School/CCNY/Summer 2016/Artificial Intelligence/CSC448_program_2/program2.pl compiled 0.00 sec, 9 clauses
1 ?-
귀하의 과제에 대한 최종 설명은 매우 분명합니다. ** 귀하의 전략을 설명해야합니다 **. 그러니 제발, 가능 ** 계산 가능 ** 해결책이 될 수 있다고 생각하는 것에 대한 힌트를주십시오. – CapelliC
모든 코드를 관련 술어에 넣어야합니다. 그래서'length (MaryJobs, ..)'로 시작하는 곳에서'solve (Solution) : - length (...)'와 같은 술어 이름을 삽입하십시오. 둘째,'findall' 문에는'Job'과'Jobs'가 있습니다 - 따라서 싱글 톤 경고는 같은 것으로 이름을 변경하십시오. – SND