Seek help about formulation of the constraints
Awaiting user inputI want to write a MIP solver for the maxpregion problem: https://onlinelibrary.wiley.com/doi/epdf/10.1111/j.14679787.2011.00743.x
I do not know how I can add this constraint (constraint (4) on page 8, where Ni is a set of integers. Could someone please give me a hint about how to write the addConstrs() for this constraint?
0

Hi Yunfan,
I assume you use Python API.
Based on your inputs, I would imagine the following code to work:
import gurobipy as gp
model = gp.Model()
# define K, C, I and x
for k in K:
for c in C:
for i in I:
m.addLConstr(
x[k, c, i] <= gp.quicksum(x[k, c  1, j] for j in N[i]),
name=f"c_{k}_{c}_{i}",
)
# alternatively
m.addConstrs(
(
x[k, c, i] <= gp.quicksum(x[k, c  1, j] for j in N[i])
for k in K
for c in C
for i in I
),
name="c",
)0
Please sign in to leave a comment.
Comments
1 comment