[gecode-users] How to specify a constraint of weighted sum of bool variable array

Guido Tack tack at gecode.org
Mon Jun 27 18:32:57 CEST 2011


On 27 Jun 2011, at 15:41, Dongrui She wrote:

> Hi All,
> 
> I am new to gecode and I have a question about how to model a constraint:
> sum{a_i*b_i}
> 
> where a is an integer variable array and b is a bool variable array.
> Basically I want to constrain the sum of some elements in a.
> 
> It seems that I cannot directly specify such constraint. Right now what I can
> think of is to use channel constraint to create an integer array with the same
> value as b and use it to specify the constraint I want.
> 
> Is this the right way to go?

You could do that, but I suspect it would be more efficient to introduce temporary integer variables c_i such that
b -> c_i = a_i
and
!b -> c_i = 0

and then use the sum of the c_i.

Cheers,
	Guido

-- 
Guido Tack, http://people.cs.kuleuven.be/~guido.tack/




More information about the users mailing list