Hi,
let me add here a tiny example on how to do since I am often asked that.
Suppose you want to position m cells on a n*n 2 dimensions board.
You have 2 goals:
1) Minimize the max x
2) Minimize the max y
You may do that by using weights. Weights should be computed to make one single objective take into account different objectives:
int n=10;
int m=25;
range position = 0..n-1;
dvar boolean x[position][position];
dvar int obj1 in position;
dvar int obj2 in position;
minimize (obj1)*n+obj2;
subject to
{
sum(i,j in position) x[i][j]==m;
forall(i,j in position) (x[i][j]==1) => (obj1>=i);
forall(i,j in position) (x[i][j]==1) => (obj2>=j);
}
tuple sequence_like {
int start;
int end;
string label;
int type;
};
execute
{
writeln("objectives : ",obj1+1," ",obj2+1);
}
{sequence_like} array2[i in position] = {<j-1,j," ",x[i][j]> | j in position};
execute noname {
array2;
}
And then by clicking array2 you may see
But you may also use a main to do the lexicographic goal programming:
int n=10;
int m=25;
range position = 0..n-1;
dvar boolean x[position][position];
dvar int obj1 in position;
dvar int obj2 in position;
minimize (obj1)*n+obj2;
subject to
{
sum(i,j in position) x[i][j]==m;
forall(i,j in position) (x[i][j]==1) => (obj1>=i);
forall(i,j in position) (x[i][j]==1) => (obj2>=j);
}
tuple sequence_like {
int start;
int end;
string label;
int type;
};
execute
{
writeln("objectives : ",obj1+1," ",obj2+1);
}
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();
}
if you turn
int n=10;
int m=25;
into
int n=100;
int m=250;
you may notice that the goal programming version is 4 times faster than the weight aggregated single objective.
regards
#DecisionOptimization