Hi
Let 's start with a tiny example:
suppose you have 10*10 boxes and you want to select 25 boxes (The green ones below) so that first we still have maximum spare down rows and then second maximum spare right columns.
You have several ways to model this with OPL:
1) Use weights within CPLEX
int n=10;
int m=25;
range position = 1..n;
dvar boolean x[position][position];
dvar int obj1 in position;
dvar int obj2 in position;
minimize (obj1-1)*n+obj2;
subject to
{
sum(i,j in position) x[i][j]==m;
obj1==max(i,j in position) i*x[i][j];
obj2==max(i,j in position) j*x[i][j];
}
execute
{
writeln("objectives : ",obj1," ",obj2);
writeln("-----------------------------");
writeln();
for(var i in position)
{
for(j in position) write((x[i][j]==1)?"+":" ");
writeln();
}
}
2) Use flow control to solve with the first objective and then the second objective while freezing the first one (Goal programming):
int n=10;
int m=25;
range position = 1..n;
dvar boolean x[position][position];
dvar int obj1 in position;
dvar int obj2 in position;
minimize (obj1-1)*n+obj2;
subject to
{
sum(i,j in position) x[i][j]==m;
obj1==max(i,j in position) i*x[i][j];
obj2==max(i,j in position) j*x[i][j];
}
execute
{
writeln("objectives : ",obj1," ",obj2);
writeln("-----------------------------");
writeln();
for(var i in position)
{
for(j in position) write((x[i][j]==1)?"+":" ");
writeln();
}
}
main
{
thisOplModel.generate();
cplex.setObjCoef(thisOplModel.obj2,0);
cplex.solve();
thisOplModel.postProcess();
var obj1=thisOplModel.obj1.solutionValue;
thisOplModel.obj1.LB=obj1;
thisOplModel.obj1.UB=obj1;
cplex.setObjCoef(thisOplModel.obj2,1);
cplex.solve();
thisOplModel.postProcess();
}
3) Use the built in lexicographic objective within CPO:
using CP;
int n=10;
int m=25;
range position = 1..n;
dvar boolean x[position][position];
dvar int obj1 in position;
dvar int obj2 in position;
minimize staticLex(obj1,obj2);
subject to
{
sum(i,j in position) x[i][j]==m;
obj1==max(i,j in position) i*x[i][j];
obj2==max(i,j in position) j*x[i][j];
}
execute
{
writeln("objectives : ",obj1," ",obj2);
writeln("-----------------------------");
writeln();
for(var i in position)
{
for(j in position) write((x[i][j]==1)?"+":" ");
writeln();
}
}
regards
#DecisionOptimization#OPLusingCPLEXOptimizer