[gecode-users] customize IntVar

Mikael Zayenz Lagerkvist zayenz at gmail.com
Fri Apr 15 06:52:43 CEST 2011


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/b4294887/attachment.htm>


More information about the users mailing list