CSc 8710 Deductive Databases and Logic Programming
Assignment 3: Due 5 October 1998 (Monday)

Consider the following base relation:
  flights(Airline,From,To,Departs,Arrives)
with the sample data:
  flights('UA','SF','DEN',930,1230).
  flights('AA','SF','DAL',900,1430).
  flights('UA','DEN','CHI',1500,1800).
  flights('UA','DEN','DAL',1400,1700).
  flights('AA','DAL','CHI',1530,1730).
  flights('AA','DAL','NY',1500,1930).
  flights('AA','CHI','NY',1900,2200).
  flights('UA','CHI','NY',1830,2130).

Write (a) Prolog programs and (b) Procedural programs (using embedded-SQL or JDBC or SQLJ) with a suitable user interface to answer the following queries:

  1. Get the pairs of cities (X,Y) for which it is possible to get from city X to city Y by taking one or more flights. In Prolog, define a predicate reaches(X,Y) to solve this query.
  2. Get the pairs of cities (X,Y) for which it is possible to get from city X to city Y by taking one or more United Airlines flights but it is not possible to do so by taking one or more American Airlines flights. In Prolog, define the predicate united_only(X,Y) to solve this query.
  3. connects(X,Y,D,A) = true if it is possible to start in city X at time D and arrive at city Y at time A by taking one or more connecting flights. Assume that there must be at least one hour to make a connection.
In Oracle, you should define the FLIGHTS table as follows:
    create table flights (
      airline   char(2),
      dcity     char(3),
      acity     char(3),
      dtime     integer,
      atime     integer);
and populate the table using the following statements:
  insert into flights values ('UA','SF','DEN',930,1230).
  insert into flights values ('AA','SF','DAL',900,1430).
  insert into flights values ('UA','DEN','CHI',1500,1800).
  insert into flights values ('UA','DEN','DAL',1400,1700).
  insert into flights values ('AA','DAL','CHI',1530,1730).
  insert into flights values ('AA','DAL','NY',1500,1930).
  insert into flights values ('AA','CHI','NY',1900,2200).
  insert into flights values ('UA','CHI','NY',1830,2130).