-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakonsel-Problem3.py
132 lines (98 loc) · 2.59 KB
/
Makonsel-Problem3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
# coding: utf-8
# In[21]:
#coefficients and parameters
Production=["Plant1","Plant2"]
Warehouse=["W1","W2"]
Customer=["R1","R2","R3"]
#demand for plant
demand_w={}
demand_w["Plant1"]=225
demand_w["Plant2"]=300
#final demand of retailer
demand={}
demand["R1"]=175
demand["R2"]=200
demand["R3"]=150
#transportation cost from plant to warehouse
cost_w={
("Plant1","W1"):450,
("Plant1","W2"):560,
("Plant2","W1"):510,
("Plant2","W2"):600,
}
#capacity for warehouse
capacity_p={
("Plant1","W1"):125,
("Plant1","W2"):150,
("Plant2","W1"):175,
("Plant2","W2"):200,
}
#transportation cost from warehouse to retailer
cost_r={
("W1","R1"):470,
("W1","R2"):505,
("W1","R3"):495,
("W2","R1"):390,
("W2","R2"):415,
("W2","R3"):440,
}
#capacity for retailer
capacity_w={
("W1","R1"):100,
("W1","R2"):150,
("W1","R3"):100,
("W2","R1"):125,
("W2","R2"):150,
("W2","R3"):75,
}
# In[22]:
from gurobipy import *
model = Model("Makonsel")
#decision variable
X={}
Y={}
for i in Production:
for j in Warehouse:
X[i,j] = model.addVar(vtype=GRB.INTEGER,lb=0,ub=GRB.INFINITY)
for i in Warehouse:
for j in Customer:
Y[i,j] = model.addVar(vtype=GRB.INTEGER,lb=0,ub=GRB.INFINITY)
model.modelSense = GRB.MINIMIZE
model.update()
# In[24]:
#demand constraints
#for plant
for i in Production:
model.addConstr(quicksum(X[i,j] for j in Warehouse)== demand_w[i])
#for customer
for j in Customer:
model.addConstr(quicksum(Y[i,j] for i in Warehouse)== demand[j])
#maximum flow contraints
#for warehouse
for i in Production:
for j in Warehouse:
model.addConstr(X[i,j] <= capacity_p[i,j])
#for customer
for i in Warehouse:
for j in Customer:
model.addConstr(Y[i,j] <= capacity_w[i,j])
# Equilibrium
for j in Warehouse:
model.addConstr(quicksum(X[i,j] for i in Production) - quicksum(Y[j,m] for m in Customer) == 0)
#objective function
objective = quicksum(cost_w[i,j]*X[i,j] for j in Warehouse for i in Production)+ quicksum(cost_r[i,m]*Y[i,m] for m in Customer for i in Warehouse)
model.setObjective(objective)
model.optimize()
# In[25]:
#Printing outputs
if model.status==GRB.OPTIMAL:
print ("Optimal value:", model.objVal)
print ("--- Quantity (Production to Warehouse)---")
for i in Production:
for j in Warehouse:
print ( i, j, X[i,j].x)
print ("--- Quantity (Warehouse to Customers)---")
for i in Warehouse:
for j in Customer:
print (i, j, Y[i,j].x)