[gecode-users] Construct a variables of a model with variables from another model

Christian Schulte cschulte at kth.se
Thu Jul 4 10:20:10 CEST 2013



Your idea does not work: passing an IntVarArgs to an IntVarArray makes a
copy of the array but not of the variables.


What you can do, though, is: (a) create an IntVarArray of the right size and
with variables from Int::Limits::min to Int::Limits::max (b) use a dom
function that can constraint a variable to the domain of some other variable
(this is new in 4.*, check MPG).






Christian Schulte, Professor of Computer Science, KTH,


From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Farshid Hassani Bijarbooneh
Sent: Wednesday, July 03, 2013 10:11 PM
To: users at gecode.org
Subject: [gecode-users] Construct a variables of a model with variables from
another model




I have two Gecode models and in one (say class A) I create variables and I
want the variables in the other class (say class B) be initialised with the
domains of a subset of  variables from class A. This is similar to the
'kakuro.cpp' case study example in MPG with one difference that I want to
initialise those variables in class B to take the exact domain as the
variables passed from class A. I know this is possible by passing an array
of IntSet and a Dom constraint to propagate the domains of the variables in
class B, but I wanted to directly use the constructor of the IntVarArray:

IntVarArray (Space &home, const IntVarArgs &a)

Initialize from integer variable argument array a (copy elements). 


I attached a minimal example 'test.cpp' to demonstrate this problem. In the
attached example class A is called PassVar and class B is called
DistinctTest. The example finds the solutions to the model of class
DistinctTest but it fails at class PassVar by throwing a segmentation fault,
and I don't see why that is the case. If I remove the distinct constraint in
class DistinctTest then both classes can successfully find all the
solutions. According to Gecode reference initialising an IntVarArray with (
ecode_1_1Space.html> Space &home, const
ecode_1_1IntVarArgs.html> IntVarArgs &
pr_8cpp.html#ab4e3456f754f4608a3d7f4c5de43a6a5> a) should only initialise
the new variables by copying the elements, but I think this might not to be
the case here. Can you please have a look at the code and let me know if I'm
doing something wrong here.



Best regards,



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20130704/e32991c3/attachment.html>

More information about the users mailing list