[gecode-users] customize IntVar

Christian Schulte cschulte at kth.se
Fri Apr 15 10:14:55 CEST 2011


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: users-bounces at gecode.org [mailto:users-bounces at gecode.org] 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 <changbin.liu at gmail.com>

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
users at gecode.org
https://www.gecode.org/mailman/listinfo/gecode-users




-- 
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20110415/e6eab484/attachment.htm>


More information about the users mailing list