0
$\begingroup$

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)

$\endgroup$
2
  • 4
    $\begingroup$ 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. $\endgroup$
    – Kuifje
    Jul 14 at 7:51
  • $\begingroup$ Thank you much @Kuifje for suggestion and the response form Walter Sebastian Gilser solves my issue with coding simplification. $\endgroup$
    – Deepan
    Jul 14 at 9:04
2
$\begingroup$

Your question isn't entirely clear and isn't really an OR question, but I think what you are trying to do is the following:

for j in n:
    for k in r:
        o += xsum(w[k] *y[k][jj] for jj in n if jj <= j) >= xsum (a[i][k]* x[i][j] for i in p)
$\endgroup$
1
  • $\begingroup$ Yes, this solves my requirement. Thank you very much for timely response. $\endgroup$
    – Deepan
    Jul 14 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.