Find the shortest path between two nodes in a graph in (Prolog) and display the result as array

自作多情 提交于 2019-12-25 04:34:07

问题


[

]

How can I write (using print_path) a rule to print the path from one node to another if exists

Print_path(a, c, Res) --->  Res=[a, f, c]

What I did was :

path(a,b). %there is a path from a to b 
path(a,f).
path(b,c).
path(c,d).
path(c,e).
path(e,d).
path(f,g).
path(f,c).
path(f,e).`

I do not know what to do next.

来源:https://stackoverflow.com/questions/41112132/find-the-shortest-path-between-two-nodes-in-a-graph-in-prolog-and-display-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!