[gecode-users] iterating/filtering IntView
Christian Schulte
cschulte at kth.se
Tue May 15 10:04:57 CEST 2007
Just some additions to what Guido and Mikael said.
1. As you are in a propagator, you are talking about views - say of type
View - so you should use
ViewValues<View> to iterate over the values.
2. The most efficient version is to create an iterator class that produces
the values you want
to have for x1:
- constructor: creates an iterator i for x1
- operator(), test whether iterator is done: check whether i is done
- operator++, move to next value:
do
++i;
while (i() && !my_predicate(x0.val(),i.val()));
- value access val(): just return i.val();
3. Then turn the value iterator from above into a range iterator with
Iter::Values::ToRanges, let's call it r
4. Then tell that the values of x1 must be r:
x1.narrow(home,r);
Note, that this is safe: narrow has acopying semantics: it first
reads all of r (depending on x1)
and only then updates the domain of x1.
For an example see gecode/int/element/int.icc or just grep for
Values::ToRanges
Christian
--
Christian Schulte, http://www.imit.kth.se/~schulte/
-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Kilian Sprotte
Sent: Monday, May 14, 2007 8:16 PM
To: users at gecode.org
Subject: [gecode-users] iterating/filtering IntView
Hi,
I am inside a propagate method of a binary propagator... :)
At some point, I know that x0 is assigned. What I would like to do is
to filter the domain of x1 using a given predicate function.
if (x0.assigned()) {
IntVarValues r1(x1);
while (r1()) {
if (!my_predicate(x0.val(), r1.val()))
GECODE_ME_CHECK(x1.nq(home, r1.val()))
++r1;
}
return ES_SUBSUMED;
It does not seem to be a good idea however to alter the view x1 while
iterating over it...(is it true that this should not be done/will
cause problems?)
Hhm, could anyone give me a hint, what I could use in order to do
this safely?
Thanks a lot,
Kilian
_______________________________________________
Gecode users mailing list
users at gecode.org https://www.gecode.org/mailman/listinfo/gecode-users
More information about the gecode-users
mailing list