2016-07-20 5 views
1

私はプロローグを新しくしており、この課題を完了する必要があります。 私は、私が持っている事実と私が自分で作った結論との関係を作る方法について非常に混乱しています。 この質問のコードセクションには、特定の情報のリストとデータからの私の結論が掲載されています。 割り当てを完了するために正しい方向に導くことができれば、私はそれを感謝するでしょう。 ありがとうございます!元の質問TOProlog Jobs Puzzle

%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

これはあなたのワークフローを説明しなければならない割り当てがあるので、私は完全な提供することはありません 主なエラーが含むコードでありますむしろ、この問題にどのようにアプローチできるかについてのいくつかのアイデアや指針を示しています。あなたは簡単に必要な変数にアクセスすることができ、このような方法で作成したソリューションを、表すモデルをするつもりだ

MODEL

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

ここでは、それぞれMary、Jim、Johnの2つのジョブを表す3つの変数があります。

は第二に、我々は彼らと仕事をするために使用可能なジョブの事実を使用する必要があるので、私たちはの同類で何かの操作を行います。我々は我々のモデルと関連するすべての必要な情報を持っている。この時点で

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

をこのラインでプロローグが異なる選択肢の間の分岐開始することを

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

注:我々は、我々のモデルなどのような、利用可能なすべてのジョブ間の関係を記述することができます。

RULES

あなたはすでにあなたの質問に英語でのルールのほとんどを書かれているので、それは本当にかかっているすべてのプロローグにそれらを翻訳しています。例を見てみましょう:

"VetAssistantは看護婦+メアリーと出かけませんでした。単にコードで、だから、 『

をメアリーは看護することはできません、また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