Modifying data from “main” scripting
Data elements can be modified and then used as a data source for another model.
You can access and modify data in the data elements obtained from the current OPL model, as follows:
data.capacity["flour"] = capFlour;
Then, the value of the variable capacity["flour"] is
modified in the structure of the data elements.
Note, however, the following restrictions:
Scalar data, whether in the
.modfile or the.datfile, cannot be modified via scripting.You can use data elements to add new elements, but only for scalar types.
Only external data can be modified by script. If, in the
.modfile, you have, for example:int arr[1..3] = [1,2,3];you cannot modify the array
arr. You need to declare it as:int arr[1..3] = ...;and initialize it externally.
So you would need to create a
.datfile that contains the data to update, except for scalar data. The scalars that need to be updated would not be initialized in the.mod, or in a.dat, but in a new instance ofOplDataElementsthat you can then add as a data source:float maxOfx = ...; . . main { . . var data = new IloOplDataSource("basicmodel.dat"); var opl = new IloOplModel(def,cplex); var data2 = new IloOplDataElements(); data2.maxOfx=11; opl.addDataSource(data); opl.addDataSource(data2); opl.generate(); . . }