나는 가계도를 가지고 있습니다. CLIPS를 사용하여 사람의 며느리를 찾아야합니다. 처남이깡통 'not'와 'eq'가 함께 작동합니다.
규칙 1
(defrule MAIN::fnd_BrthrsNLaw1 ;spouse's brother
(findRelative (person ?pn) (relationship b_i_lw)) ;Brothers-in-Law
(and
(and (and (or (marriage-between (personA ?pn) (personB ?sp))
(marriage-between (personA ?sp) (personB ?pn))
)
(child-of (relationship ?x) (person ?sp) (mother ?m) (father ?f))
)
(child-of (relationship son-of) (person ?pn2) (mother ?m) (father ?f))
)
(not (marriage-between (personA ?pn) (personB ?pn2)))
)
=>
(printout t ?pn "'s brothers-in-Law: (spouse's brother) " ?pn2 crlf)
)
(배우자의 형제를 찾기 위해) 찾을 수
규칙
가계도
규칙 2 (찾을 수 배우자의 여동생의 남편)
(defrule MAIN::fnd_BrthrsNLaw2 ;spouse's sister's husband
(findRelative (person ?pn) (relationship b_i_lw)) ;Brothers-in-Law
(and
(and
(and
(or
(marriage-between (personA ?pn) (personB ?sp))
(marriage-between (personA ?sp) (personB ?pn))
)
(and
(child-of (relationship ?x) (person ?sp) (mother ?a) (father ?b))
(child-of (relationship daughter-of) (person ?p2) (mother ?a) (father ?b))
)
)
(and
(not (eq ?sp ?p2))
(marriage-between (personA ?p2) (personB ?px2))
)
)
=>
(printout t ?pn "'s brothers-in-Law: (spouse's sister's husband) " ?px2 " <sister = " ?p2 " ; spouse = " ?sp " ; spouse's parents: " ?a " , " ?b ">" crlf)
)
규칙 3 (여동생의 남편을 찾을 수)
(defrule MAIN::fnd_BrthrsNLaw3 ;sister's husband
(findRelative (person ?p) (relationship b_i_lw)) ;Brothers-in-Law
(and
(and
(child-of (relationship ?y) (person ?p) (mother ?c) (father ?d))
(child-of (relationship daughter-of) (person ?sist) (mother ?c) (father ?d))
)
(and
(not (eq ?p ?sist))
(marriage-between (personA ?sist) (personB ?p2))
)
)
=>
(printout t ?p "'s brothers-in-Law: (sister's husband) " ?p2 <sister = " ?sist " ; " ?p "'s parent = " ?sp " ; spouse's parents: " ?c " , " ?d ">"crlf)
(reset)
)
템플릿
(deftemplate MAIN::marriage-between
(slot personA)
(slot personB))
(deftemplate MAIN::child-of
(slot relationship (type SYMBOL) (allowed-symbols son-of daughter-of))
(slot person)
(slot mother)
(slot father))
(deftemplate MAIN::findRelative
(slot relationship (type SYMBOL)
(allowed-symbols g_g_p ;Great-GrandParents
g_ch ;GrandChildren
b_i_lw)) ;Brothers-in-Law
(slot person))
,451,515, 지금 - 1) 다이애나, 처남 (또는 b_i_lw) 앤드류 마크 에드워드 2) 마크해야, b_i_lw의 앤드류, 에드워드와 찰스이다. 3) Charles, b_i_lw '는 Mark 여야합니다. 일부 잘못된 정보도 배우자의 형제 자매 (규칙 "fnd_BrthrsNLaw2"라는 이름의)와 자매의 남편 ("fnd_BrthrsNLaw3"라는 규칙)의 규칙에 대한 올바른 사람과 추론 될 때
하지만 내 출력은 완전히 정확하지 않습니다. 다이애나를 검색하는
출력 : 마크, 다이애나와 찰스에 대한
출력 아래에서 언급
CLIPS> (assert (findRelative (person Diana) (relationship b_i_lw)))
<Fact-20>
CLIPS> (run)
Diana's brothers-in-Law: (spouse's brother) Edward
Diana's brothers-in-Law: (spouse's brother) Andrew
Diana's brothers-in-Law: (spouse's sister's husband) Mark <sister = Anne ; spouse = Charles ; Charles's parents: Elizabeth , Phillip>
Diana's brothers-in-Law: (sister's husband) Charles <sister = Diana ; Diana's parent: Kydd , Spencer>
출력 마크를 검색하는 :
CLIPS> (assert (findRelative (person Mark) (relationship b_i_lw)))
<Fact-20>
CLIPS> (run)
Mark's brothers-in-Law: (spouse's brother) Edward
Mark's brothers-in-Law: (spouse's brother) Andrew
Mark's brothers-in-Law: (spouse's brother) Charles
Mark's brothers-in-Law: (spouse's sister's husband) Mark <sister = Anne ; spouse = Anne ; Anne's parents: Elizabeth , Phillip>
Charles 검색을위한 출력 : 나는 (이 없습니다 (당량))입니다 테스트 한하지만
CLIPS> (assert (findRelative (person Charles) (relationship b_i_lw)))
<Fact-20>
CLIPS> (run)
Charles's brothers-in-Law: (spouse's sister's husband) Charles <sister = Diana ; spouse = Diana ; Diana's parents: Kydd , Spencer>
Charles's brothers-in-Law: (sister's husband) Mark <sister = Anne ; Anne's parent: Elizabeth , Phillip>
내 가정은 그들 안에있는 '및'블록에 영향을 미치는되지 않는 규칙 2, 규칙 3 (하지 (EQ))의 사용이다 그들이 동등 할 때 언제나 진실하고 동등하지 않고 거짓이되는 것을 얻습니다.
고마워요. 나는이 수수께끼를 풀기 위해 무관 한 것을 배우는 데 3 일을 이미 잃어 버렸다. – fs71gh
가독성을 위해 규칙에서 "and"조건부 요소를 제거 할 수도 있습니다. 나열된 규칙에서는 불필요합니다. 일반적으로 "not"조건부 요소와 함께 여러 패턴을 배치해야 할 때이를 사용합니다. –