Referencing imported data and defining solution output in a model
For Python DOcplex or OPL models, you can refer to imported data by using the following syntax.
Python models
For Python DOcplex models, the data that you imported in the Prepare data
view in the experiment UI is accessible from the input dictionary. To
access your imported data you must define each table with the following syntax
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']
Similarly, to show tables in the Explore solution view of the experiment UI you must specify them using the syntax
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 model: the diet problem.
OPL models
In an OPL model you must declare a
tupleset
, for each table that you imported in
the Prepare data
view using the same names. The schema for each
tupleset must have 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 = ...;
Similarly if you want to display a table in the Explore solution
view, you must define a
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;
}
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 model: the diet problem.
- For more information about OPL models, see OPL models.