[gecode-users] Starting with C++

Christian Schulte cschulte at kth.se
Thu Nov 20 08:32:32 CET 2008

I’d keep the design: it makes update explicit and has the advantage that it
can be done outside the intializer list. Quite often, propagators do some
cleanup before they call update on their datastructures.




From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Javier Andrés Mena Zapata
Sent: Wednesday, November 19, 2008 10:29 PM
To: gecode list
Subject: Re: [gecode-users] Starting with C++


Hi Christian,

If one of the reasons, is historical, and supossing you must/want to
reimplement it, then would you implement Gecode using the same design?

If no, then how would you implement it?


On Wed, Nov 19, 2008 at 5:24 AM, Christian Schulte <cschulte at kth.se> wrote:

Hi Malcolm,

all your questions have a yes as the answer. Having the possibility to
construct variables in an uninitialized state is actually quite useful
(think of just declaring an integer variable without initializing, same
thing). It might not useful during copying but in other situations (in
particular think of an array of variables - such as IntVarArgs - you would
like to pass as an argument, here you definitely do not want to create a
variable first and then overwrite it).

The reason why copying an array is not controlled by a copy constructor but
by an update function is for two reasons: one, historical (because in
earlier versions the constructor would have clashed with other constructors)
and the other uniformity (for some data structures it is not very easy to
define a constructor, but it is easy to have a separate update function).


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

-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Malcolm Ryan
Sent: Wednesday, November 19, 2008 5:06 AM
To: gecode list
Subject: [gecode-users] Starting with C++

Given that GecodeJ is no longer supported, I'm in the process of
migrating my code to C++ (and learning C++ in the process).

It seems from my perusal of the examples that the C++ library works
slightly differently. Whereas in java the copy constructors for spaces
look like:

  public Queens(Boolean share, Queens queens) {
    super(share, queens);
    n = queens.n;
    q = new VarArray<IntVar>(this, share, queens.q);

in C++ they look like:

  /// Constructor for cloning \a s
  Queens(bool share, Queens& s) : Example(share,s) {
    q.update(this, share, s.q);

The Java code explicitly contructs a new var array from the old. The C+
+ code seems to implicitly construct an empty var array and then call
'update' to copy the old into the new. Is that correct? Does every
kind of variable have an no-arg constructor? What is the rationale for
this choice? It seems that it allows you to construct variables in an
incompletely initialised state. Is that deliberate?


Gecode users mailing list
users at gecode.org

Gecode users mailing list
users at gecode.org

"La buena educación, es lo que nos queda cuando se nos olvida todo lo que
nos han enseñado"

Javier Andrés Mena Zapata
+57 (2) 318 1000 ext. 2910
Cali - Colombia

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ps.uni-sb.de/pipermail/users/attachments/20081120/d2897134/attachment.htm>

More information about the gecode-users mailing list