Originally posted by: humbleprogrammer
I am getting different objective values when using CP optimizer and CPLEX to solve the same model.
Below is a small test function that reproduces the problem. When Test(false) is called it uses CPLEX and prints the correct optimal value of 10876, but when Test(true) is called it uses the CP optimizer and prints 10875 which is incorrect.
enum {S, E, N, D, M, O, T, Y};
void Test(bool use_cp) {
IloEnv env;
IloModel mod(env);
IloIntVarArray d(env, Y + 1, 0, 9);
mod.add(d);
IloIntVar money(env, IloIntMin, IloIntMax);
mod.add(money == 10000 * d[M] + 1000 * d[O] + 100 * d[N] + 10 * d[E] + d[Y]);
IloObjective obj(env, money, IloObjective::Maximize);
mod.add(obj);
mod.add(d[S] != 0);
mod.add(d[M] != 0);
mod.add(1000 * d[S] + 100 * d[E] + 10 * d[N] + d[D] +
1000 * d[M] + 100 * d[O] + 10 * d[S] + d[T] == money);
for (int i = S; i <= Y; i++)
for (int j = i + 1; j <= Y; j++)
mod.add(d[i] != d[j]);
//mod.add(IloAllDiff(env, d));
std::auto_ptr<IloAlgorithm> alg(use_cp ?
static_cast<IloAlgorithm*>(new IloSolver(env)) : new IloCplex(env));
alg->extract(mod);
alg->solve();
std::cout << "Obj: " << alg->getValue(obj) << std::endl;
}
Victor
#CPOptimizer#DecisionOptimization