Originally posted by: Mathsg
hi neosenio,
I hope you are enjoying your day. I am facing the same problem as your passing dvar multi dimentional array array from main model to sub model, update it in submodal and then use it again in main model through script part of OPL Cplex. i have see some post on this community platform to declare new array first to store the value of array used in master problem so i have declare the new array with name t and put all elements of lemda in t but still i am getting an error. here is the script of my main code. kindly have a look and guide me in this regards,
main {
var status = 0;
thisOplModel.generate();
var RC_EPS = 1.0e-6;
var masterDef = thisOplModel.modelDefinition;
var masterCplex = cplex;
var masterData = thisOplModel.dataElements;
var subSource = new IloOplModelSource("PP_Jan.mod");
var subDef = new IloOplModelDefinition(subSource);
var subData = new IloOplDataElements();
var subCplex = new IloCplex();
var subOpl = new IloOplModel(subDef, subCplex);
var best;
var curr = Infinity;
while ( best != curr ) {
best = curr;
var masterOpl = new IloOplModel(masterDef, masterCplex);
masterOpl.addDataSource(masterData);
masterOpl.generate();
masterOpl.convertAllIntVars();
writeln("Solve master.");
if ( masterCplex.solve() ) {
curr = masterCplex.getObjValue();
writeln();
writeln("OBJECTIVE: ",curr);
}
else {
writeln("No solution!");
masterOpl.end();
break;
}
//subData.lemda = masterOpl.lemda;
subData.nmbr_routes = masterOpl.nmbr_routes;
subData.nbnodes = masterOpl.nbnodes;
subData.flows = masterOpl.flows;
subData.Lincards = masterOpl.Lincards;
subData.hope_count = masterOpl.hope_count;
subData.link = masterOpl.link;
subData.q = masterOpl.q;
subData.ECcards = masterOpl.ECcards;
subData.Duals = masterOpl.Duals;
for (var i in masterOpl.routes) {
subData.Duals[i] = masterOpl.Const10[i].dual;
}
//var subOpl = new IloOplModel(subDef, subCplex);
subOpl.addDataSource(subData);
subOpl.generate();
writeln("Solve sub.");
if ( subCplex.solve() ) {
writeln();
writeln("OBJECTIVE: ",subCplex.getObjValue());
}
else {
writeln("No solution!");
subOpl.end();
masterOpl.end();
break;
}
if (subCplex.getObjValue() >-RC_EPS) {
subOpl.end();
masterOpl.end();
break;
}
// Prepare the next iteration:
//masterData.routes.add(masterData.routes.size,1,subOpl.getObjValue());
var t = new Array();
for (var i in thisOplModel.flows){
t[i] = new Array();
for ( var j in thisOplModel.routes){
t[i][j] = new Array();
for (var u in thisOplModel.nodes){
t[i][j][u] = new Array();
for (var v in thisOplModel.nodes){
t[i][j][u][v] = new Array();
t[i][j][u][v] = 0;
}}}}
for (j in thisOplModel.routes){
for (u in thisOplModel.nodes){
for (v in thisOplModel.nodes){
for (v in thisOplModel.nodes){
t[i][j][u][v] = masterOpl.lemda[i][j][u][v];
masterData = t[i][j][u][v];
// masterData = t[i][j][u][v];
//masterOpl.addDataSource(z[i][j][u][v]);
}
}
}
}
writeln("Master pattern before +++ : \n ",masterData.t[1][1][1][1]);
for ( var j in subOpl.routes){
masterData.t[1][j][1][1].add(masterData.t[1][j][1][1],size,1,subOpl.lemda[Opl.first(masterOpl.flows)][j][1][1].solutionValue); // Here i am geeting an error
// (subOpl.f[Opl.first(subOpl.Lincards)][j][1][1].solutionValue);
}
//masterData.routes.add(subOpl.getObjValue());
subOpl.end();
masterOpl.end();
}
writeln("Relaxed model search end.");
masterOpl = new IloOplModel(masterDef,masterCplex);
masterOpl.addDataSource(masterData);
masterOpl.generate();
writeln("Solve integer master.");
if ( masterCplex.solve() ) {
writeln();
writeln("OBJECTIVE: ",masterCplex.getObjValue());
if (Math.abs(masterCplex.getObjValue() - 122)>=0.0001) {
writeln("Unexpected objective value");
status = -1;
}
/*for(i in masterData.Patterns) {
if (masterOpl.Cut[i].solutionValue > 0) {
writeln("Pattern : ", i, " used ", masterOpl.Cut[i].solutionValue << " times");
}
}*/
}
masterOpl.end();
status;
}
your help will be highly appricated and i am looking forward to hearing from you. thank you
#DecisionOptimization#OPLusingCPLEXOptimizer