Originally posted by: Mathsg
Hi Seniors,
I am using column generation technique to optimize network planning problem. i have decesion boolean variable lemda in my master problem which has one element called route and i am using this route as a input parameter in solving sub problem. First i have relaxed Master problem through 2 k shortest path and then sub problem will generate new paths if any that can improve the solution of master problem. Now i am getting an error in scripting part as i am going to update the master problem for next iteration through scripting part. i have gone through all code but i am unable to locate the problem. First i think i am getting an error due to i did not declear the decesion variable in script then i declear the new array and store the value of lemda in this new array but still i am getting the same error i.e., data element z does not exist. can you help me how to update master problem from sub model for next iteration. attached is the script part of my code
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 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!");
var z = new Array();
for (var i in thisOplModel.flows){
z[i] = new Array();
for ( var j in thisOplModel.routes){
z[i][j] = new Array();
for (var u in thisOplModel.nodes){
z[i][j][u] = new Array();
for (var v in thisOplModel.nodes){
z[i][j][u][v] = new Array();
z[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){
z[i][j][u][v] = masterOpl.lemda[i][j][u][v];
masterData.z[i][j][u][v] = z[i][j][u][v];
masterOpl.addDataSource(z[i][j][u][v]);
}}}}
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());
for ( var j in subOpl.routes){
masterData.z[1][j][1][1].add(masterData.z[1][j][1][1],size+1,subOpl.lemda[Opl.first(subOpl.flows)][j][1][1].solutionValue); //'Here i am getting 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;
}
#DecisionOptimization#OPLusingCPLEXOptimizer