ODBC Data Sources

Windows versions of LINGO include a variation of the standard transportation model that retrieves all data from a database, and writes a solution back to the same database. This file can be found in the file SAMPLES\TRANDB.LG4. The contents of this model are displayed below.

MODEL:

  ! A 3 Plant, 4 Customer Transportation Problem;

 

  ! Data is retrieved from either an Access, SQL  or

    Oracle database using an ODBC link. You *MUST* use the

    ODBC Administrator to register one of the supplied

    databases under the name "Transportation" in order

    to get this model to run. Refer to Chapter 10 for

    more details.;

 

  TITLE Transportation;

   

  SETS:

     PLANTS: CAPACITY;

     CUSTOMERS: DEMAND;

     ARCS( PLANTS, CUSTOMERS): COST, VOLUME;

  ENDSETS

 

  ! The objective;

    [OBJ] MIN = @SUM( ARCS: COST * VOLUME);

 

  ! The demand constraints;

    @FOR( CUSTOMERS( C):

       @SUM( PLANTS( P): VOLUME( P, C)) >= DEMAND( C));

 

  ! The supply constraints;

    @FOR( PLANTS( P):

       @SUM( CUSTOMERS( C): VOLUME( P, C)) <= CAPACITY( P));

 

  DATA:

 

     ! Import the data via ODBC;

     PLANTS, CAPACITY    = @ODBC();

     CUSTOMERS, DEMAND   = @ODBC();

     ARCS, COST          = @ODBC();

 

     ! Export the solution via ODBC;

     @ODBC()  = VOLUME;

 

  ENDDATA

 

END

Model: TRANDB

You will note that in the data section of this model, we use the @ODBC function to establish a link to an ODBC data source to retrieve all the data and to export the final solution.

An ODBC data source is a database that 1) resides in a DBMS for which you have an ODBC driver, and 2) has been registered with the ODBC Administrator. Databases in an ODBC enabled DBMS do not qualify as an ODBC data source until they have been registered with the ODBC Administrator. The ODBC Administrator is a Windows Control Panel utility. Registering a database with the ODBC Administrator is a straightforward process. We illustrate the registration process for a Microsoft Access database and for an Oracle database.