[gecode-users] Space and variables cloning

jeremie.vautard jeremie.vautard at laposte.net
Tue Mar 28 16:06:24 CEST 2006


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)







More information about the gecode-users mailing list