Hi,
if you rely on the solution pools you could use
Replace the solution which has the worst objective
But this won t do exactly what you look for.
Let me give you a complete example.
Suppose you want the 8 best solutions for maximize x+y
You could write
dvar int x in 0..10;
dvar int y in 0..10;
int maxNbSolutions=8;
dvar int nbForbiddenSolutions in 0..0;
dvar int forbidx[1..maxNbSolutions];
dvar int forbidy[1..maxNbSolutions];
maximize x+y;
subject to
{
forall(i in 1..maxNbSolutions) ((forbidx[i]==x) && (forbidy[i]==y))=> (nbForbiddenSolutions<=i-1) ;
}
execute
{
writeln("x=",x," and y=",y);
}
main {
var nbsol=0;
thisOplModel.generate();
while ((1==cplex.solve()) && (nbsol<thisOplModel.maxNbSolutions))
{
thisOplModel.postProcess();
nbsol++;
var tempx=thisOplModel.x.solutionValue;
var tempy=thisOplModel.y.solutionValue;
thisOplModel.nbForbiddenSolutions.UB=nbsol;
thisOplModel.nbForbiddenSolutions.LB=nbsol;
thisOplModel.forbidx[nbsol].UB=tempx;
thisOplModel.forbidx[nbsol].LB=tempx;
thisOplModel.forbidy[nbsol].LB=tempy;
thisOplModel.forbidy[nbsol].UB=tempy;
}
writeln("nb solutions = ",nbsol);
}
which gives
x=10 and y=10
x=10 and y=9
x=9 and y=10
x=8 and y=10
x=9 and y=9
x=10 and y=8
x=8 and y=9
x=7 and y=10
nb solutions = 8
regards
https://www.linkedin.com/pulse/how-opl-alex-fleischer/
#DecisionOptimization#OPLusingCPLEXOptimizer