# How to simplify the following constraints as I'm using MIP optimization solver in python?

Following is the initial snippet of the code:

# o is the model and x,y are variables and a,w are parameters. (i=1,...p and j=1,...n and k=1,....r)

# ( X_ij,  Y_kj,  W_k,   A_ik)

(o += w[0] *(y[0][0] + y[0][1]) >= xsum (a[i][0]* x[i][0] for i in p) + xsum (a[i][0]* x[i][1] for i in p)

o += w[1] *(y[1][0] + y[1][1]) >= xsum (a[i][1]* x[i][0] for i in p) + xsum (a[i][1]* x[i][1] for i in p)

o += w[2] *(y[2][0] + y[2][1]) >= xsum (a[i][2]* x[i][0] for i in p) + xsum (a[i][2]* x[i][1] for i in p)
#..

#..upto r times

o += w[0] *(y[0][0] + y[0][1] + y[0][2]) >= xsum (a[i][0]* x[i][0] for i in p) + xsum (a[i][0]* x[i][1] for i in p) + xsum (a[i][0]* x[i][2] for i in p)

o += w[1] *(y[1][0] + y[1][1] + y[1][2]) >= xsum (a[i][1]* x[i][0] for i in p) + xsum (a[i][1]* x[i][1] for i in p) + xsum (a[i][1]* x[i][2] for i in p)

o += w[2] *(y[2][0] + y[2][1] + y[2][2]) >= xsum (a[i][2]* x[i][0] for i in p) + xsum (a[i][2]* x[i][1] for i in p) + xsum (a[i][2]* x[i][2] for i in p)


I simplified the above to the following which is correct

for k in r:

o += (w[k] * y[k][0]) >= xsum (a[i][k]* x[i][0] for i in p)
for k in r:

o += (w[k] * (y[k][0]+ y[k][1])) >= xsum (a[i][k]* x[i][1] for i in p)


But i need to simplify further, so, how to simplify further?

I tried this:

for j in n:

for k in r:

o += xsum(w[k] *y[k][j] for j in n) >= xsum (a[i][k]* x[i][j] for i in p)


But it is not correct representation as I got wrong answers.

( Though I didn't explained in detail, hope this might be enough for my issue with simplification of constraints, please reply if needed more details)

• I suggest you edit your question with the mathematical model. Code is harder to read, and it is better to figure out first if this is a modeling issue, or an implementation issue. Jul 14 at 7:51
• Thank you much @Kuifje for suggestion and the response form Walter Sebastian Gilser solves my issue with coding simplification. Jul 14 at 9:04

for j in n: