On Mon, Nov 24, 2008 at 2:27 AM, Malcolm Ryan <[EMAIL PROTECTED]> wrote:
> I'm sorry. I still don't completely understand how to us post. Say I
> have a constraint like:
>
> ((X1 == Y1) && (X2 == Y2) && ... && (XN == YN)) --> L > 0
>
> for general 'N'.
>
> What I've got is:
>
>        BoolVar allEqual;
>        BoolVarArgs eq = BoolVarArgs(nRobots);
>        for (int r = 0; r < N; r++) {
>           eq[r] = post(space, ~(X[r] == Y[r]));
>        }
>        rel(space, BOT_AND, noop, allEqual);
>
>        post(space, !allEqual || (L > 0));
>
> But I'm getting compilation errors on both the 'post' lines. What
> should they be? Why?

Assuming that
 a) space is a pointer to a Space
 b) L is an IntVar
 c) X and Y are IntVarArrays och IntVarArgs of length N
 d) N is the same as nRobots
 e) you mean eq instead of noop
the above code compiles fine in gecode-2.2.0 for. There are two errors
however. 1) since you didn't put tt(..) around the expression in the
last post, which means that it just reifies the expression and returns
the variable. It should be
        post(space, tt(!allEqual || (L > 0)));
2) The allEqual-variable will not be initialized. You should write it
        BoolVar allEqual(space, 0, 1);

As a matter of style, in C++ you should write
        BoolVarArgs eq(nRobots);
for automatic variables.

> Finding documentation on 'post' is tricky, since there are so many
> different instances of this function across many files. I'm a bit
> uncomfortable with the fact that sometimes it adds an actual
> constraint and sometimes it just creates a reified BoolVar. How do I
> know which case is which?

While there are a number of versions of post, they are all quite
similar. Versions of the form
    post(Space* home, expression)
will post propagators for the expression, and return the resulting
value. Versions of the form
    post(Space* home, relation)
will post propagators for the relation, but will not return anything.

Cheers,
Mikael

-- 
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/

_______________________________________________
Gecode users mailing list
[EMAIL PROTECTED]
https://www.gecode.org/mailman/listinfo/gecode-users

Reply via email to