ODBC data exchange of composite objects

This is a companion article to Modeling composite objects.

The two modeling approaches in that article lead to different structuring of the data. As ODBC databases are frequently used to exchange data with mathematical programming applications, it is worthwhile to check how to exchange data using the two modeling approaches for composite objects.

The AIMMS 4.82 project download

Data table declaration in SQLite

1CREATE TABLE "ArcsComponentBased" (
2    "arcId" TEXT NOT NULL,
3    "from"  TEXT NOT NULL,
4    "to"    TEXT NOT NULL,
5    "flow unit cost"    REAL,
6    PRIMARY KEY("arcId")
7)

As this table is about data of arcs, and arcs are considered to be identifiable objects, the practice is followed to have a single column as the primary key for this table.

Database writing in the component based approach

To accomodate the column arcId in the database table, an artificial element is created for each valid combination of (i_nodeFrom, i_nodeTo) and stored in the element parameter ep_backRef(i_nodeFrom, i_nodeTo). With this element parameter, writing to a database table in AIMMS is straightforward. First, the database table is declared in AIMMS as follows:

 1DatabaseTable db_arcs1 {
 2    DataSource: sp_connectionString;
 3    TableName: "ArcsComponentBased";
 4    Mapping: {
 5        "from"           --> i_nodeFrom,
 6        "to"             --> i_nodeTo,
 7        "flow unit cost" --> p_cost1( i_nodeFrom, i_nodeTo ),
 8        "arcId"          --> ep_backRef(i_nodeFrom, i_nodeTo)
 9    }
10}

And then the writing to that table is done using the following code:

1Procedure pr_writeComponentBasedToDatabase {
2    Body: {
3        write to table db_arcs1 ;
4    }
5}

Database writing in the reference element based approach

As the reference element based approach is closely linked to database design for objects, there is no need to create additional identifiers.

 1DatabaseTable db_arcs2 {
 2    DataSource: sp_connectionString;
 3    TableName: "ArcsReferenceBased";
 4    Mapping: {
 5        "arcId"          --> i_arc,
 6        "from"           --> ep_arcNodeFrom( i_arc ),
 7        "to"             --> ep_arcNodeTo( i_arc ),
 8        "flow unit cost" --> p_cost2( i_arc )
 9    }
10}
1Procedure pr_writeReferenceBasedToDatabase {
2    Body: {
3        write to table db_arcs2 ;
4    }
5}

Summary

Exchanging data with databases is can be done for both the component based and reference element based approaches to handle composite objects.