[gecode-users] advice on building interface (with Haskell)

Guido Tack tack at ps.uni-sb.de
Mon Jan 15 09:45:36 CET 2007


Hi.

> Hi, all! I am considering interfacing Haskell with gecode, although  
> I'm
> totally unexperiened with the latter (!). Actually, I have a Mozart/Oz
> background and can see the strong resemblance between the two  
> systems, but
> there are some points that are not quite clear to me. First of all,  
> do you
> think using a simple, fixed subclass of Space instantiating the copy
> methods with something like this:
>
> SimpleSpace(bool share, SimpleSpace &other): Space(share, other) { }
>
> virtual Space* copy(bool share) {
>    return new SimpleSpace(share,*this);
> }
>
> would do the job? I mean: my idea would be to create such objects and
> (indirectly, from Haskell) apply propagator-imposing functions (post,
> etc.) on them. Have you done anything much different for Alice?

As Mikael already pointed out, the Alice interface uses exactly this  
approach.

For a Haskell interface, I'd suggest a slightly different approach,  
though. Instead of actually calling the propagator posting functions  
directly from Haskell, just create a value of some data type that  
represents the problem. Without having thought this fully through, a  
model would be a list of constraints, which in turn would be defined  
in terms of constraint variables. Of course monads might come in  
handy for creation of models.

The advantage of this setup would be that the creation of a model is  
purely functional.

The C/C++ part would then just take that abstract representation,  
create the real Gecode model, solve it, and return the solution as a  
Haskell term. I don't know how exactly the Haskell foreign function  
interface works, but I think something along these lines should be  
doable. In fact, even this operation then is purely functional.

One thing I am not so sure about is how exactly to return the  
solutions. One could make a model a pair of a list of constraints and  
a list of variables, and then make the solver return a list of  
"solution variables" that correspond to the variables of the model.

Cheers,
	Guido

-- 
Guido Tack
Programming Systems Lab, Saarland University, Germany
http://www.ps.uni-sb.de/~tack







More information about the gecode-users mailing list