Re: Help with a breadth first search in prolog.



On Mar 19, 11:56 am, Chip Eastham <hardm...@xxxxxxxxx> wrote:
On Mar 18, 9:45 pm, ajpowerran...@xxxxxxxxxxxxxx wrote:



On Mar 18, 11:32 pm, Chip Eastham <hardm...@xxxxxxxxx> wrote:

On Mar 18, 7:33 am, ajpowerran...@xxxxxxxxxxxxxx wrote:

On Mar 18, 11:17 am, Nick Wedd <n...@xxxxxxxxxxxxx> wrote:

In message
<cfb27fa3-bc66-4489-8964-9ff52ab4e...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
ajpowerran...@xxxxxxxxxxxxxx writes

I am trying to do a task I found on breadth first searchs but am
stuck! The task is a maze, at each node is a sound level the higher
the sound the closer the the exit you are. I have written a lot of
code for this task so far which I will post if anyone actually replys
to this message (prolog seems to be a hard area to get help for
online!)

Would anyone be able to help me get the solution to the task?

Does your solution work if you leave out the bit about the sound level?

(You have asked "I have written a program with at least one bug in it,
please help me to find the bug". I am doing my best.)

Nick
/--
Nick Wedd n...@xxxxxxxxxxxxx

Thanks for the reply, I am new at prolog. The task is meant to sort
the nodes by noise level and then output the quickest path from the
start of the maze to the end, this is the error i get when i run the
code: uncaught exception: error(existence_error(procedure,path/
3),findall/3)

Perhaps you've written a subgoal involving findall/3
which invokes solutions to path/3, but that predicate
(at least with arity 3) does not exist??

Certainly check your code for occurrences of findall,
and see if one of these matches the error message.

regards, chip

Thanks for the reply. Here is a section of the code that may make the
problem easier to solve:

solve(Start, Finish, Solution) :-
breadthfirst([[Start]], Finish, Solution).
breadthfirst([[Finish | Path ]], Finish, [Finish|Path]).

breadthfirst([Path | Paths], Finish, Solution) :-
extend(Path, NewPaths),
sortPath(NewPaths, Results),
append(Paths, Results, Paths1),
breadthfirst(Paths1, Finish, Solution).

extend([Node | Path], NewPaths) :-
findall([NewNode, Node |Path],
(path(Node, NewNode, Path),
not(member(NewNode, [Node | Path]))), NewPaths), !,
extend(Path ,[]).

findall(X,Goal,Xlist) :-
call(Goal),
assertz(queue(X)),
fail;
assertz(queue(bottom)),
collect(Xlist).

collect(L) :-
retract(queue(X) ) , !,
(X == bottom, !, L=[]
;
L=[X | Rest], collect(Rest) ).

I have the findall procedure so why do i get the error? and how can io
solve it?

My concern was not that findall is undefined (it is a builtin
predicate for most Prologs), but rather that path/3 is not
defined. Notice that findall, as invoked by extend/2, will
supply the compound goal:

(path(Node, NewNode, Path), not(member(NewNode, [Node | Path])))

Your code snippet shown above does not define path/3, but
I'd guess that what you want is for it to find NewNode
adjacent to Node (the rest of the compound goal being
a check to see that NewNode is distinct from the nodes
previously "visited" by Path.

But since Path is being passed as an argument to path/3,
I think it makes more sense to formulate a predicate
that combines both finding NewNode adjacent to Node
and checking NewNode is distinct from previous nodes
on Path.

regards, chip


Thanks, I am really new to prolog and that went over my head lol could
you help me get started with this please?
.