[gecode-users] About the offset.

Guido Tack tack at ps.uni-sb.de
Fri Mar 28 19:01:27 CET 2008


Juan Carlos wrote:
> I need to use the offset argument in the element propagator.
> But now that no longer exists,I ve been thinking about some ways to  
> achieve the same effect.
>
> 1)
> VarArray array;
> IntVar var1;
> IntVar var2= var1+offset; (using the right propagator of course)
> Int value;
> element(array, var2, value)
>
> 2)
> int offset;
> VarArray a1(the real thing);
> VarArray a2;
> element (a2, var1, value);
> a1[i+offset]=a2[i]; (using the propagator too )
>
>  I cant get  what is the idea of the dummy objects to the array that  
> you  mention in the changelog, Im very curious about that. Would you  
> explain me your idea?.

The dummy objects are the additional dummy variables that you add at  
the beginning of a2.  Your solution 2) (the one with the dummy  
variables) has one clear advantage: you create only one propagator  
instead of two.  That means less memory, and less propagator  
invocations, so it should be more efficient.  The additional variables  
are just present in the root space, they don't even get copied because  
the propagators detects that they're not needed.

One hint: don't create a2 as a VarArray, but as a VarArgArray.  Then  
create one single IntVar dummy, and initialize all elements from  
0..offset-1 with dummy, and the rest with a2[i].  Don't use a  
propagator for equality, but just assign them.  Here's some completely  
untested code:

IntVarArgs a2(a1.size()+offset);
IntVar dummy(this,0,0);
for (int i=0; i<offset; i++) a2[i] = dummy;
for (int i=0; i<a1.size(); i++) a2[i+offset] = a1[i];
element(a2,var1,value);

Cheers,
	Guido





More information about the gecode-users mailing list