Why is my model infeasible?
AnsweredHi, I am trying to implement this model, but the model is always infeasible. What is the reason for this?
\(\min \sum_{i\in I} \sum_{d\in D} \sum_{j\in J} C_j\cdot x_{ijd}\)
\(\sum_{j\in J}x_{ijd}=1y_{id}\quad \forall i\in I,d\in D\)
\(\sum_{i\in I}\sum_{j\in J}A_{jt}\cdot x_{ijd}\ge r_{td}\quad \forall t\in T, d\in D\)
\(x_{i6d}+x_{i1(d+1)}\le 1 \quad \forall i\in I, d\in \{1,...,D1\}\)
This is my code:
import gurobipy as gp
from gurobipy import GRB
# Sets and indices
persons = [1, 2, 3, 4, 5, 6]
shifts = [1, 2, 3, 4, 5, 6]
days = [1, 2, 3, 4, 5, 6, 7]
time_intervals = [1, 2, 3, 4, 5, 6]
# Parameters
requirements = {(1, 1): 11, (2, 1): 18, (3, 1): 22, (4, 1): 32, (5, 1): 28, (6, 1): 21,
(1, 2): 11, (2, 2): 18, (3, 2): 22, (4, 2): 32, (5, 2): 28, (6, 2): 21,
(1, 3): 11, (2, 3): 18, (3, 3): 22, (4, 3): 32, (5, 3): 28, (6, 3): 21,
(1, 4): 11, (2, 4): 18, (3, 4): 22, (4, 4): 32, (5, 4): 28, (6, 4): 21,
(1, 5): 11, (2, 5): 18, (3, 5): 22, (4, 5): 32, (5, 5): 28, (6, 5): 21,
(1, 6): 11, (2, 6): 18, (3, 6): 22, (4, 6): 32, (5, 6): 28, (6, 6): 21,
(1, 7): 11, (2, 7): 18, (3, 7): 22, (4, 7): 32, (5, 7): 28, (6, 7): 21}
A = [[1, 1, 0, 0, 0, 0],
[0, 1, 1, 0, 0, 0],
[0, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0],
[0, 0, 0, 0, 1, 1],
[1, 0, 0, 0, 0, 1]]
costs = {1: 145, 2: 100, 3: 80, 4: 95, 5: 110, 6: 150}
# Model
model = gp.Model()
# Decision variables
x = model.addVars(persons, shifts, days, vtype=GRB.BINARY, name="x")
y = model.addVars(persons, days, vtype=GRB.BINARY, name="y")
# Objective function: Minimize costs
model.setObjective(gp.quicksum(gp.quicksum(costs[j] * x[i, j, d] for j in shifts) for i in persons for d in days), GRB.MINIMIZE)
# Constraints
model.addConstrs(gp.quicksum(x[i, j, d] for j in shifts) == 1  y[i, d] for i in persons for d in days)
model.addConstrs(gp.quicksum(A[j1][t1]*x[i, j, d] for i in persons for j in shifts) >= requirements[t, d] for t in time_intervals for d in days)
model.addConstrs(x[i, 6, d] + x[i, 1, d+1] <= 1 for i in persons for d in range(1, 7))
# Solve
model.optimize()
# Optimal solution
if model.status == GRB.OPTIMAL:
print("Optimal assignment:")
for i in persons:
for j in shifts:
for d in days:
if x[i, j, d].x > 0:
print("Person", i, "assigned to shift", j, "on day", d)
print("Total costs:", model.objVal)
else:
print("No solution found.")
0

Hi Nico,
There are KB articles that can guide you on how to determine which subsets of constraints are causing model infeasibility. Please check these articles and follow the instructions.
 How do I use compute IIS to find a subset of constraints that are causing model infeasibility?
 How do I determine why my model is infeasible?
Best regards,
Maliheh
0
Please sign in to leave a comment.
Comments
1 comment