As part of a bigger model I have a matrix of variables $x_{ij} \geq 0$ and a "selector" set of variables $y_j \in \{0,1\}, \sum_j y_j = 1$. From $x_{ij}$ I'd like to get the variables of column $j$, where $y_j = 1$, so it's kind of a matrix lookup: $x_{.j}$ with $j = \sum_k k \space y_k$
I'm interested in efficient modelling variants to achieve this. Probably there is not the best variant, as it largely depends on the other parts of the model, so proposals are welcomed.
My approach:
$c_i$: columns of $x_{ij}$ where $y_j = 1$ $$ \forall i: c_i = \sum_j x_{ij} \space y_j $$ As $x_{ij} \space y_j$ is not linear, I introduce substitute $z_{ij} \geq 0$ and $M$ as upper bound on $x_{ij}$ with
$$ 0 \leq z_{ij} \leq x_{ij} \\ x_{ij} - M (1 - y_j) \leq z_{ij} \leq M \space y_j \\ $$ So $c_i = \sum_j z_{ij}$ with the constraints from above. It works, but I wonder if it can be improved. What I don't like (beside Big-M) is that I have to introduce additional variables in the size of $x_{ij}$ plus 3 additional constraints per variable - and in the end I only need $c_i$. The $z_{ij}$ are just "intermediates".