Originally posted by: EdKlotz
I think think the solution and objective values are consistent with the model created by your and Daniel's code. For each (p,q) pair, you are expressing the constraint:
* (mat[p][q] >= t[0] AND fmat[p][q] >= t[0])
* OR
* (mat[p][q] <= t[1] AND fmat[p][q] <= t[1])
Furthermore, the upper bounds on t[0] and t[1] are both 255, as seen from the code you sent below:
t.add(IloIntVar(env,0,255));
t.add(IloIntVar(env,0,255));
So, for each OR constraint, we can choose to satisfy the condition
mat[p][q] <= t[1] AND fmat[p][q] <= t[1]
while leaving the corresponding condition on t[0] unsatisfied. This leaves us free to set t[0] to its upper bound of 255. Since the objective is
model.add(IloMaximize(env, t[0]-t[1]));
we then want to set t[1] as small as possible. If the maximum value of mat is 254, and nothing in fmat prevents us from setting t[1] to 254, then the optimal solution to this model is indeed what was reported; t[0] = 255, t[1] = 254, and an objective value of 1.0.
So, it looks to me like CPLEX correctly solves the model given to it, but that model is not quite the one you actually want to solve.
Regarding more general recommendations for troubleshooting this type of unexpected results, I have three recommendations:
-
If possible, try it on a much smaller data set, with the dimensions of the arrays being say 8x8 instead of 256x256.
-
Use the IloCplex::exportModel to export an LP file of the model so you can look at it.
-
Experiment with simplified versions of the model by commenting out subsets of the constraints.
#CPLEXOptimizers#DecisionOptimization