3
I am implementing an in-depth graph search in Prolog, I already have the following:
%arestas:
edge(c4,b4).
edge(b4,b3).
edge(b3,a3).
edge(b3,c3).
%determina que o grafo é nao direcionado
edge(V1, V2) :- edge(V2, V1).
%busca em profundidade
dfsB(Node,Solution) :- dfsB3(Node, [], Solution).
dfsB3(Node, History, [Node|History]) :- goal(Node).
dfsB3(Node,History,Solution) :- sucessor(Node, Node1), not(member(Node1,History)), dfsB3(Node1,[Node|History],Solution).
sucessor(X,Y) :- edge(X,Y). %esta certo?
In the dfs
, History
is a list of the nodes that have already been visited.
I’m in doubt if the sucessor(X,Y)
is correctly implemented.
And when rotating a query dfs(c4,a3)
(which was supposed to run because it has a path) SWI-Prolog is running and does not finish. So I believe I need to limit the depth of the search... how can I do that?