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
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
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
Post is closed for comments.
Comments
2 comments