[gecode-users] Add constraints to Flatzinc sharing parameters between them

Guido Tack tack at gecode.org
Wed Sep 26 01:34:06 CEST 2012


Hi Andrea,

there's currently no sharing between arrays (i.e., a new AST::Array object is created for each invocation), and it's probably coincidental that s_array is the same between invocations.  The reason for this is the very simple memory management model for AST objects.
Do you already have a problem just posting the constraints because FlatZinc/Gecode creates the duplicate arrays, or are you mainly worried about solver performance?  If it's the latter, you could create a global hash table mapping AST::Arrays to IntSharedArrays in your registry post function.

Cheers,
Guido

On 25/09/2012, at 8:09 PM, Andrea Pretto <a.pretto at miriade.it> wrote:

> Hi,
> 
> I'm trying to add a custom constraint in Flatizinc/Gecode. A simple version is already working. (Yes, I figured out how to modify registry.cpp etc... and yes, I know this is more hacking than extending cause there's no an official way to do that)
> 
> I have the problem of sharing data (parameters) between constraints.
> This is the constraint signature:
> 
> predicate my_con(var int: x, var int: y, array[int] of int: params1, array[int] of int: params2);
> 
> my_con is a constraint between X and Y, parametrized by params1 and params2.
> params1 and params2 are (possibly) large arrays, so I want to share them between different my_con instances:
> 
> There's a clean way to do that ??
> 
> 
> The simplest solution I found was using flatzinc parameters, but I have some problems.
> 
> % flatzinc file
> array [1..many many] of int: p1;
> array [1..many many] of int: p2;
> 
> ...
> 
> my_con(x, y, p1, p2)
> ...
> my_con(z, w, p1, p2)
> %
> 
> The flatzinc file above should resolve the problem alone, because the parameter arrays should be shared.
> This is a snippet of the function in registry.cpp that receives the constraint declaration.
> 
> void p_my_con(FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
>       ...
>       AST::Array* s_array = ce[2]->getArray();
>       AST::Array* e_array = ce[3]->getArray();
> 
>       std::cout << "SA " << s_array << std::endl;
>       std::cout << "SE " << e_array << std::endl;
>       ...
> }
> 
> Now the output shows me that s_array pointer is the same between invocation, but e_array is not, so it's like the second parameter array is copied every time.
> 
> I don't know if this is a bug or not.
> However the main question is how to share data between multiple constraints.
> 
> Any help is appreciated.
> 
> Cheers.
>  
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users




More information about the users mailing list