Getting the data elements from an IloOplModel instance

Defines data elements and explains how to access them.

What are data elements?

You cannot directly change the data in a data source. A data source represents what is in a .dat file and the only way to change it would be to modify the .dat file. However, you can ask for another editable view of the data. This other view is referred to as the data elements of the OPL model. These data elements can be modified and then used as a data source for another model.

Using data elements

In the mulprod_main example, you want to get the data from the current model at each successful iteration, modify it, and use it to solve another optimization model.

  1. To get the elements of the IloOplModel instance, write:

    
    var data = produce.dataElements;
    
  2. To reuse the same model definition, write:

    
    var def = produce.modelDefinition;
    
Note:

All the scalar elements that are in the .dat file (string, int, float) are copied whereas complex data such as arrays, sets, and tuples are shared. In other words, scalar data elements are passed by value while nonscalar data is passed by reference.