Is this a valid mathematical model (MILP)? Is it ok to calculate values in one set of constraint and than using it for another in MILP model. Here Z and Y are binary variable.


No, in a mathematical programming model the limits of summation cannot be variables. (In a constraint programming formulation, you can sum a variable number of variables.) One workaround (assuming the $Z_{j,q}$ are nonnegative integers) is the following:


*

*introduce binary variables $x_{1,q},\dots, x_{K_q,q}$, where $K_q$ is the maximum possible value of $\sum_{j=1}^M Z_{j,q}$;

*constrain the new variables so that $x_{k,q}=1 \iff \sum_{j=1}^M Z_{j,q}\ge k$;

*change your second constraint to $\sum_{k=1}^{K_q} Y_{j,k,q}x_{k,q} = 1$; and

*linearize the product in that constraint (which is fairly straightforward if the $Y$ variables are bounded).

