Hi
let me adapt https://www.ibm.com/developerworks/community/forums/html/topic?id=471cc451-9dc2-44d8-a0e9-5f146fb14765&ps=25
to CPO
sub.mod
using CP;
int maxOfx = ...;
dvar int x;
dvar int y;
maximize y;
subject to {
ct:x<=maxOfx;
y==2*x;
}
execute
{
writeln("x= ",x);
writeln("y= ",y);
}
sub2.mod
using CP;
int maxOfx = ...;
dvar int x;
dvar int y;
maximize y;
subject to {
ct:x<=maxOfx;
y==3*x;
}
execute
{
writeln("x= ",x);
writeln("y= ",y);
}
and then
main {
var source1 = new IloOplModelSource("sub.mod");
var cp = new IloCP();
var def1 = new IloOplModelDefinition(source1);
var opl1 = new IloOplModel(def1,cp);
var data1= new IloOplDataElements();
data1.maxOfx=5;
opl1.addDataSource(data1);
opl1.generate();
if (cp.solve()) {
writeln("OBJ = " + cp.getObjValue());
opl1.postProcess();
} else {
writeln("No solution");
}
var source2 = new IloOplModelSource("sub2.mod");
var cp = new IloCP();
var def2 = new IloOplModelDefinition(source2);
var opl2 = new IloOplModel(def2,cp);
var data2= new IloOplDataElements();
data2.maxOfx=opl1.y.solutionValue; // transfer solution of model1 to input for model2
opl2.addDataSource(data2);
opl2.generate();
if (cp.solve()) {
writeln("OBJ = " + cp.getObjValue());
opl2.postProcess();
} else {
writeln("No solution");
}
opl1.end();
opl2.end();
}
gives
OBJ = 10
x= 5
y= 10
OBJ = 30
x= 10
y= 30
sub.mod multiplies 5 by 2 and gives 10 which is the input for sub2.mod that will multiply 10 by 3
regards
#DecisionOptimization#OPLusingCPOptimizer