Prolog Tree Nodes Path

2019-03-01 13:07发布

enter image description here

Hello, I have basic knowledge about prolog and I am facing problems in writing the prolog code for the following problem: Write the fact about the above figure and write the following prolog rule: pos_path.

Sample run of the rule:

?- pos_path(n1, nx, L). 
L = [n1,n3,n7,nx] ? ; 
L = [n1,n3,n4,n5,nx] ? ; 
L = [n1,n3,n4,n6,nx] ? ; 
no

标签: prolog
1条回答
Root(大扎)
2楼-- · 2019-03-01 13:25
edge(ne,n1).
edge(n1,n2).
edge(n1,n3).
edge(n3,n7).
edge(n7,nx).
edge(n3,n4).
edge(n4,n5).
edge(n5,nx).
edge(n4,n6).
edge(n6,nx).

pos_path(A, B, Path) :-
   path(edge, Path, A, B).

using path/4 defined in another question.

查看更多
登录 后发表回答