[gecode-users] std::set to Gecode::IntVar conversion - my quick and dirty solution

Grégoire Dooms dooms at info.ucl.ac.be
Thu May 11 15:56:25 CEST 2006


Martin Mann wrote:
> It is not a final solution, because I would like to have a direct 
> conversion from std::set<int> to Gecode::IntVar, but with a 
> Gecode::IntSet step between it is usable.

For a more direct version, do this:

IntVar i(home, Limits::Int::int_min(), Limits::Int::int_max()); // 
creates a -inf,+inf single range
GC_StlSetRangeIterator it(&s);
IntView iv(i); // modifiable wrapper  around Int var implementation
GECODE_ME_FAIL(home, iv.inter(it)); //modify upper bound of var by 
intersecting its ranges with the set iterator
cout << i << endl;

This way, you don't need to create the intermediate IntSet (and the 
intermediate vector as I did because I forgot the std::set was already 
sorted).

Best,
--
Grégoire






More information about the gecode-users mailing list