2016-11-28 37 views
0

您好所有我有一個問題序言無向圖線發出

我有一個圖形非定向enter image description here enter image description here

我所列舉的在節點的形式,各節點(姓名,[路徑])。 其中具有多個路徑的節點是節點(名稱,[路徑名,路徑])。 //然而,可能的路徑與節點相交。

>node(giant,[sizePath]). 
>node(large,[sizePath]). 
>node(big,[sizePath]). 
>node(a0,[numPath,alphabetPath]). 
>node(1,[numPath]). 
>node(2,[numPath]). 
>node(3,[numPath]). 
>node(b,[alphabetPath]). 
>node(c,[alphabetPath]). 
>node(d,[alphabetPath]). 

然後我寫了一個規則,說明

samePath(Node1,Node2,PathName):-node(Node1,PathName),node(Node,1PathName). 

如果我用值samePath(2,3,PathName)我得到的輸出

true; 
numLine. 

但是如果我使用的值samePth(A0,1,PathName)我應該得到

true; 
numLine. 

但是我得到

true; 
fail. 

,因爲它不會只列出兩個列表中匹配的元素

+0

您需要展示整個程序! – false

+0

我做到了,但在這裏再次 – techninja1997

回答

0

您比較列表,而不是數組中的元素 - 得到這個工作,你應該修改samePath閱讀

samePath(Node1,Node2,PathName) :- 
    node(Node1,Paths1), 
    node(Node2,Paths2), 
    member(PathName,Paths1), 
    member(PathName,Paths2). 

這將統一PathName與這兩個列表中的任何路徑。