[FlopCpp] indexing with parameters

Michal Kaut mail at michalkaut.net
Mon Nov 26 06:02:08 EST 2007


Hello,

I have a model based on a tree, with variables indexed by nodes of the 
tree. In some constraints, I need to relate the nodes to their parents, 
i.e. I need to be able write something like x(Parent[NODES]) or 
x(Parent(NODES)) in an MP_expression, where NODES is an MP_set.

I found one solution for balanced trees, i.e. trees where the index of a 
predecessor can be computed as a simple function of the current index. 
For example, for a binary tree I have,
: MP_index_exp get_parent(MP_index &node) {
:     return floor((node-1) / 2);
: }
which allows me to write
: x(get_parent(NODES))
in an MP_expression.
My first question is whether there is a simpler (more elegant) way of 
doing this?

The main problem, however, is what to do in the case of general trees, 
i.e. trees where the parents are given as a data (such as double[][2], 
vector of pairs, MP_data indexed on NODES)?
How do I put "x(Parent[NODES])" to an MP_expression then?


Thanks a lot in advance.

Regards,

Michal Kaut


More information about the FlopCpp mailing list