# 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 *(y + y) >= xsum (a[i]* x[i] for i in p) + xsum (a[i]* x[i] for i in p)

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

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

#..upto r times

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

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

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


I simplified the above to the following which is correct

for k in r:

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

o += (w[k] * (y[k]+ y[k])) >= xsum (a[i][k]* x[i] 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: