Infeasibility of model due to new constraints
回答済みWhen I add certain constraints, my model shows infeasibility.
Initial Model
import gurobipy as gp
from gurobipy import GRB
# Input data
plants = ['Plant1', 'Plant2', 'Plant3']
warehouses = ['Warehouse1', 'Warehouse2']
transport_cost = {
('Plant1', 'Warehouse1'): 10,
('Plant1', 'Warehouse2'): 15,
('Plant2', 'Warehouse1'): 20,
('Plant2', 'Warehouse2'): 25,
('Plant3', 'Warehouse1'): 30,
('Plant3', 'Warehouse2'): 35
}
discounts = {
'Plant1': {
(0, 100): 0.9,
(101, float('inf')): 0.8
},
'Plant2': {
(0, 50): 0.95,
(51, float('inf')): 0.85
},
'Plant3': {
(0, 75): 0.92,
(76, float('inf')): 0.82
}
}
plant_volumes = {
'Plant1': 80,
'Plant2': 120, # Adjusted volume value outside the defined range
'Plant3': 90
}
warehouse_demands = {
'Warehouse1': 100,
'Warehouse2': 120
}
# Create model
model = gp.Model('Transportation')
# Create variables
x = model.addVars(plants, warehouses, name='x')
# Set objective
obj = gp.quicksum(
transport_cost[plant, warehouse] * (1 - discount)
* x[plant, warehouse]
for plant in plants
for warehouse in warehouses
for (volume_range, discount) in discounts[plant].items()
if volume_range[0] <= plant_volumes[plant] <= volume_range[1]
)
model.setObjective(obj, GRB.MINIMIZE)
# Add constraints
supply_constraints = {
plant: model.addConstr(gp.quicksum(x[plant, warehouse] for warehouse in warehouses) <= plant_volumes[plant])
for plant in plants
}
demand_constraints = {
warehouse: model.addConstr(gp.quicksum(x[plant, warehouse] for plant in plants) >= warehouse_demands[warehouse])
for warehouse in warehouses
}
# Optimize model
model.optimize()
# Print solution
if model.status == GRB.OPTIMAL:
print('Optimal solution found.')
for plant in plants:
for warehouse in warehouses:
print(f'x[{plant}, {warehouse}] = {x[plant, warehouse].x}')
else:
print('No solution found.')
Now the challenge with this model is it fulfills the demand of a warehouse with multiple plants which is not desired hence introduced 2 new variables which are mentioned below
single_assignment_constraints = {
warehouse: model.addConstr(gp.quicksum(x[plant, warehouse] for plant in plants) == 1,name='singleflag')
for warehouse in warehouses
}
warehouse_assignment_constraints = {
warehouse: model.addConstr(gp.quicksum(x[plant, warehouse] for plant in plants) <= y[plant] * plant_volumes[plant],name='assignment')
for warehouse in warehouses
for plant in plants
}
The moment I do this, the result becomes infeasible in though the demand is below the supply and warehouse capacities.
So i ran IIS with below result but not able to pinpoint the problem
IIS computed: 2 constraints, 0 bounds
IIS runtime: 0.02 seconds (0.00 work units)
Constraints in the Irreducible Inconsistent Subsystem (IIS):
demand singleflag
0
-
Your issue is not reproducible because variable \(\texttt{y[plant]}\) is not defined.
After computing the IIS, you can write it to a file
model.write(iis.ilp)
and open the IIS file \(\texttt{iis.ilp}\) in any standard text editor. You can then analyze the constraints in the IIS and try to find out why they together are infeasible.
You are saying that the 2 constraint found by the IIS algorithm are demand and singleflag
model.addConstr(gp.quicksum(x[plant, warehouse] for plant in plants) >= warehouse_demands[warehouse])
model.addConstr(gp.quicksum(x[plant, warehouse] for plant in plants) == 1These 2 constraint are incompatible because \(\texttt{warehouse_demands[warehouse] > 1}\).
I guess your \(\texttt{y}\) variable is a binary assignment constraint which you wanted to use in the singleflag constraint instead of \(\texttt{x}\).
0
サインインしてコメントを残してください。
コメント
1件のコメント