Hi,
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). Cheers Christian -- Christian Schulte, Professor of Computer Science, KTH, www.ict.kth.se/~cschulte/ From: users-boun...@gecode.org [mailto:users-boun...@gecode.org] On Behalf Of Farshid Hassani Bijarbooneh Sent: Wednesday, July 03, 2013 10:11 PM To: users@gecode.org Subject: [gecode-users] Construct a variables of a model with variables from another model Hi, 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 ( <file:///\\Users\farshidhassanibijarbooneh\Downloads\gecode-doc-4.0.0\classG ecode_1_1Space.html> Space &home, const <file:///\\Users\farshidhassanibijarbooneh\Downloads\gecode-doc-4.0.0\classG ecode_1_1IntVarArgs.html> IntVarArgs & <file:///\\Users\farshidhassanibijarbooneh\Downloads\gecode-doc-4.0.0\set-ex 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, Farshid
_______________________________________________ Gecode users mailing list users@gecode.org https://www.gecode.org/mailman/listinfo/gecode-users