[gecode-users] Space and variables cloning

Christian Schulte schulte at imit.kth.se
Tue Mar 28 16:24:53 CEST 2006


Never use copy! or the constructor! Use the clone method instead (which, in
turn uses the copy method). Please read about clone (it is a member function
of Space). Also, you might want to check how the search engines are done.
They also use clone.

Christian

--
Christian Schulte, http://www.imit.kth.se/~schulte/ 

-----Original Message-----
From: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of jeremie.vautard
Sent: Tuesday, March 28, 2006 4:06 PM
To: users
Subject: [gecode-users] Space and variables cloning


Hi ! 

I created a subclass of Space in which I added two IntVars a and b, which
are instanciated in the default constructor. A linear propagator is also
defined. The constructor for cloning updates these IntVars using the cloned
space members, and the copy method simply use this constructor, like in the
examples. Here is my code : 


class QSpace : public Space {

public :
  IntVar a;
  IntVar b;
  Int::IntView va;
  QSpace() {
    a=IntVar(this,1,4);
    b=IntVar(this,1,4);
    post(this,4*a == 1*b);    
    va=Int::IntView(a);
  }

  QSpace(bool share, QSpace& q) : Space(share,q) {
    a.update(this,share,q.a);
    b.update(this,share,q.b);
  };

  virtual QSpace* copy(bool share) {return new QSpace(share,*this);} };


But, if in my main method, I declare : 
QSpace* qs = new QSpace; 
QSpace* qs2 = new QSpace(false,*qs); ( or qs2=qs->copy(false) ) then,
calling the status method of qs will perfectly work, but I will get a
segmentation fault if I try to get the qs2 status. Removing the a.update and
b.update lines in the constructor for cloning of QSpace gets me rid of this
segmentation fault, but, of course, I can't  get the values of a and b at
all, as they have not been instanciated. 
What am I doing wrong ? 

The point of all this is to be able to have complete access on the variables
of the space in order to search, perform branching, or add new constraints
from outside. So, I need to keep an access to the variables of the cloned
space. Is it possible ?

Jeremie Vautard

Accédez au courrier électronique de La Poste : www.laposte.net ; 
3615 LAPOSTENET (0,34 €/mn) ; tél : 08 92 68 13 50 (0,34€/mn)




_______________________________________________
Gecode users mailing list
users at gecode.org https://www.gecode.org/mailman/listinfo/gecode-users





More information about the gecode-users mailing list