For Python DOcplex or OPL models, you can refer to imported data by using the following syntax.
Python models
inputs['tablename']
. For example, in this line of code, food is an entity that is
defined from the table called diet_food
:
food = inputs['diet_food']
outputs['tablename']
. For example,
outputs['solution'] = solution_df
defines an output table that is called
solution
. The entity solution_df
in the Python model defines this
table.You can find this Diet example in the Model_Builder folder of the DO-samples. To import and run (solve) it in the experiment UI, see Solving and analyzing a Decision Optimization model: the diet problem.
OPL models
tupleset
, for each table that you imported in
the Prepare data
view and with the same names. The schema for
each tupleset must have the same number of columns as the table and use the same field names. For
example, if you have an input table in your Prepare data
view called Product
with the
attributes name, demand, insideCost,
and outsideCost
, your OPL
model must contain the following definition:
tuple TProduct {
key string name;
float demand;
float insideCost;
float outsideCost;
};
{TProduct} Product = ...;
The limitation on only using tuples and tuple sets as OPL input is to facilitate integration with data sources. For example, SQL data sources can be accessed and data-streamed with a minimum of effort; NoSQL data sources can be accessed and data can be transformed automatically to tables. If necessary, the optimization model developer can reformulate the data to populate other data structures during the optimization, but this manipulation must not affect the input or output data.
tupleset
for this output table in your OPL model. For example, this code produces
an output table with 3 columns in the
solution./// solution
tuple TPlannedProduction {
key string productId;
float insideProduction;
float outsideProduction;
}
{TPlannedProduction} plan = {<p.name, Inside[p], Outside[p]> | p in Products};
You can find this example OPL model for a pasta production problem in the Model_Builder folder of the DO-samples. You can download and extract all the samples. Select the relevant product and version subfolder.
Learn more
- For a tutorial on creating Python DOcplex models, see Solving and analyzing a Decision Optimization model: the diet problem.
- For more information about OPL models, see Decision Optimization OPL models.