11.4 Export Constraint Values to Database

Just as exporting variable values, MPL can also export the constraint values to the database. You will need to define constraint vectors in the CONSTRAINTS section with the keyword EXPORT TO followed by the keyword DATABASE and parentheses containing the table name and the column/field name you want to export to.

Example:

    SUBJECT TO
       FactoryCapacity[factory]
          EXPORT ShadowPrice TO DATABASE("Factory","ShadowPrice");

In the above example, MPL will open the database table Factory, locate the columns FactID and ShadowPrice, and then export in the shadow price values for the constraint FactoryCapacity.

Here is an example of the Factory table after the shadow price values have been exported.

Notice that MPL automatically uses the same name as the default for the index column FactID, as in the original tables the factory index was defined from. If an index column does have a different name than in the original table you can specify it following the table name by first entering the index name followed by an equal sign and the column name.

    SUBJECT TO
       FactoryCapacity[factory]
          EXPORT ShadowPrice TO DATABASE("Factory","ShadowPrice",
                                         factory="Factory");

This means, if you are consistent in naming the columns in different tables, you do not have to specify them each time you refer to them in MPL.

MPL supports multiple databases for both importing and exporting data. The default database is specified in the Database Options dialog box in the Options menu. If you need to export a constraint vector to table in a database other than the default, you can do so by specifying the database name before the name of the table.

In the example below, MPL will export the shadow price of the constraint vector FactoryCapacity from FoxPro instead of the default database.

 SUBJECT TO
   FactoryCapacity[factory]
      EXPORT ShadowPrice TO DATABASE(FoxPro,"Factory","ShadowPrice");

MPL also allows you to export constraint values other than the shadow price. You can export the slack values, the upper and lower ranges for the right-hand-side as well as the right-hand-side values. You change which values will be exported by entering one of the following keywords directly after the keyword EXPORT: Activity, Slack, ShadowPrice, RhsValue, RhsLower, RhsUpper. For example, if you want to export the slack for a constraint enter the following:

    SUBJECT TO
        FactoryCapacity[factory]
           EXPORT Slack TO DATABASE("Factory","Slack");

If you need to export more than one value for a variable vector you can do so by entering multiple export statements after the variable definition.

MPL offers three different options on how the database table is updated by the EXPORT statement. The first one, which is the default, searches through the database and for each record locates the corresponding value in the solver solution and updates the database entry with it. This option minimizes the changes done to the database table since only the existing values are updated, but can sometimes be slow especially on SQL type databases.

The second option is to use the REFILL keyword right after the EXPORT keyword to specify that the whole database table should be emptied and then refilled with the entries from the solver solution. Since this takes out the necessity to search the table this can often lead to faster export times for larger tables.

The third option is to use the CREATE keyword right after the EXPORT keyword to specify that the database table should be created and then filled with the entries from the solver solution. This option is mainly useful when exporting to the database table for the first time.


Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page