1

I have a linear program with the following variables.

X[i, j, k] for i,j,k in range(0,100)
Y[j, k] for j, k in range(0,100)

I am wondering how I can create the following constraint for X and objective function from Y.

Constraint: (creates 100 constraints, 1 for each i)
for i in range(0,100):
    solver.Add( sum( X[i,j,k] for j, k in range(0,100) ) == 1)

Objective:
solver.Minimize(solver.Sum(Y[j, k] for j,k in range(0,100) ))

These work if I am only iterating through j, not j and k. I am wondering if there is a way to iterate through multiple lists on a single line sum. If not, is there a way I can store the LP variables into a variable and then create the constraints/objective by summing those variables together? Or what would be the best approach for this? Thanks

1 Answer 1

0

replace

  for j,k in range(0,100)

by

  for j in range(0,100) for k in range(0,100)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.