[gecode-users] posting constraints for assigned variable

Guido Tack tack at ps.uni-sb.de
Sun Apr 20 20:18:55 CEST 2008


Hi!

I'm not sure I understand your syntax.  Is this C++, do you e.g. mean  
Gecode::me_failed?  Assuming that this is the case, let's have a look  
at your questions.

Debdeep Banerjee wrote:

> hi,
> I have some questions about reducing domain of a variable. Say I  
> have a
> IntVar x and its domain is IntSet {1,2,5,6,-2}
> q1. if I want say x != 2 then I use the following code
>       IntView v(x)
>       Gecode.me_failed( v.nq( home, 2 ) ) ==> this should return  
> true/1
>     Is this correct ?

No, it should return false.  The semantics of nq is the following (in  
pseudo code):

nq(int i):
	domain := domain - {i}
	if domain is empty return false else return true

The domain contains 2, and after you say v.nq(home,2), it does not  
contain 2 any more, but there are other values left, so the operation  
does not result in failure.

> q2. Say x is already assigned to 5, ie
>    IntView v(x) and v.assigned() == true.
>      What will happen if I try to do the following
>    Gecode.me_failed( v.nq( home, 2 ) ) == > what should this code
> return 0 or 1 ??

If you remove a value from a domain that isn't in the domain, the  
operation does not fail, because the resulting domain is not empty.

> q3. Say I want to say x != 9 ( 9 is not in the domain of x)
>       IntView v(x)
>       Gecode.me_failed( v.nq( home, 9 ) ==> what this will return ???
>    Does this depends on whether x is already assigned or not ??

Same as above, if 9 is not in the domain, the operation does not  
fail.  This has nothing to do with whether x is assigned or not.

Finally, in what context are you using these operations?  The fact  
that you wrote IntView v(x) made me think you might be trying this in  
a model.  The operations really should only be used in propagators and  
branchings, definitely not in a model!  Use rel/dom constraint posting  
functions instead.

Cheers,
	Guido





More information about the gecode-users mailing list