[gecode-users] Computing Variable Domains

Guido Tack tack at gecode.org
Fri Aug 10 06:44:17 CEST 2012


Hi,

here's some code that will do what you want:

      Iter::Ranges::Singleton si00(6,Int::Limits::max);
      Iter::Ranges::Singleton si10(Int::Limits::min,9);
      Iter::Ranges::Inter<Iter::Ranges::Singleton,Iter::Ranges::Singleton> 
        inter0(si00,si10);

      Iter::Ranges::Singleton si01(101,Int::Limits::max);
      Iter::Ranges::Singleton si11(Int::Limits::min,104);
      Iter::Ranges::Inter<Iter::Ranges::Singleton,Iter::Ranges::Singleton> 
        inter1(si01,si11);

      Iter::Ranges::Union<
        Iter::Ranges::Inter<Iter::Ranges::Singleton,Iter::Ranges::Singleton>,
        Iter::Ranges::Inter<Iter::Ranges::Singleton,Iter::Ranges::Singleton> > 
        u(inter0,inter1);

      IntVar a(*this,IntSet(u));

You can also use the n-ary variants of the iterators if you need to compute a union or intersection of more than two sets.

Cheers,
Guido

On 08/08/2012, at 9:41 PM, Max Ostrowski <ostrowsk at cs.uni-potsdam.de> wrote:

> Sorry for reposting an old question. I'm just cleaning up my code and noticed that i still not managed to use gecode's functionality to precompute domains of IntVar.
> So, given a constraint "(a>5 /\ a<10) \/ (a>100 /\ a<105)"
> I want to precompute the domain of "a".
> I'm simply not able to find out how the Ranges iterators are used.
> How to i create a range "5..inf" and a range "-inf..10"
> How do i create the intersection of both.
> And finally how to set the domain of IntVar x to this range then.
> 
> 
> I tried to grep the gecode code and the examples but was not able to find any.
> 
> Sorry again for reposting this, i'm ashamed.
> 
> Best,
> Max
> 
> 
> 
> 
> 
> The best is to look for examples in the code ;-) Just grep for it.
> 
> MinMax is nothing but a base-class for other classes and cannot be used 
> directly. Look for the iterators that take arrays as input, they will do what 
> you want.
> 
> Best
> Christian
> 
> --
> Christian Schulte, KTH, web.it.kth.se/~cschulte/
> 
> -----Original Message-----
> From: users-boun... at gecode.org [mailto:users-boun... at gecode.org] On Behalf Of 
> Max Ostrowski
> Sent: Thursday, July 21, 2011 10:49 AM
> To: users at gecode.org
> Subject: [gecode-users] Computing Variable Domains (Integer)
> 
> Hello everybody,
> 
> as variables in gecode need to have a domain, i want to compute the domain of 
> the variables automatically, given the constraints.
> I could also let the constraints restrict the domains of my variables, but as i 
> understood, this is similar to propagation and could take some time.
> There i want to restrict the domain manually for all unary constraints.
> So, given a constraint "(a>5 /\ a<10) \/ (a>100 /\ a<105)"
> the domain should be {6..9,101..104}.
> Therefore i wanted to use some Gecode classes to compute the 
> intersection/union/complement etc.. of the sets.
> Am i right that i can use the Int::Iter::Ranges classes for this?
> And second, how do they work?
> So in this case, i would create a 
> 
> IntSet a1(Gecode::Iter::Ranges::MinMax(5+1,Int::Limits::max));
> IntSet a2(Gecode::Iter::Ranges::MinMax(Int::Limits::min, 10-1));
> 
> And them somehow the intersection of this.
> But i was neither able to initialize a set with a Range, nor to combine Ranges 
> recursively.
> 
> So, how do i do this using the helping classes of gecode.
> 
> Best,
> Max
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20120810/f20995f1/attachment.html>


More information about the users mailing list