Travel Agency Routes

Assume that a travel agency asks to derive all the destinations reachable by an airline company either by using its vectors or by exploiting code-share agreements. Suppose that the direct flights of each company are stored in a relation flight_rel(Id, FromX, ToY, Company) of the database dbAirports, whereas the code-share agreements between companies are stored in a relation codeshare_rel(Company1, Company2, FlightId) of an external database dbCommercial; if a code-share agreement holds between the company c1 and the company c2 for FlightId, it means that the flight FlightId is actually provided by a vector of c1 but can be considered also carried out by c2. Finally, assume that, for security reasons, it is not allowed to travel agencies to directly access the databases dbAirports and dbCommercial, and, consequently, it is necessary to store the output result in a relation composedCompanyRoutes of a separate database dbTravelAgency supposed to support travel agencies. The datalog program that can derive all the connections is:

destinations(FromX, ToY, Comp) :- flight(Id, FromX, ToY, Comp).
destinations(FromX, ToY, Comp) :- flight(Id, FromX, ToY, C2), codeshare(C2,Comp, Id).
destinations(FromX, ToY, Comp) :- destinations(FromX, T2, Comp), destinations(T2, ToY, Comp).

In order to exploit data residing in the databases cited above, we should map the predicate flight with the relation flight_rel of dbAirports and the predicate codeshare with the relation codeshare_rel of dbCommercial. Finally, we have to map the predicate destinations with the relation composedCompanyRoutes of dbTravelAgency.

Solution with #import/#export.

The commands that must be added to the datalog program above to implement mappings are:

#import(dbAirports, "airportUser", "airportPasswd", "SELECT * FROM flight_rel", flight, type : U_INT, Q_CONST, Q_CONST, Q_CONST).
#import(dbCommercial, "commUser", "commPasswd", "SELECT * FROM codeshare_rel", codeshare, type : Q_CONST, Q_CONST, U_INT).
#export(dbTravelAgency, "agencyName", "agencyPasswd", destinations, composedCompanyRoutes).

The command line to evaluate the logic program (whit #import and #export command) in main-memory is:

dl travel_agency_ie.dlv

where, dl is an executable version di DLVDB and travel_agency_ie.dlv is a text file containing the logic program and the necessary #import/#export commands.

Solution with Auxiliary Directives.

In order to implement mappings above, the content of file associating whit the logic program, is:

USEDB dlvdb:myname:mypasswd.
USE flight_rel (Id, FromX, ToY, Company)
FROM dbAirports:airportUser:airportPasswd
MAPTO flight (integer, varchar(255), varchar(255), varchar(255)).
USE codeshare_rel (Company1, Company2, FlightId)
FROM dbCommercial:commUser:commPasswd
MAPTO codeshare (varchar(255), varchar(255), integer).
CREATE destinations_rel (FromX, ToY, Company)
MAPTO destinations (varchar(255), varchar(255), varchar(255))
KEEP_AFTER_EXECUTION.
OUTPUT destinations AS composedCompanyRoutes
IN dbTravelAgency:agencyName:agencyPasswd.

If we want to perform the execution in mass-memory (on a DBMS), the command line needed to evaluate the logic program is:
dl -DBSupport -ORdr- travel_agency.dlv travel_agency.typ

where, dl is an executable version di DLVDB travel_agency.dlv is a text file containing the logic program see above and travel_agency.typ is a text file containing the auxialry directives.

Reachability

This is an example of the classical Reachability problem. Given a graph G=<N,E> described by the set of its edges – the facts edge(X,Y) – two nodes X and Y are reachable – reachable(X,Y) is true – if there is a path in G from X to Y.

This example will guide you through the complete execution of a program in DLVDB in the direct database execution modality.

Step 1.

Create an empty database on your PC (preferably a PostgreSQL database), and create an ODBC connection to it named dlvdb , user postgres , password postgres

Step 2.

Download the example files and uncompress them in a folder.

Step 3.

From the command line type first the following command (be sure the binary dl is in the path):

dl -DBSupport -ORdr- init-reachability.dl database-facts.dl init-reachability.typ
This is is needed just to load the facts edge contained in the file database-facts.dl in the database you named dlvdb

It is just a fast way to initialize your database for this example. It is not needed if you already have the facts in your database!

Step 4.

You are now able to run the reachability example. Type:

dl -DBSupport -ORdr- reachability.dl reachability.typ

You will find all pairs of reachable nodes in the table reachable the system automatically creates in your database named dlvdb.