Add Constraint for only some tuples
AnsweredHello,
I wrote the constraint below.
I expect it to add a constraint for only (3, 1), (4, 2), (5, 2), (5, 3) these tuples.
But instead, it adds the same constraint for whole taskFS tuple list.
How can I fix this problem?
Thanks,
Ozlem
setLag = (3,4,5)
taskFS = gp.tuplelist([(2, 1),
(3, 1),
(4, 2),
(5, 2), (5, 3),
(6, 3),
(7, 5),
(8, 5), (8, 6),
(9, 6),
(10, 7), (10, 8), (10, 9),
(12, 10), (12, 11)])
startTimeFSLag = m.addConstrs((s[t] >= c[j] + lag[t] for t in setLag for (t, j) in taskFS), name="startTimeFSLag")
0
-
Official comment
This post is more than three 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 why not try our AI Gurobot?. -
Hi Ozlem,
To implement this restriction, you can just put an if-condition into the list comprehension:
only = [(3, 1), (4, 2), (5, 2), (5, 3)]
startTimeFSLag = m.addConstrs(
(s[t] >= c[j] + lag[t] for t in setLag for (t, j) in taskFS if (t, j) in only),
name="startTimeFSLag",
)Cheers,
Matthias0
Post is closed for comments.
Comments
2 comments