2016-11-28 5 views
0

こんにちは問題をプロローグ無向グラフ線は

を有していたすべてのIは、非enter image description here enter image description here

を有向グラフを持っを発行Iは、ノードの形(名前、[パス])内の各ノードを列挙しています。 複数のパスを持つノードはノード(名前、[パス名、パス])です。 //ただし、パスがノードと交差する可能性があります。私はその後、私は値samePth(A0,1,PathName)を使用している場合、私は

を取得する必要があり、私は私が

true; 
numLine. 

しかし出力を得るsamePath(2,3,PathName)を値を使用している場合

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

を記載ルールを書かれている

>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]). 

true; 
numLine. 

それは両方のリストに一致する要素のみを表示されませんように私は

true; 
fail. 

取得しかし

+0

プログラム全体を表示する必要があります。 – false

+0

私はここでしたが、もう一度です – techninja1997

答えて

0

あなたはむしろ、リストの要素よりも、リストを比較している - これは、変更すべき作業samePathを取得しますto read

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

これにより、両方のリストのパスでPathNameが統一されます。