[gecode-users] Extending Integer Variable

Christian Schulte cschulte at kth.se
Sat Apr 5 00:39:55 CEST 2008


Hi Vincent,

the idea of having something extra by default is interesting. But not that
clear to me how it would work (just the though of one extra pointer makes me
shiver, of course). 

Good luck with the experiments
Christian

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


-----Original Message-----
From: Vincent Barichard [mailto:Vincent.Barichard at univ-angers.fr] 
Sent: Friday, April 04, 2008 9:23 AM
To: gecode-users at gecode.org; cschulte at kth.se
Subject: Re: [gecode-users] Extending Integer Variable

Dear Christian,

Thank you very much for your useful information and advices.

My purpose is to design some search algorithms which deal with values and 
domains. In fact, I need at the same time the _min and _max value of the 
variable domain and the _current value that I try to instantiate.
As In Gecode, an instantiation makes the domain to reduce  to a single value

(_min == _max), I need another "int" member to store the _current value 
without reducing the domain.

I am not sure that other people will absolutely need that, but It can be 
usefull to add its own data structure to an existing Gecode variable. Maybe
a 
pointer to an object (NULL by default) given to the constructor. If a user 
wants to deal with this object, he must design a View which tackles the 
object.

As a conclusion, I will follow your advice and do the experiment first :-)

Thank you again,

Cheers,
Vincent

Le jeudi 3 avril 2008, Christian Schulte a écrit :
> Dear Vincent,
>
> let me first elaborate a little bit how Gecode's variables and propagators
> are structured before I actually attempt to give an answer.
>
> Gecode has three important concepts regarding variables:
>  - variables: they are used for modeling, and the only operations they
> provide are good for modeling. In particular,
>    variables to not provide operations to update their domain. Examples
are
> IntVar, BoolVar, etc. Variables are
>    hence provide nothing but an interface to variable implementations
> (actually, variables are implemented as
>    a pointer to variable implementations).
>  - variable implementations: they are the real objects storing the domain
> and which propagators and advisors must be
>    executed when the domain changes. They themselves are constructed in
two
> steps: a domain independent stub that is
>    automatically generated from a simple description (just a few lines).
> The stub is concerned with events, how
>    propagators can be subscribed to, and linking the variable
> implementations to the Gecode kernel etc. The real
>    variable implementation then inherits from the generated stub and adds
> the variable domain and so on.
>  - views: like variables they are nothing but an interface for variable
> implementations. However, views are used
>    by propagators and branching and provide operations to update variable
> domains, subscribe propagators to changes,
>    and so on. More importantly, for the same variable implementation
> several views exist: a MinusView for a variable
>    implementation x, for example, provides an interface that behaves as if
> the operations on the MinusView are executed
>    on -x rather than x. Examples are IntView, BoolView, MinusView,
> OffsetView, ... For more on views there is paper
>    on the Gecode webpage.
>
> Propagators themselves have two parts: a post function and the actual
> propagator. A post function (such as rel, distinct, linear, etc.) is used
> for modeling and hence takes variables as arguments. It then chooses the
> right propagator and the right views (converting variables to views by
> passing the underlying reference to the variable implementation).
>
> Propagators are typically parametric (as templates in C++) with respect to
> the view they are using: for example, the Max propagator is instantiated
> for the max posting function with an IntView whereas it is also
> instantiated with a MinusView for the min posting function.
>
> Sorry for the long blurb, let's move to the answer: as Gecode is designed,
> you can reuse propagators provided that you implement: a variable
> implementation by yourself (that's what you want to do), variables for
them
> (so that you can model), and views for them (so that you can reuse the
> propagators), post functions (because they talk about your variables).
>
> This is a lot of effort! If you want to make something that is used
(rather
> than an experiment), then one could also make views and variables
> parametric wrt the variable implementation used. That is easy but requires
> intimate Gecode knowledge. Then, in principal, one could also make the
post
> functions parametric but this is almost impossible in reality as they
> should provide simple static linkage as they constitute the basic
interface
> to Gecode.
>
> So it really depends on what you want to do. For an experiment, hack the
> variable implementation. For something, first do the experiment ;-)
>
> What do you want to do? Do you think it me be generally useful to be
> included in Gecode anyway?
>
> All the best
> Christian
>
> --
> Christian Schulte, www.ict.kth.se/~cschulte/
>
>
> -----Original Message-----
> From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
> Of Vincent Barichard
> Sent: Wednesday, April 02, 2008 4:08 PM
> To: gecode list
> Subject: [gecode-users] Extending Integer Variable
>
> Hi,
>
> I am trying to extend IntVar in order to use it in my self(-made
> algorithms. I would like to use an unaltered Gecode, but I need to add an
> "int" member in
> the IntVar implementation. I don't want to make my own Integer Variable
> class
> because I also need to use the algorithms designed in Gecode.
> Is there a clean way to extend this class (by inheritance maybe ....) and
> add
> a member without altering Gecode ?
>
> Thank you for your assistance.
> Best regards,
>
> Vincent



-- 
Vincent Barichard        Université d'Angers (LERIA)
Tel: 02 41 73 52 06      Département Informatique
Fax: 02 41 73 50 73      H203





More information about the gecode-users mailing list