Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

This is a classical Prolog application. Given the following graph of possible flights between seven US cities: (graph taken from the web site of the...

This is a classical Prolog application. Given the following graph of possible flights between

seven US cities:

(graph taken from the web site of the American Mathematical Society, http://www.ams.org)

Write a Prolog program that would check if there is a route from a city A to a city B:

Steps:

1. Encode your database of facts:

flight(fresno, seattle).

flight(seattle, omaha).

and so on.

2. Write the rules:

What does it mean that there is a route from city A to city B? Well, we either have a

direct connection, or we can to go from A to some city from which we have a direct

connection to B. This is written as:

route(A, B) :- flight(A, B).

route(A, B) :- route(A, X), flight(X, B).

And that’s it.

Now you can ask Prolog if there is a routs from a city to a city, for example:

?- route(fresno, atlanta).

You do not have to turn in the primer, but it will be useful to code it, as a warm-up, and to get a

sense of working in Prolog.

Note that the way the route rule was written is actually a recursion.

route(A, B) :- flight(A, B).

is the base case, and:

route(A, B) :- route(A, X), flight(X, B).

is the recursive step. Every time we apply the recursive step, we should be getting one city closer

to the source.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question