Question: 1 Searching using Prolog 1 . 1 Finding a path Consider the plan of a house as shown in Fig. 1 . Write a Prolog
Searching using Prolog
Finding a path
Consider the plan of a house as shown in Fig. Write a Prolog description of this plan that
allows a Prolog program search for paths between locations indicated on the plan. For
example, if one is Outside and wishes to find a path to the WC then a possible answer can be:
Outside Porch Kitchen Leaving Room Corridor WC Your program should
Figure : Top view of a two bedroom house showing how different locations in and out of
the house are connected.
avoid loops and be as general as possible, in that, given any two locations representing an
origin and a destination it returns:
a path from to if it exists;
every possible path from to if there are more than one;
meaningful error messages, if the wrong input is provided for and
Comment the code submitted for this part to contain the name of the search algorithm that
you selected to find the path.
Paths ending at a common destination
Define a Prolog program that searches bidirectionally from two origins and to meet
up at a common destination D It is up to you how you define that, perhaps by reusing parts
of the program you developed for section however this time you do not have to check
that the input parameters are correct, simply assume they are. Your program should
combine a path from to with a path from to if they exist, to produce a
combined path showing how you reach meeting point from and respectively. You
are expected to produce all possible combinations P and P to construct P non
deterministically, if we ask for more answers. Test your program using Fig. by asking
different queries and see whether your work produces the expected outcomes. Maximum
marks will be obtained for also providing a program that returns only the shortest paths P
and P combined to produce P
Paths with Costs
Rewrite the problem description for the program you defined in section to include the
individual cost an integer describing the distance in meters between locations of the
house as shown in Fig. Once you have a new representation that takes individual cost
between locations into account, rewrite also you search program to calculate the total cost
of a path, so that when you return a path P as a solution, you also return Your new
program should also return every path, if there is more than one, returning the cheap ones
first, and then the more expensive ones, in rank order. Then use your new program to define
how to meet up from two origins and to a destination as in only if the cost
is the same from both and respectively.
Cost as distance
Figure : Cost between locations.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
