2016-07-20 2 views
1

저는 프롤로그를 처음 사용하며이 과제를 완료해야합니다. 나는 가지고있는 사실과 내가 직접 만든 결론과 어떻게 관계를 맺는 지 매우 혼란 스럽다. 이 질문의 코드 섹션에는 주어진 정보 목록과 데이터에서 얻은 결론이 나와 있습니다. 과제를 완료하기 위해 올바른 방향으로 안내 할 수 있다면 감사하게 생각합니다. 미리 감사드립니다. 원래의 질문 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 ?- 
+1

귀하의 과제에 대한 최종 설명은 매우 분명합니다. ** 귀하의 전략을 설명해야합니다 **. 그러니 제발, 가능 ** 계산 가능 ** 해결책이 될 수 있다고 생각하는 것에 대한 힌트를주십시오. – CapelliC

+0

모든 코드를 관련 술어에 넣어야합니다. 그래서'length (MaryJobs, ..)'로 시작하는 곳에서'solve (Solution) : - length (...)'와 같은 술어 이름을 삽입하십시오. 둘째,'findall' 문에는'Job'과'Jobs'가 있습니다 - 따라서 싱글 톤 경고는 같은 것으로 이름을 변경하십시오. – SND

답변

0

이 당신이 당신의 워크 플로우를 설명해야 과제이기 때문에, 나는 전체 제공하지 않습니다 주요 오류가 포함 된 코드에 오히려이 문제에 접근 할 수있는 방법에 대한 몇 가지 아이디어와 지침을 제공합니다.

모델은

당신은 당신이 쉽게 필요한 변수에 액세스 할 수있는 방법으로 만든 솔루션을 나타내는 모델을 원하는 것입니다. 예를 들면 다음과 같습니다 :

length(MaryJobs,2), 
length(JimJobs,2), 
length(JohnJobs,2), 
Solution = [mary-MaryJobs,jim-JimJobs,john-JohnJobs] 

이제 Mary, Jim 및 John의 두 작업을 나타내는 3 개의 변수가 있습니다.

둘째, 우리는 그들과 함께 작업하기 위해 사용할 수있는 작업 사실을 사용해야합니다, 그래서 우리의 좋아하는 뭔가 할 : 우리는 우리의 모델과 관련된 필요한 모든 정보를이 시점에서

findall(Job,job(Job),AllJobs), 
AllJobs = [Gardener,VetAssistant,DishWasher,Nurse,MathTeacher,BioTutor]. 

을 우리는과 같이 우리의 모델과 사용 가능한 모든 작업 사이의 관계를 작성할 수 있습니다 :이 라인에 프롤로그가 다른 옵션 사이에서 분기 시작됩니다

flatten([MaryJobs,JimJobs,JohnJobs],Jobs), 
permutation(Jobs,AllJobs) 

참고.

그래서 정말 달려 그 모든 프롤로그에 그 번역되어, 당신은 이미 귀하의 질문에 영어로 대부분의 규칙을 작성했습니다

규칙 금지. 예를 들어 봅시다 :

"VetAssistant는 간호사와 함께 나갔다 + Mary는 외출하지 않았습니다.단순히 코드에서, 그래서 "

을 마리아는 간호사가 될 ​​수 없다, 나 VetAssistant"

이 암시 적으로 아직 명시된 바와 같이 말한다 "

\+ member(Nurse,MaryJobs), 
\+ member(VetAssistant,MaryJobs) 

당신이 생각이 라인을 따르는 경우 당신의 영어 규칙을 모두 Prolog 코드로 번역하면, 나 자신이 가지고있는 것처럼 몇 가지 해결책이 남을 것입니다. 최종 결과를 얻으려면 언급하지 않은 숨겨진 암시 적 규칙이 하나 더 있습니다. 아직 여기 쓰실 수 있지만 어쩌면 먼저 시도해 보셔야합니다. 어쨌든 재미 있어요.

행운을 빌어 요!

+0

정말 고마워요 !! 이것은 내 숙제자와 어디를 가야 하는지를 이해하는 데 정말로 도움이되지만, 안심을 위해 사소한 질문을해야합니다. 해결 방법 = [mary-MaryJobs, jim-JimJobs, john-JohnJobs] 이것은 솔루션 목록 일뿐만 아니라 - 구문에 대해 잘 모르겠습니다. – KatieRose1029

+0

'(-)/2'는 단순히 쌍을 나타냅니다. 자세한 내용은 [this] (http://stackoverflow.com/a/8053234/1153801) 응답을 참조하십시오. 이름을 제외하고 대신'Solution = [MaryJobs, JimJobs, JohnJobs]'라고 할 수 있습니다. 최종 결과가 반환 될 때 명확성을 위해 방금 추가했습니다. – SND

+0

광고 나는 사람들과 일자리의 동일한 목록을 유지합니까? – KatieRose1029