Arr.sum() - constraint

Hello,

Can someone explain how to interpret when an argument is passed to the arr.sum function?

For example: In this solution to the N-Queen, problem, how to interpret:
queen_b.sum(b) with (i+b.index<N? int’(queen_b[b.index][i+b.index]) : 0) <= 1;

Is “b” considered an iterator?

This constraint is pretty clear (we iterate each row)
queen_b[i].sum() with (int’(item)) == 1;

Would highly appreciate an explanation.

Thanks!

Yes, b is the name of the iterator. If you do not supply a name, item is the default. This gives you the flexibility of declaring a name that is more useful to you, especially when nesting iterators. In this example, since the iterator name is repeated so many times, a shorter name might be more useful.

1 Like