[gecode-users] question about counting constraint

Alberto Delgado trosky99 at gmail.com
Sun Nov 29 14:49:11 CET 2009


Hi all,

Let's say i have an IntVarArray vars,  an integer value b and an
IntVar car.  According to the documentation,  if i post the
constraint: count(*this,vars,b,IRT_EQ,car),  the variable car will
represent the number of occurrences of b in vars.

Now,  instead of b being an integer value let's assume it's an IntArgs
with all the elements of the domain of variables from vars, and that
car is now an IntVarArray that will represent the number of
occurrences of all values from b in vars.  I wanted to constrain the
occurrences of each value from b in vars according to car,  so i
implemented a for loop and posted a count constraint for each value in
b and variable in car:  count(*this,vars,b[i],IRT_EQ,car[i]).

Then I realized that it is possible to use just one count constraint:
count(*this,vars,car,b),  that should be equivalent to posting a count
constraint for each value in b.

Attached to this email there is an example that reflects what i
described above. When i run the example with line 64 uncommented and
line 67 commented,  this is using a loop to post a count constraint
for each value in b,  the solver finds a solution without failing at
all. If i comment line 64 and uncomment line 67,  posting just one
count constraint,  the solver fails right away.

Did i get wrong the definition of count(*this,vars,car,b) and it is
not equivalent to post a constraint for each value in b?

Thanks in advance,

Alberto
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cc
Type: text/x-c++src
Size: 2133 bytes
Desc: not available
URL: <http://www.gecode.org/pipermail/users/attachments/20091129/ae0bd3bd/attachment.cc>


More information about the users mailing list