I have a scheduling model where each job $p$ requires three operations (with fixed precedence and they must happen in a row) for a fixed number of $i$ service sessions (each session on a specific day). The service duration for operations of job $p$ is equal to $S^1_p$, $S^2_p$, and $S^3_p$. An identical machine $n$ can serve multiple jobs at the same time slot $j$ and day $t$, but not two jobs within their first operations, third operations, and first and third operations. In other words, a machine can handle multiple jobs at the same time within their second operations ($S^2_p$), but only one of jobs can be within their first or third operations:
where $a_{pjti}$ is a binary variable indicating job $p$ starts at time slot $j$ on day $t$ for service session $i$, and $y_{pnti}$ is a binary variable indicating job $p$ is being allocated to machine $n$ on day $t$ for its service session $i$.
I have used these constraints in my MILP model and coded it in python (shown below). However, for large-sized instances, it takes one day to generate each of the above constraint sets (on a powerful computer). Do you have any suggestions on how I can implement these constraints?