[gecode-users] question about posting of linear expressions

Guido Tack tack at gecode.org
Fri Jul 9 09:56:46 CEST 2010


Kish Shen wrote:

> Guido Tack wrote:
> 
>>> reif = solver->vBool[b];
>>> ...
>>> reif = post(*solver, c);
>>> ...
> 
> Hi Guido,
> 
> Thanks for pointing this out. After some trial and error, I think I have now know how to work around the problem. The issue appears to be reif is
> on the left hand side of =, and should be a new (uninitialised) BoolVar - not an existing initialised BoolVar like what I was doing.

Yes, post returns a fresh BoolVar, and the assignment overwrites the previous variable (so it usually only makes sense if it's uninitialized).

> After the assignment, reif can then be linked to an existing BoolVar like solver->vBool[b], or an integer value (0 or 1).

Right.  But any linking has to be done by constraints (such as eqv), never by C++ assignment.  In your case, I'd try to reuse the existing BoolVars as much as possible, only creating new variables if it cannot be avoided.  In general, using

post(*solver, tt(eqv(c,b)));

will be more efficient than

BoolVar reif = post(*solver, c);
post(*solver, eqv(reif,b));

If the distinction is just between variable or 0/1 constant, you could simply add two assigned BoolVars to the array (one for 0 and one for 1), so that the posting becomes more uniform.  The post function analyzes the arguments anyway and will post the most efficient propagators (e.g. it won't post reified propagators if the reification is statically 1 or 0).

Cheers,
	Guido

-- 
Guido Tack, http://people.cs.kuleuven.be/~guido.tack/




More information about the users mailing list