/**
   * Detect different equalities cliques.
   *
   * @param matrix matrix of equalities
   * @param nbIntVars nb of IntegerVariable within the model
   * @param color array of colir, ie nb different variable
   * @param domainByColor list of domain by color.
   * @return nb of different color found
   */
  private int detect(
      final ISparseMatrix matrix,
      final int nbIntVars,
      final int[] color,
      final TIntObjectHashMap<IntegerVariableMerger> domainByColor) {
    int nb = -1;
    IntegerVariableMerger dtmp = new IntegerVariableMerger();
    final Iterator<Long> it = matrix.iterator();
    while (it.hasNext()) {
      final long v = it.next();
      final int i = (int) (v / nbIntVars);
      final int j = (int) (v % nbIntVars);

      if (color[i] == -1) {
        nb++;
        color[i] = nb;
        domainByColor.put(nb, new IntegerVariableMerger(model.getIntVar(i)));
      }
      final IntegerVariableMerger d = domainByColor.get(color[i]);
      // backup
      dtmp.copy(d);
      if (d.intersection(model.getIntVar(j))) {
        color[j] = color[i];
        domainByColor.put(color[i], d);
      } else {
        add(Choco.eq(model.getIntVar(i), model.getIntVar(j)));
        // rollback
        d.copy(dtmp);
        if (color[j] == -1) {
          nb++;
          color[j] = nb;
          domainByColor.put(nb, new IntegerVariableMerger(model.getIntVar(j)));
        }
      }
    }
    return nb;
  }
 /**
  * Merge equal IntegerVariable into a unique one.
  *
  * @param k number of unique variables
  * @param nbIntVars number of integer variable within the model
  * @param color array of indice of unique variables
  * @param domainByColor domain of unique variables
  */
 @Override
 protected void apply(
     final int k,
     final int nbIntVars,
     final int[] color,
     final TIntObjectHashMap<IntegerVariableMerger> domainByColor) {
   final IntDomainVar[] var = new IntDomainVar[k + 1];
   IntegerVariableMerger dtmp;
   IntegerVariable vtmp;
   for (int i = 0; i < nbIntVars; i++) {
     final int col = color[i];
     if (col != -1) {
       final IntegerVariable v = model.getIntVar(i);
       if (var[col] == null) {
         dtmp = domainByColor.get(col);
         vtmp = dtmp.create();
         vtmp.addOptions(dtmp.optionsSet);
         vtmp.findManager(CPModel.properties);
         var[col] = (IntDomainVar) ppsolver.getMod2Sol().readModelVariable(vtmp);
       }
       ppsolver.setVar(v, var[col]);
     }
   }
 }