Code Comments
Programming Forum and web based access to our favorite programming groups.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?
Post Follow-up to this messageOn Mar 17, 8:30 pm, ajpowerran...@googlemail.com wrote: > 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? I'm not sure if breadth-first entirely explains what one wants to do in a maze search task. Of course, if that is in some sense a requirement of your coding, then so be it. However I'd think a more natural requirement would be that the path not "self-intersect". Is that of some assistance? regards, chip
Post Follow-up to this messageIn message <cfb27fa3-bc66-4489-8964-9ff52ab4e8a6@e10g2000prf.googlegroups.com>, ajpowerranger@googlemail.com 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 nick@maproom.co.uk
Post Follow-up to this messageOn Mar 18, 11:17 am, Nick Wedd <n...@maproom.co.uk> wrote: > In message > <cfb27fa3-bc66-4489-8964-9ff52ab4e...@e10g2000prf.googlegroups.com>, > ajpowerran...@googlemail.com writes > > > > 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...@maproom.co.uk 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)
Post Follow-up to this messageOn Mar 18, 7:33 am, ajpowerran...@googlemail.com wrote: > On Mar 18, 11:17 am, Nick Wedd <n...@maproom.co.uk> wrote: > > > > > > > > > > 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
Post Follow-up to this messageOn Mar 18, 11:32 pm, Chip Eastham <hardm...@gmail.com> wrote: > On Mar 18, 7:33 am, ajpowerran...@googlemail.com wrote: > > > > > > > > > > > > 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?
Post Follow-up to this messageOn Mar 18, 9:45 pm, ajpowerran...@googlemail.com wrote: > On Mar 18, 11:32 pm, Chip Eastham <hardm...@gmail.com> wrote: > > > > > > > > > > > > > > > > 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
Post Follow-up to this messageOn Mar 19, 11:56 am, Chip Eastham <hardm...@gmail.com> wrote: > On Mar 18, 9:45 pm, ajpowerran...@googlemail.com wrote: > > > > > > > > > > > > > > > > > > > > > > > > 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?
Post Follow-up to this messageOn Mar 19, 1:36 pm, ajpowerran...@googlemail.com wrote: > On Mar 19, 11:56 am, Chip Eastham <hardm...@gmail.com> wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Thanks, I am really new to prolog and that went over my head lol could > you help me get started with this please? Let's start with what the standard findall/3 predicate is supposed to do. The slash-3 means "this predicate has three arguments". findall(Instance,Goal,List) The Instance here is a variable or term containing variables that appear within the Goal expression. findall succeeds by binding List to a list of all values to which Instance binds when Goal succeeds. Typically Goal is a nondeterministic predicate, meaning it can succeed in more than one way, and thus List gets to be a list of length greater than 1. However Goal might not succeed at all, in which case List is an empty list, or it might succeed in just one way (determinism), in which case List has length 1. Example: Suppose we have a fact-like predicate: edge(a,b). edge(b,c). edge(c,d). Then we could ask for: findall(X:Y,edge(X,Y),List). and get the result: List = [a:b,b:c,c:d] The items of the list have the same form as the first argument of findall/3. What you coded was a bit tricky in assigning a compound goal (a goal with subgoals) to the second argument. This is where your predicate path/3 comes in: findall( [NewNode, Node |Path], (path(Node, NewNode, Path), not(member(NewNode, [Node | Path]))), NewPaths ) as part of the Goal argument to findall. So, how did you define predicate "path" (if you did), and which version of Prolog are you using? It seems strange that you found it necessary to write an implementation of findall/3 for your program. regards, chip
Post Follow-up to this messageIn message <9e14cc38-bc72-449e-a522-496a66bb87ec@s19g2000prg.googlegroups.com>, ajpowerranger@googlemail.com writes >On Mar 18, 11:17 am, Nick Wedd <n...@maproom.co.uk> wrote: > >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) Does the noise propagate along the passages, so that it will increase, or at least not decrease, as we take the correct path to the exit? Or does it propagate over the walls, so that it will be almost useless as a guide? If the former, a breadth-first search, exhaustively searching routes which we know are wrong, seems daft. If the latter, I recommend ignoring the noise level. As for your error message - Chip Eastham has now explained it. Nick -- Nick Wedd nick@maproom.co.uk
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.