```
range D = 1..10000; range R = 1..100; dvar
```**
int** x[r in R] in D; subject to
{ c: forall(d in D) count(all(r in R) x[r], d) <= 1;
}

To me, using

```
c: forall(d in D) sum(r in R) (x[r] == d) <= 1;
```

Is completely equivalent here. Indeed, the semantic of "counting" and "summing" seem to be exactly the same. Which is more efficient between count and sum? How does the solving engine handle them at a lower level?

Both the versions of this model post

*10000*constraints, and in general, the number of constraints raises as the domain of

*x*gets larger.

However, there is what I think is a more efficient solution:

```
c: allDifferent(all(r in R) x[r]);
```

Again, my conjecture supposes that within CP/CPLEX the

*allDifferent*constraint isn't simply translated into its equivalent formulation using sum/count, but I couldn't find any information about this details in the ILOG guide.

What if now we want to state that at most

*k*variables in

*x*should have the same value? The only thing that came into my mind is stating the constraint in the inefficient way using either sum or count:

```
c: forall(d in D) sum(r in R) (x[r] == d) <= k;
```

```
c: forall(d in D) count(all(r in R) x[r], d) <= k;
```

However, in the CP theory there exists a generalization of the allDifferent constraint known as Global Cardinality Constraint, or GCC (see for instance Decompositions of All Different, Global Cardinality and Related Constraints, p.421). The constraint GCC(x1..xn, l1..ln, u1..un) states that the value of

*xi*should occur in

*x*at least

*li*and at most

*ui*times. In this way, I could write something like

```
c: gcc(all(r in R), x[r], all(r in R) k[r], all(r in R) k[r]);
```

or even, having defined

*k*as an integer

```
c: gcc(all(r in R), x[r], k, k);
```

Are global cardinality constraints somehow supported in OPL?

Regards,

Stefano