[Gecode] RE: PowerB

Christian Schulte schulte at imit.kth.se
Tue Nov 4 19:02:04 CET 2003


Hej everybody,

[Gabor: I am sending the answer to the gecode list as it might be of general
interest]

And of course my aplogies for delay.

Christian

> I added my first propagator, try examples/power1 and power2. 
> Don't look at the "algorithm", I only care about using the interfaces 
> properly for now.
> I shamelessly copied everything from your code, and then spent 2 days 
> trying to understand what I did :-)
> 
> Questions:
> 0,
> I used the eclipse.org IDE, did it do anything nasty to the 
> source that 
> bothers you? (CR/LFs, tabs to spaces, etc)
> I can try to configure it more, or just ditch it and learn 
> Emacs :-)

As I am using Windows, the sources are mistreated anyway.
 
> 1, If a propagator wants to replace itself with a 
> simpler one, do you use 
> the post functions from the API or create the propagator 
> instance directly? 2, (dual of 1,) Do you put the "first 
> time" smartness into the post functions or the 
> propagator constructors?
> I mean I've seen it in a post function, but was that by design?

YOU CAN'T USE THE POST FUNCTIONS FROM THE API! The reason is that they
actually work on different datastructures for passing arguments.

The right architecture should be as follows:
 1. The API function does preprocessing on the arguments, creates the
appropriate variable arrays to be passed to the propagators proper.
    The last point happens automatically when implicitly casting a IntArgs
to VarArray<IntVar>.
    Then, a propagator-based (maybe a static method) post-method is invoked.

 2. Then the propagator-based post-method decides what is the right
propagtor (typically some appropriate variant) to create.

 3. The propagator constructor does the real job of initializing a
propagator.

Unfortunately, quite often I have combined 2. and 3. This needs to be fixed
eventually.

Now getting back to your real question: Typically, you will go for 3. when
replacing a propgator. You never go for 1. as you don't want to create new
variable arrays (they are just resued for the newly created propagator). So,
in a fixed system you would also have the choice between 2. and 3.

> 3,
> How would you "cast" an IntVar into a BoolVar?
> My propagator wants to replace itself with a reified 
> constraint: 0^b=c  <=>  c=(b==0) 4, (generalisation of 3,) Do 
> you have a short summary or some easy to read code about the 
> relationships of the different types related to domain 
> variables and how 
> to convert between them?
> [Core](Int|Bool)Var ...
> Something tells me a bool is just an int but you exploit knowing it's 
> 0/1 valued statically :-)

You are right, the difference is just in the static type-system.

Hmmm, don't know. What needs to be done is adding an implicit constructor to
BoolVar taking an IntVar as argument. If you like, you can try that. What
will happen is easy: You just create a boolvar (and might even check by
assertions that it satisifies the 0/1 restrictions). Remember it is just a
pointer to a CoreIntVar.

> 5,
> I know this is a stupid question, maybe I just did not sleep 
> enough: I don't understand why doing ceil/floor on integer 
> valued floats works.  
> Looks like the 100dB amplification of Braun noise to me, but 
> I'm just an 
> engineer... ;-)
> I mean it's pot luck whether floor(ln(4.0)/ln(2.0))  is 1 or 
> 2, right? 6, Do you have any preference in unit testing 
> frameworks? Anything against 
> CppUnit?

Yes, might be. But maybe that means you have to resort to exact algorithms
(integer-based) for log (ld). Why ln to start with?





More information about the gecode-users mailing list