Thanks Mikael and Christian, I finally realized that generally it is not a good idea to extend IntVar (as suggested by Mikael). It makes life much easier to simply use additional separate data structures to store what users want to add.
On Fri, Apr 15, 2011 at 4:14 AM, Christian Schulte <[email protected]> wrote: > Please read the part V in Modeling and Programming with Gecode. There you > will see that IntVar etc are nothing but read-only interfaces to variable > implementations. And this is what you should extend, not the IntVar class. > > > > Christian > > > > -- > > Christian Schulte, www.ict.kth.se/~cschulte/ > > > > *From:* [email protected] [mailto:[email protected]] *On > Behalf Of *Mikael Zayenz Lagerkvist > *Sent:* Friday, April 15, 2011 6:53 AM > *To:* Changbin Liu > *Cc:* gecode gecode > *Subject:* Re: [gecode-users] customize IntVar > > > > Hi, > > > > In almost all cases it is not a good idea to try to extend the IntVar > classes, and the system is not designed for this to be done. It is much > better to store any additional data that you would like to associate with > the variables in a separate data-structure. > > > > Cheers, > > Mikael > > 2011/4/15 Changbin Liu <[email protected]> > > Hi folks, > > > > I am trying to customize existing class IntVar by adding some more data > member into it. My current way is to subclass from IntVar (say the new class > name is MyIntVar) and write constructors and new member functions to > manipulate the new data. This works well. > > > > However, if I want to use IntVarArray and IntVarArgs to hold MyIntVar, all > MyIntVar elements seems are converted to IntVar. > > > > For example, in the code > > > > MyIntVar myIntVar(*this, 0, 10); > > IntVarArgs intVarArgs; > > intVarArgs << myIntVar; > > > > I observe that intVarArgs[0] is IntVar type. I can not even use > dynamic_cast to cast it to MyIntVar. > > > > If I do it another way by implementing MyIntVarArray and MyIntVarArgs for > MyIntVar following the document "Modeling and Programming with Gecode" (this > corresponds to IntVarArray and IntVarArgs for IntVar), this works well. But > the problem is that constraints posting (e.g. sum, "+") do not work on new > MyIntVarArray and MyIntVarArgs. > > > > Basically, my question is what is the easiest to way to slightly modify > IntVar to adapt to user needs. > > > > Many thanks > -- > -------------------------------------------- > Changbin Liu > Computer & Information Science Department > University of Pennsylvania > Philadelphia, PA > U.S. > > > _______________________________________________ > Gecode users mailing list > [email protected] > https://www.gecode.org/mailman/listinfo/gecode-users > > > > > -- > Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/ > -- -------------------------------------------- Changbin Liu Computer & Information Science Department University of Pennsylvania Philadelphia, PA U.S.
_______________________________________________ Gecode users mailing list [email protected] https://www.gecode.org/mailman/listinfo/gecode-users
