cplexopl

Why does cplex return a solution which doesn't meet the constraints?


int n=6;
int a[1..n] = [12,0,10,4,10,8];

dvar int x in 0..1;

maximize x;
subject to
{
    forall(i,j in 1..n)
        (i!=j && a[i]==a[j]) => x==0;
}

Since there is a duplicate inside the array a, x should be 0 but cplex returns 1, why?


Solution

  • you have found a bug, involving indicator constraints and conjunctions. A workaround is to replace the conjunction by the keyword "ordered" in the forall:

        forall(ordered i,j in 1..n) {
            (a[i]==a[j]) => x==0;
        }
    

    Another workaround is to use "if" instead of "=>" :

        forall(i,j in 1..n) {
            if (i!=j && a[i]==a[j]) x==0;
        }
    

    We will get in touch with the OPL dev team who will investigate and improve in a next release.