IloInt choose(IloCP cp, IloIntVarArray vars) {
   IloNum best = IloInfinity;
   IloInt bestIndex = -1;
   IloInt n = vars.getSize();
   for (IloInt i = 0; i < n; i++) {
     if (!cp.isFixed(vars[i])) {
       IloNum c = CalcCentroid(cp, vars[i]);
       if (c < best) {
         best = c;
         bestIndex = i;
       }
     }
   }
   return bestIndex;
 }
void wqueens(IloEnv& env, IloModel& model, IloIntVarArray& vars)
{
    cout << "Add 3 hard AllDiff constraints for the Queens problem." << endl;

    model.add(vars); // ensure vars are the main decision variables

    int nqueen = vars.getSize();

    IloIntVarArray vars1(env, nqueen, -2 * nqueen, 2 * nqueen);
    IloIntVarArray vars2(env, nqueen, -2 * nqueen, 2 * nqueen);

    for (IloInt i = 0; i < nqueen; i++) {
        model.add(vars1[i] == vars[i] + i);
        model.add(vars2[i] == vars[i] - i);
    }

    model.add(IloAllDiff(env, vars));
    model.add(IloAllDiff(env, vars1));
    model.add(IloAllDiff(env, vars2));
}
void quasi(IloEnv& env, IloModel& model, IloIntVarArray& vars)
{
    int n = sqrt((double)vars.getSize());
    cout << "Add " << n * 2 << " hard AllDiff constraints for the \"homogeneous\" QuasiGroup problem." << endl;
    for (int i = 0; i < n; i++) {
        int pos = i * n;
        IloIntVarArray vars1(env, n);
        for (int j = 0; j < n; j++) {
            vars1[j] = vars[pos];
            pos++;
        }
        model.add(IloAllDiff(env, vars1));
    }
    for (int j = 0; j < n; j++) {
        int pos = j;
        IloIntVarArray vars1(env, n);
        for (int i = 0; i < n; i++) {
            vars1[i] = vars[pos];
            pos += n;
        }
        model.add(IloAllDiff(env, vars1));
    }
}