-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.py
89 lines (66 loc) · 2.97 KB
/
world.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
# -*- coding: utf-8 -*-
import math
import filereader
import drone
import Warehouse
class world:
drones = list()
def __init__(self):
self.datasetfromfile = filereader.readFile("data_set/busy_day.in")
self.gridx = self.datasetfromfile[0]
self.gridy = self.datasetfromfile[1]
self.warehouseObjects = self.datasetfromfile[2]
self.droneCount = self.datasetfromfile[3]
self.maxCommands = self.datasetfromfile[4]
self.maxPayload = self.datasetfromfile[5]
self.orderObjects = self.datasetfromfile[6]
self.productWeights = self.datasetfromfile[7]
# Create the drones
for i in xrange(self.droneCount):
self.drones.append(drone.drone(self.warehouseObjects[0].location, self.maxPayload))
# Calculate the nearest wearhouse to each order and vise-versa
type(self.orderObjects)
for order in self.orderObjects:
calculatedDistances = []
for wh in self.warehouseObjects:
calculatedDistances.append(travelTime(order.location,wh.location))
order.mywarehouse = self.warehouseObjects[calculatedDistances.index(min(calculatedDistances))]
wh.deliveryPoints.append(order)
# for wh1 in self.warehouseObjects:
# calculatedDistances = []
# for wh2 in self.warehouseObjects:
# calculatedDistances.append(travelTime(order.location,wh.location)
# order.mywarehouse = self.warehouseObjects[calculatedDistances.index(min(calculatedDistances))]
# wh.excessInventory
# wh.wishlist
# for wh1 in self.self.warehouseObjects:
# for wh2 in self.self.warehouseObjects:
self.commandList = list()
for wh1 in self.warehouseObjects:
for wh2 in self.warehouseObjects:
if wh1 == wh2:
continue
for wl in wh1.wishlist:
for el in wh2.excessInventory:
if wl in el:
self.commandList.append((wh1,wh2,wh1.wishlist.index(wl)))
wh2.excessInventory.remove(wl)
wh2.allProducts.remove(wl)
wh1.wishlist.remove(wl)
wh1.allProducts.append(wl)
print self.commandList
# list of orders
# How many can we currently delvier to from our inventory
def simulate(self):
print "CALLED"
# Loop through time starting zero
for t in xrange(self.maxCommands):
for d in self.drones: d.step()
for i in self.commandList:
print i
continue
for d in self.drones:
if not d.checkBusy:
print "%i L %i %i %i " % (d.idx,wh1.idx,p,1)
def travelTime(self, From, To):
return math.ceil(math.sqrt(pow((From[0] - To[0]),2) + pow((From[1] - To[1]),2)))