Constraint with for loop
AnsweredHello,
I have a lillte probleme and would appreciate your help,
I created a variable X[i,j]
I want to add constraints on X dependently of i,
for example if i equal to 2,3,4 i have a constraint
and if i equal to 1,5,6 i have an other one
Thank you for your help
0
-
Hi Rayan,
Thank you for reaching us again.
You can write concise code when you refer to our 'Python Dictionary Example' page.
And, specifically, you can resolve your issue with 'tuplelist class'.The following is an arbitrary example utilizing the tuplelist class.
import gurobipy as gp
l = gp.tuplelist([(i, j) for i in range(10) for j in range(10)])
m = gp.Model()
x = m.addVars(l, name="x")
m.update()
m.addConstr(x[0, 0] <= gp.quicksum(i + j * x[i, j] for i, j in l.select([2, 3, 5], '*')))
m.addConstr(x[1, 1] <= gp.quicksum(i + j * x[i, j] for i, j in l.select([1, 5, 6], '*')))Feel free to leave comments if you have any further questions.
Best regards,
Chung-Kyun Han0
Please sign in to leave a comment.
Comments
1 comment