This sample demonstrates how to use the IBM Decision Optimization Modeling with OPL custom data source .net API to import data from a data source into an OPL model.
This sample illustrates the Working with OPL interfaces -> Custom data sources section from the OPL User's manual. This sample shows you how to read and write tuplesets to/from a database with .net. It also enables you to read a database and generate .dat files to be used in the IDE to prototype your optimization model.
While this sample uses Microsoft SQL Server as data storage, it can be easily adapted to any database that provide a .net client. This example will work with any 12.x OPL version, even if it is configured to run with 12.7.0 version.
- Prerequisites
- Build and run the sample
- Export plain dat files
- Run with a previous OPL version
- License
-
This sample assumes that IBM ILOG CPLEX Optimization Studio 12.7.0 is installed and configured in your environment.
-
This sample assumes you have Visual Studio 2013 installed.
-
Optional: To run the sample with SQL Server, download and install Microsoft SQL Server 2014 Express.
-
Optional: To run the sample with Access, download and install the Microsoft Access Data Engine 2010 Redistributable if you don't have Access installed on your machine.
The solution CustomDataSourceSample.sln
is configured to use the OPL .NET API that
is in $(CPLEX_STUDIO_DIR127)\opl\lib\oplall.dll
. The CPLEX_STUDIO_DIR127
environment
variable is set by the IBM CPLEX Studio installer.
In case it is not set, you need to add the OPL .NET APIs.
-
In the Solution view, select the project (CustomDataSourceSample), the References, and click Add Reference.
-
In the Add Reference Wizard, select Browse, navigate to the OPL installation, and add /lib/oplall.dll.
Build the project with BUILD -> Build Solution (Ctrl+Shift+B).
Edit data\db_mssql.xml
for your database connection string.
Launch the sample using the Visual Studio Debug/Start Debugging command.
The default Start solution configuration appends -export model.dat -create_sample -configuration ../../data/db_mssql.xml
to the command line. This has the effect of:
- use the
data/db_mssql.xml
configuration, which is the default configuration for SQL Server. - create sample demo database on program startup.
- export data to file
result.dat
.
Edit data\db_access.xml
for your database connection string.
Left click CustomDataSourceSample
in the Solution Explorer, then properties.
In the properties window, navigate to the Debug tab. In the command line arguments,
input: -export model.dat -create_sample -configuration ..\..\data\db_access.xml
Launch the sample using the Visual Studio Debug/Start Debugging command. This will:
- use the
data/db_access.xml
configuration, which is the default configuration for Access using OleDb. - create sample demo database on program startup.
- export data to file
result.dat
. - with the default configuration, data are written to file
data\oil.accdb
.
- When running the
CustomDataSourceSample.exe
command, simply add-export model.dat
on the command line, and it will export all the tuplesets that have been extracted from the database tomodel.dat
file. - The default run configuration for CustomDataSourceSample include
-export model.dat
, so after running the sample, you should have amodel.dat
file inbin\Debug
- In the
References
of the project, removeoplall
then add a new reference with your 12.x version. - Recompile the project
This sample is delivered under the Apache License Version 2.0, January 2004 (see LICENSE.txt).