Originally posted by: MatthiasP.
Hi,
With the following code, I'm trying to successively solve a master and subproblem in IBM ILOG CPLEX Optimization Studio. The master-problem generates 2 decision variables that I need as integer arrays in the subproblem. When I tried to expand the code to also take into account the generated solutions of the master problem solution pool, I noticed that the these arrays are not updated. I keep on getting the values of the optimal solution and not those of pool solution s.
main
{
var masterDef = thisOplModel.modelDefinition;
var masterCplex = cplex;
var masterData = thisOplModel.dataElements;
var masterOpl = new IloOplModel(masterDef, masterCplex);
masterOpl.addDataSource(masterData);
masterOpl.generate();
var MasterObjective;
var SubObjective;
if (masterCplex.solve() )
{
masterOpl.postProcess();
var subSource = new IloOplModelSource("Submodel.mod");
var subDef = new IloOplModelDefinition(subSource);
var subCplex = new IloCplex();
var subOpl = new IloOplModel(subDef, subCplex);
MasterObjective = masterCplex.getObjValue();
writeln();
writeln("Solve the master problem: ");
writeln("Master objective for the initial solution: ", MasterObjective);
writeln();
var subData = thisOplModel.dataElements;
subData.rx = masterData.rx;
subData.zx = masterData.zx;
subOpl.addDataSource(subData);
subOpl.generate();
if ( subCplex.solve() )
{
subOpl.postProcess();
SubObjective = subCplex.getObjValue();
writeln("Solve the sub problem with: ");
writeln("z[d][k] = ", masterOpl.zx);
writeln("r[k][p] = ", masterOpl.rx);
writeln();
writeln("Sub objective for the initial solution: ", SubObjective);
writeln();
subOpl.end();
subData.end();
if (masterCplex.populate())
{
MasterObjective = masterCplex.getObjValue();
masterOpl.postProcess();
var nrsolutions = cplex.solnPoolNsolns;
for (var s=1; s<nrsolutions; s++)
{
var subSource = new IloOplModelSource("Submodel.mod");
var subDef = new IloOplModelDefinition(subSource);
var subCplex = new IloCplex();
var subOpl = new IloOplModel(subDef, subCplex);
if (masterCplex.getObjValue(s) < MasterObjective + SubObjective)
{
MasterObjective = masterCplex.getObjValue(s);
masterOpl.setPoolSolution(s);
writeln("Solve the master problem: ");
writeln("Master objective for pool solution nr. ", s, ": ", MasterObjective);
writeln();
var subData = thisOplModel.dataElements;
subData.rx = masterOpl.rx;
subData.zx = masterOpl.zx;
subOpl.addDataSource(subData);
subOpl.generate();
if ( subCplex.solve() )
{
writeln("Solve the sub problem with: ");
writeln("z[d][k] = ", masterOpl.zx);
writeln("r[k][p] = ", masterOpl.rx);
subOpl.postProcess();
SubObjective = subCplex.getObjValue();
writeln("Sub objective for pool solution nr. ", s, ": ",SubObjective);
writeln();
subOpl.end();
subData.end();
}
else
{
subOpl.end();
subData.end();
}
}
}
}
}
else
{
writeln("No solution to sub problem!");
subOpl.end();
}
subOpl.end();
}
masterOpl.end();
};
If I had to take a guess, I would think that in
subData.rx = masterOpl.rx;
subData.zx = masterOpl.zx;
masterOpl.xx refers to the values of the optimal solution and not those of the pool solution s? Is there a way to change this code similar to
MasterObjective = masterCplex.getObjValue(s);
to get the rx and zx variables corresponding to solution s?
Ultimately, I would like to be able to evaluate the pool solutions of the master. The rx and zx-variables from pool solutions with an objective smaller than MasterObjective+SubObjective would then be used to solve the corresponding subproblems to look for a joined objective that's smaller than the previous one.
Thanks in advance for any help, I'm kind of new to programming in Cplex.
#DecisionOptimization#OPLusingCPLEXOptimizer