[gecode-users] InVarArray methods

Christian Schulte cschulte at kth.se
Tue Dec 9 11:33:25 CET 2008


Hi,

it works as follows:
 - no variables are kept alive during cloning implicitly.
 - a variable is kept alive during cloning if it is updated explicitly.
 - a variable is updated explicitly if it is stored in a space and is there
updated explicitly, or it is 
   stored in some data structure (such as a IntVarArray) that is explicitly
updated which in turn will 
   explicitly update its fields, or it is used by a propagator or branching
that while being copied also
   while explicitly update the variables they use.

With other words, when you want to use inside your space variables not only
when you initialize the space but also for printing a solution etc, then you
have to keep them alive by yourself. That typically will amount to storing
them in a space directly or storing them in an IntVarArray that is stored in
the space or some other datastructure and update them in the copy function
of a space.

ArgArrays cannot be used to keep variables alive, they only serve as a
temporary datastructure for passing arrays of variables as arguments (for
example, to post a constraint or a branching).

Then, variables are indeed implemented as pointers to variable
implementations but that should be of no concern. Whenever you update a
variable the corresponding variable implementation will be copied if needed
(sometimes some magic is used to actually avoid copying variable
implementations, for example for Boolean variable implementations being
already assigned 0 or 1).

Hope that helps
Christian

--
Christian Schulte, www.ict.kth.se/~cschulte/


-----Original Message-----
From: Patrik Haslum [mailto:patrik.haslum at anu.edu.au] 
Sent: Tuesday, December 09, 2008 11:21 AM
To: Christian Schulte
Cc: 'Julian Cardona'; users at gecode.org
Subject: Re: [gecode-users] InVarArray methods


Hi,
Actually, I'm a bit confused over Var's and VarArrays too. My 
understanding (and please correct me if I'm wrong) is that a Var or 
VarArray (and similarly ArgArrays; not sure what's the difference with 
them) holds only pointers/references to the actual variables, which are 
(in some slightly magic fashion) associated with the space object. Does 
this mean that having all variables in VarArrays that are members of the 
Space-derived object (and doing .updates on them in the copy 
constructor) is in fact not necessary? (execpt if I want to do something 
else with the variables, such as print them after a solution has been 
found). The actual variables (as opposed to the pointers stored in a 
Var/VarArray) would get copied/updated anyway? It seems to work, but I 
haven't found a clear indication either way in the documentation.

Julian, if you want to assign a value to an integer variable (that your 
IntVar holds a reference to), I think you have to do it by posting a 
constraint. For example,

dom(this, X, 4, 4)

would constrain the IntVar X so that 4 <= X <= 4 (here assuming the call 
is made from within a method of the space-derived class; otherwise put a 
pointer to the space instead of "this").

cheers,
			/P at trik


Christian Schulte wrote:
> You can only print fields after they have been initialized.
> 
> If you say "assign values" what do you mean? Assigning variables to fields
> in thne array? Or, assigning values to the variables stored at a fields in
> the array?
> 
> Did you look at the examples that come with Gecode?
> 
> --
> Christian Schulte, www.ict.kth.se/~cschulte/
> 
> 
> -----Original Message-----
> From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
> Of Julian Cardona
> Sent: Monday, December 08, 2008 6:32 PM
> To: users at gecode.org
> Subject: [gecode-users] InVarArray methods
> 
> Hey people i feel very idiot posting this but i have no idea hot to assign

> values to a IntVarArray, i mean, i have an IntVarArray and i can
initialize
> it 
> how it is described in the API but i dont know how to assign arbitrary
> vaules 
> to it.
> I cant figure out why i can print out the value of a desired position:
> std::cout << MyIntVarArray[i] << std::endl;
> but im unable to assign values to it in the common way:
> MyIntVarArray[4] = element;
> 
> Please help me!!!
> 
> 
> 
> 
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
> 
> 
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users






More information about the gecode-users mailing list