1
Given the width search on graphs in Prolog, a graph where one node connects to the other via the connected fact(a,b). connected(b,c). connected(b,e). And so on, the algorithm would normally work by returning to the user the shortest route between a starting node, the first node or not, and the destination node, which could also be either. The algorithm would look like this:
/* Chegar de A a Z, retornando caminho percorrido P,
comecando de um caminho vazio
*/
path(A,Z,P) :- path1(A,Z,[],P).
/* Se ja' cheguei ao destino, parar a busca e incluir
destino na lista contendo o caminho percorrido */
path1(Z,Z,L,L).
/* Se ainda nao cheguei no destino, encontrar caminho
parcial de A para Y, adicionar `a lista contendo o
caminho parcial e continuar a busca a partir de Y
*/
path1(A,Z,L,P) :- (conectado(A,Y);conectado(Y,A)),
\+ member(Y,L),
path1(Y,Z,[Y|L],P). /* encontra caminho parcial de */
/* Y a Z */
However I seek something different for my application, I need not receive the shortest path between the starting point and the destination, but rather I want to receive the virtual path that the algorithm has traveled to obtain this result. That is, if he had to check all of us of the same width, only then to increase the depth, since this that the search in width does obviously, I want to receive not the direct path to the goal, but the figurative path that the algorithm had to do, that is, that the way he returns me contains us all in the same width before passing to the next level, instead of not including them in the answer to seeing that there is a shorter path. Basically I do not want to receive the best ideal path from X to Y, but rather the path that the algorithm searches in width had to go through in the graph to return me this path, as if it were a debug