[gecode-users] How to iterate over a integer view's domain

Guido Tack tack at ps.uni-sb.de
Fri Apr 4 13:33:34 CEST 2008


Debdeep Banerjee wrote:

> Guido Tack wrote:
>> Debdeep Banerjee wrote:
>>> I want to iterate over the current domain of a integer view
>>> (Gecode::Int::IntView). How can I do that ? Is this domain current ?
>>> I want to implement my own variable and value selection. That's  
>>> why I
>>> need to access the current domain of the variable. Is there any  
>>> good way
>>> to do it ?
>>
>> Yes, using ViewRanges<IntView>:
>> http://www.gecode.org/gecode-doc-latest/classGecode_1_1Int_1_1ViewRanges.html
>>
>
> Is this going to give me the ranges or it will iterate over all values
> in the domain ?
> For example: if the domain of a variable X is Dom(X): 
> {1,4,5,6,9,10,11,15}
> Which output will be given by ViewRanges ?
> Option 1: 4 ranges
>                   R1: 1
>                   R2: 4..6
>                   R3: 9..11
>                   R4: 15

This one.  That's why it's called ViewRanges.

> Option 2: It will iterate through all the values of the domain.

If you need that, use a ViewValues iterator.

> May be it is a silly question, but I don't understand what is the
> advantage of the range.

It potentially needs less memory (you store only the endpoints) and  
less run time.  E.g., computing the intersection of two domains is  
linear in the number of ranges, not values, which can be a huge  
difference.

Cheers,
	Guido





More information about the gecode-users mailing list