- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
Latest commit
124 lines (106 loc) · 4.55 KB
/
Copy pathparser.py
File metadata and controls
124 lines (106 loc) · 4.55 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
frommodelsimport*
fromloggerimportLogger
importmath
importcopy
log=Logger()
defgetDistance(location1, location2):
euclidDist=math.sqrt((location1[0]-location2[0])**2+(location1[1]-location2[1])**2)
returnmath.ceil(euclidDist)
f=open("busy_day.in","r")
commandList= []
#Parameters of simulation
[nRows,nCols,nDrones,maxSteps,maxLoad]=[int(i) foriinf.readline().split()]
#weights of the products available for orders
nTypes=int(f.readline())
productWeights= [int(i) foriinf.readline().split()]
#warehouses and availability of individual product types
nWarehouses=int(f.readline())
warehouseList= []
foriWarehouseinxrange(nWarehouses):
location=tuple([int(i) foriinf.readline().split()])
items= [int(i) foriinf.readline().split()]
warehouse=Warehouse(items,location)
warehouseList.append(warehouse)
#customer orders
nOrders=int(f.readline())
orderList= []
foriOrderinxrange(nOrders):
location=tuple([int(i) foriinf.readline().split()])
nOrderedProducts=int(f.readline())
tmpItems= [int(i) foriinf.readline().split()]
items= [tmpItems.count(i) foriinrange(nTypes)]
warehouseDistances= [(getDistance(location, warehouseList[i].location),i) foriinrange(nWarehouses)]
warehouseDistances.sort()
order=Order(items,location,warehouseDistances)
orderList.append(order)
#Create drones
droneList= [Drone(warehouseList[0].location, maxLoad, nTypes) foriinrange(nDrones)]
deforderWeight(order):
sum=0
foriinrange(len(order.items)):
sum+=order.items[i] *productWeights[i]
returnsum
defeasyOrders(orders,warehouses):
easy= []
wh=copy.deepcopy(warehouses)
foroidx, order2inenumerate(orders):
iforderWeight(order2) <maxLoad:
for_, widxinorder2.warehouseDistances:
iforder2.is_ready_at(wh[widx]):
easy.append((oidx, widx))
foriinrange(len(wh[widx].stock)):
wh[widx].stock[i] -=order2.items[i]
break
returneasy
#World
foriStepinxrange(maxSteps):
#do all jobs pending and find free drones
#freeDronesIdx = []
if (iStep%100==0):
log.write_to_file(maxSteps, iStep)
availableOrders=easyOrders(orderList,warehouseList)
foriDroneinxrange(nDrones):
ifdroneList[iDrone].finishedAt==iStep:
warehouseDistances= [(getDistance(droneList[iDrone].location, warehouseList[i].location),i) foriinrange(nWarehouses)]
warehouseDistances.sort()
#Find order idx for drone, starting by looking at the closest warehouse
foriinxrange(nWarehouses):
preferredWarehouseIdx=warehouseDistances[i][1]
orderIdx=None
foravailableOrderinavailableOrders:
if(availableOrder[1]==preferredWarehouseIdx):
orderIdx=availableOrder[0]
break
iforderIdxisnotNone:
break
#Handle order for drone
currentOrder=orderList[orderIdx]
foritemIdxinxrange(len(currentOrder.items)):
itemcount=currentOrder.items[itemIdx]
ifitemcount>0:
droneList[iDrone].load(itemcount, itemIdx, warehouseList[preferredWarehouseIdx])
#TODO create command in logger
commandDict= {
'name' : 'load',
'drone_id' : iDrone,
'warehouse_id' : preferredWarehouseIdx,
'prod_id' : itemIdx,
'prod_count' : itemcount
}
log.append_command(droneList[iDrone].finishedAt, commandDict)
foritemIdxinxrange(len(currentOrder.items)):
itemcount=currentOrder.items[itemIdx]
ifitemcount>0:
droneList[iDrone].deliver(itemcount, itemIdx, orderList[orderIdx])
#TODO create command in logger
commandDict= {
'name' : 'deliver',
'drone_id' : iDrone,
'order_id' : orderIdx,
'prod_id' : itemIdx,
'prod_count' : itemcount
}
log.append_command(droneList[iDrone].finishedAt, commandDict)
#update available orders
#availableOrders = easyOrders(orderList,warehouseList)
log.write_to_file(maxSteps)