使用以下形式的事实制作约会数据库:
person(name, age, sex, height, weight, education, salary)
鉴于输入:
datable(alex, X).
datable_weight_limit(alex, 170, X).
其中170是体重的阈值
如何使用规则返回潜在匹配的名称:
我已经建立了这些关系:
edu_less(hs, bachelor).
edu_less(bachelor, master).
edu_less(master, phd).
edu_lesser(A, B):-
edu_less(A, X),
edu_lesser(X, B).
我试过了:
datable(X, Y):-
person(X, Agel, Sexl, Heightl, Weightl, Educationl, Salaryl),
person(Namem, Agem, Sexm, Heightm, Weightm, Educationm, Salarym),
Sexm \== Sexl.
datable(X, Y):-
person(X, Agel, Sexl, Heightl, Weightl, Educationl, Salaryl),
Sexl == female,
findall( X, person(X, _, male, _, _, _, _), Y).
但我似乎没有运气。是否存在我缺少的功能或者我实施的错误?
答案 0 :(得分:2)
我认为你几乎是正确的。试试这个:
datable(M, F):-
person(M, AgeM, male, HeightM, WeightM, EducationM, SalaryM),
person(F, AgeF, female, HeightF, WeightF, EducationF, SalaryF),
AgeM >= AgeF,
edu_lesser(EducationF, EducationM),
datable_weight_limit(M, MaxWeight),
MaxWeight >= WeightF.
我们认为,教育也是数字。
如果您还需要功能 - datable(F,M)
:
datable(F,M) :-
person(F, _, female, _, _, _, _),
datable(M, F).