-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicking.py
More file actions
248 lines (208 loc) · 10.1 KB
/
Copy pathpicking.py
File metadata and controls
248 lines (208 loc) · 10.1 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
'''
This code is similar to the vehicle routing code with slight modifications in the cost matrix and robot capacity.
For the tsp / vrp formulation visit the tsp / vrp repo.
'''
import numpy as np
from pulp import *
import pandas as pd
class order_picking:
def __init__(self):
pass
def picking(self,items,time_matrix, vehicles,limit):
if (len(items))==2:
return(1, 2*time_matrix.loc[0,1])
if (len(items))==3:
return(1, time_matrix.loc[0,1] + time_matrix.loc[0,2] + time_matrix.loc[0,1] + time_matrix.loc[2,0])
result = []
result_name = []
M=10000
result_df = pd.DataFrame()
row,col = time_matrix.shape
vehicles=vehicles
problem = LpProblem('Warehouse_Picking', LpMinimize)
# Decision variable X & Y for picker route
decisionVariableX = LpVariable.dicts('decisionVariable_X', ((i, j, k) for i in items for j in items for k in range(vehicles)), lowBound=0, upBound=1, cat='Integer')
decisionVariableY = LpVariable.dicts('decisionVariable_y', ((i, k) for i in items for k in range(vehicles)), lowBound=0, upBound=1, cat='Integer')
# subtours elimination
decisionVariableU = LpVariable.dicts('decisionVariable_U', ((i, k) for i in items for k in range(vehicles)), lowBound=0, cat='Integer')
# Decision variable T for picker arrival time
decisionVariableT = LpVariable.dicts('decisionVariable_T', ((i,k) for i in items for k in range(vehicles)), lowBound=0, cat='Float')
# Objective Function
problem += lpSum(decisionVariableT[i, k] for i in items for k in range(vehicles))
for k in range(vehicles):
problem += lpSum(decisionVariableY[i, k] for i in items) <= limit
for i in items:
problem += (decisionVariableX[i,i, k] == 0) # elimination of (1 to 1) route
if i==0:
problem += (decisionVariableT[i, k] == 0) # at node 0 time=0
for i in items:
if (i != 0):
problem += lpSum(decisionVariableY[i, k] for k in range(vehicles)) == 1 # all non-zero nodes are visited once
for k in range(vehicles):
problem += lpSum(decisionVariableX[i, j, k] for j in items)== decisionVariableY[i, k]
problem += lpSum(decisionVariableX[j, i, k] for j in items)== decisionVariableY[i, k]
if (i == 0):
for k in range(vehicles):
problem += lpSum(decisionVariableX[i, j, k] for j in items) <= 1
problem += lpSum(decisionVariableX[j, i, k] for j in items) <= 1
for i in items:
for j in items:
for k in range(vehicles):
if i != j and (j != 0):
problem += decisionVariableT[j, k] >= decisionVariableT[i, k] + time_matrix.iloc[i][j] - M*(1-decisionVariableX[i,j, k]) # Calculating time of arrival at each node
if i != j and (i != 0) and (j != 0):
problem += decisionVariableU[i, k] <= decisionVariableU[j, k] + M * (1 - decisionVariableX[i, j, k])-1 # sub-tour elimination for picker
status = problem.solve(CPLEX_CMD(msg=0))
for var in problem.variables():
if (problem.status == 1):
if (var.value() !=0):
result.append(var.value())
result_name.append(var.name)
result_df['Variable Name'] = result_name
result_df['Variable Value'] = result
# return
return (problem.status, problem.objective.value(), result_df)
def single_order_picking(self, on_hand_dump, time_matrix, items, pick_quantity, veh, cap):
instance_detail = on_hand_dump.copy()
instance_detail['time=0']=0
instance_detail = instance_detail[['time=0','on_hand']]
items.insert(0,0)
pick_quantity.insert(0,0)
on_hand=on_hand_dump.iloc[items]
drop_list =[]
for en,i in enumerate(items):
if on_hand.loc[i,'on_hand']<pick_quantity[en]:
drop_list.append(i)
else:
if (i !=0):
picked_quantity = pick_quantity[en]
on_hand.loc[i,'on_hand'] = on_hand.loc[i,'on_hand'] - picked_quantity
for i in drop_list:
items.remove(i)
sts, obj,det = self.picking(items,time_matrix,veh,cap)
if sts ==1:
on_hand_dump.update(on_hand)
for i in range(100):
instance_detail.iloc[i,-1]=on_hand_dump.iloc[i,-1]
return sts, on_hand_dump
def batch_picking(self, on_hand_dump, time_matrix, item_matrix, veh, cap):
item_list = []
quantity_list = []
for i in item_matrix.keys():
for j in item_matrix[i].keys():
item_list.append(j)
for k in item_matrix[i].values():
quantity_list.append(k)
picking_quantity = pd.DataFrame({'item' : item_list,
'pick_quantity': quantity_list})
picking_quantity = picking_quantity.groupby(['item'], as_index=False).sum()
items = picking_quantity['item']
items = items.to_list()
pick_quantity = picking_quantity['pick_quantity']
pick_quantity = pick_quantity.to_list()
instance_detail = on_hand_dump.copy()
instance_detail['time=0']=0
instance_detail = instance_detail[['time=0','on_hand']]
items.insert(0,0)
pick_quantity.insert(0,0)
on_hand=on_hand_dump.iloc[items]
drop_list =[]
for en,i in enumerate(items):
if on_hand.loc[i,'on_hand']<pick_quantity[en]:
drop_list.append(i)
else:
if (i !=0):
picked_quantity = pick_quantity[en]
on_hand.loc[i,'on_hand'] = on_hand.loc[i,'on_hand'] - picked_quantity
for i in drop_list:
items.remove(i)
sts, obj,det = self.picking(items,time_matrix,veh,cap)
if sts ==1:
on_hand_dump.update(on_hand)
for i in range(100):
instance_detail.iloc[i,-1]=on_hand_dump.iloc[i,-1]
return sts, on_hand_dump
def zone_batch_picking(self, on_hand_dump, time_matrix, zone_matrix, item_matrix, veh, cap):
item_list = []
quantity_list = []
for i in item_matrix.keys():
for j in item_matrix[i].keys():
item_list.append(j)
for k in item_matrix[i].values():
quantity_list.append(k)
picking_quantity = pd.DataFrame({'item' : item_list,
'pick_quantity': quantity_list})
picking_quantity = picking_quantity.groupby(['item'], as_index=False).sum()
items = picking_quantity['item']
items = items.to_list()
pick_quantity = picking_quantity['pick_quantity']
pick_quantity = pick_quantity.to_list()
instance_detail = on_hand_dump.copy()
instance_detail['time=0']=0
instance_detail = instance_detail[['time=0','on_hand']]
on_hand=on_hand_dump.iloc[items]
drop_list =[]
for en,i in enumerate(items):
if on_hand.loc[i,'on_hand']<pick_quantity[en]:
drop_list.append(i)
else:
if (i !=0):
picked_quantity = pick_quantity[en]
on_hand.loc[i,'on_hand'] = on_hand.loc[i,'on_hand'] - picked_quantity
for i in drop_list:
items.remove(i)
zone_pd = pd.DataFrame({'item' : items})
zone_pd = pd.merge(zone_pd, zone_matrix, left_on='item', right_on=zone_matrix.index)
zones = zone_pd['Zone'].unique().tolist()
for i in zones:
picking_quantity = pd.DataFrame()
picking_quantity = zone_pd[zone_pd['Zone'] == i]
items=[]
pick_quantity=[]
items = picking_quantity['item']
items = items.to_list()
items.insert(0,0)
sts, obj,det = self.picking(items,time_matrix,veh,cap)
if sts ==1:
on_hand_dump.update(on_hand)
for i in range(100):
instance_detail.iloc[i,-1]=on_hand_dump.iloc[i,-1]
return sts, on_hand_dump
def wave_batch_picking(self, on_hand_dump, time_matrix, item_matrix, veh, cap):
for i in item_matrix.keys():
item_list = []
quantity_list = []
for j in item_matrix[i].keys():
for k in item_matrix[i][j].keys():
item_list.append(k)
for l in item_matrix[i][j].values():
quantity_list.append(l)
picking_quantity = pd.DataFrame({'item' : item_list,
'pick_quantity': quantity_list})
picking_quantity = picking_quantity.groupby(['item'], as_index=False).sum()
items = picking_quantity['item']
items = items.to_list()
pick_quantity = picking_quantity['pick_quantity']
pick_quantity = pick_quantity.to_list()
instance_detail = on_hand_dump.copy()
instance_detail['time=0']=0
instance_detail = instance_detail[['time=0','on_hand']]
items.insert(0,0)
pick_quantity.insert(0,0)
on_hand=on_hand_dump.iloc[items]
drop_list =[]
for en,i in enumerate(items):
if on_hand.loc[i,'on_hand']<pick_quantity[en]:
drop_list.append(i)
else:
if (i !=0):
picked_quantity = pick_quantity[en]
on_hand.loc[i,'on_hand'] = on_hand.loc[i,'on_hand'] - picked_quantity
for i in drop_list:
items.remove(i)
sts, obj,det = self.picking(items,time_matrix,veh,cap)
if sts ==1:
on_hand_dump.update(on_hand)
for i in range(100):
instance_detail.iloc[i,-1]=on_hand_dump.iloc[i,-1]
return on_hand_dump