Originally posted by: **gustavgans123**

Hi Alex,

thanks for this thread & the example. Unfortunately I am not able to adapt the example to my problem / model.

I would like to use main {} to run my Model several times, each time with a different inputs for U[i in NW] = [x,x,x] each time, the obj. value and the values for my decision variables should be safed in an excel file.

I need to change the input values by hand, as it is not something like x+i for each run. I would like to to 12 runs, which means 12 different input arrays of "U" and 12 different results.

Could someone help to adapt the example to my model?

All files attached. So far main.mod:

main{

var source = new IloOplModelSource("Opt_Final.mod");

var cplex = new IloCplex();

var def = new IloOplModelDefinition(source);

var opl = new IloOplModel(def,cplex);

var data = new IloOplDataSource("Opt_data.dat");

opl.addDataSource(data);

opl.generate();

if (cplex.solve()) {

curr = cplex.getObjValue();

writeln();

writeln("OBJECTIVE: ",curr);

}

else {

writeln("No solution");

}

var data2 = new IloOplDataSource("Opt_data.dat");

var opl2 = new IloOplModel(def,cplex);

opl2.addDataSource(data2);

opl2.dataElements.U.add(12,12,12); // new array of U for 2nd run

opl2.generate();

if (cplex.solve()) {

curr = cplex.getObjValue();

writeln();

writeln("OBJECTIVE: ",curr);

}

else {

writeln("No solution");

}

opl.end();

opl2.end();

data.end();

def.end();

cplex.end();

source.end();

}

For e.g. 12 runs, would I need to write the blocks 12 times?: opl.2generate, opl3.generate,...,opl12.generate

Or can I pre define the 12 input arrays somewhere and the model always runs with the next array.

In short: run my model e.g. 12 times with different input values for U, each time saving the objective value and the values for the decision variables

Any help is greatly appreciated!

BR

gustav

ps: I checked the other related threads, but did not manage to adapt to my model...:/