Originally posted by: OndrejKral
Hi, I have OPL project and I'm getting familiar with Flow Control scripting and I can't deal with this scenario. Data in .dat file are populated from DB by DBRead. I'm using "parametrized" SQL in the following manner: In OPL model (.mod file) I have variable defined as 'string parameter = "parameterValue"'. Then in .dat file I'm using prepare { } block to concatenate string for SQL query: Query = "SELECT * FROM" + parameterValue;. Then I'm using this query in DBRead(db,Query).
Meaning of this was to easily change parameter value in model and then, when running whole project, get different data based on parameter defined in model. (this is also possible with parametric notation of DBRead). So far I was satisfied, but then I wanted to add Flow Control and iterate over set of parameters and run several different optimizations based on current parameter.
Problem is that I don't know how to do that. According OPL documentation, I can only change scalar values in Flow Control in this manner: In .mod I have to define string parameter = ... ; and then in Flow Control I need to create new instance of data elements (data = new IloOplDataElements();) and add scalar value to it (data.parameter = "parameterValue";). Then this data with only one variable add to model with data from .dat file (model.addDataSource(data);)
But when is parameter defined as above, I get OPL error because parameter is not defined in prepare {} phase of my .dat file.
I'll be glad for any help or reaction. Basically I can rework some stuff, but I would like to find solution based on this pattern: Iterate over set of strings (defined or loaded from DB), run multiple CPLEX optimizations based on string value (data for current optimization are fetched from DB based on SQL parametrized by current string value - becauese I have all data in one table and different instance data are separated by value in one column ) and put results somehow togehter (not important).
Thank you, Ondrej.
#DecisionOptimization#OPLusingCPLEXOptimizer