[gecode-users] Initializing domain of IntegerVars

Guido Tack tack at gecode.org
Mon Jul 18 10:37:32 CEST 2011


On 18 Jul 2011, at 10:21, Max Ostrowski wrote:

> Hello,
> 
> currently i have to create some IntegerVariables and some constraints, and i'm doing this using the IntVar/2 constructor, restricting the variables domain.
> 
> Due to some design decisions it could be necessary to change this to something like:
> 
> IntVar x(*this, MIN_INT,MAX_INT);

You should use Gecode::Int::Limits::min and ::max here (otherwise you'll get an exception).

> dom(*this, x,2,12);
> or worse
> BoolVar a,b;
> dom(*this, x,2,12, a);
> dom(*this, x,24,42, b);
> rel(*this, a, BOT_OR, b, 1).
> 
> 
> Afterwards i will do post further constraints and do search.
> Is this bad in terms of performance, and if, why.

In some cases it may lead to less efficient propagators being posted (e.g. linear equation propagators exist in different versions depending on the variable domains).  In the case of the BOT_OR, it may be even worse if you search the x variables before the Boolean variables, because search will try everything in min..max instead of just the two possible sets of values (see below).

> (I can understand that i have to post the dom constraint first, because sending a constraint already does some propagation.

Yes, dom constraints have an immediate effect.

> Furthermore: does the second variant (with the BOT_OR) also restrict the domain of the variable?)

No, it doesn't (it would require something called constructive disjunction, which the BOT_OR constraint in Gecode cannot do).  In this case you'll have to preprocess your input data yourself to determine the smallest possible domains.

Cheers,
Guido

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








More information about the users mailing list