You are asked to write a simple program in Prolog to find a path through a maze. Your
input will consist of facts of the form
pway(a, b, 10).
indicating that there is a passageway from intersection a to intersection b of length 10 meters.
You are to write a rule
solve(X, Y, P, N) :- ...
that will find a path P of length N (if one exists) from intersection X to intersection Y.
The intent is that the user will invoke solve as a query, specifying X and Y as constants and P and N as variables.
Here is a concrete example. Suppose the database contains the following rules:
pway(a, b, 10).
pway(b, c, 15).
pway(d, c, 5).
pway(d, b, 10).
If the user types
solve(a, d, P, N)
the Prolog interpreter might respond with
P = [a, b, c, d]
N = 30 If at this point the user types a semicolon, the interpreter should respond with
P = [a, b, d]
N = 20
One more semicolon should produce
There are no more paths.
1. Note that passageways are bi-directional; if you can walk 10 meters from a tob, you can
also walk 10 meters from b toa.
2. Most mazes will have cycles. Your code must cope with them. There's no point in
passing through the same intersection more than once, and you certainly don't want the
interpreter to fall into an infinite regression doing so.
3. Note that the bi-directionality of passageways creates a huge number of trivial cycles:
you'll want to avoid walking from a tob and back to a again.
1. You might find the tutorials at the link below very useful.
[login to view URL]~jrfisher/www/prolog_tutorial/[login to view URL]
2. You shouldn't need to use any imperative features of Prolog (the cut, fail, or
database ordering) for this work. In fact, you shouldn't even need not, though you'll
probably want \= (numeric ``not equal''). A solution for the assignment consisting of
only seven rules does exist!
3. You'll want to add distances. Remember that you must use the is predicate to force
4. generating all possible solutions, sorting them, and then producing them one-by-one on
demand. Other approaches may be easier, however. You may need the use of cut and fail
for the this part of the work.
[login to view URL] script. Make sure to you will deliver your work as a include your README
and test cases/mazes.
6 freelancers are bidding on average $52 for this job
Hi, I am a software engineer experienced in Prolog (I am using SWI Prolog). I can complete your project within 3 days from awarding, properly tested and commented. Looking forward to hearing from you.