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

Andrea Pretto a.pretto at miriade.it
Tue Sep 25 12:09:26 CEST 2012


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20120925/31462faa/attachment.html>


More information about the users mailing list