Basic multi-warehouse support
This commit is contained in:
parent
7f9a034fd5
commit
8f1970c127
16
reborn.py
16
reborn.py
|
@ -92,18 +92,24 @@ class Client:
|
|||
def satisfied(self):
|
||||
return len(self.needs) == 0
|
||||
|
||||
def pack(self, payload=-1):
|
||||
def pack(self, payload=-1, rests=[]):
|
||||
if payload == -1:
|
||||
payload = Drone.PAYLOAD
|
||||
p = []
|
||||
load = 0
|
||||
rests = rests.copy()
|
||||
needs = []
|
||||
for need in self.plannedNeeds:
|
||||
if need in rests:
|
||||
needs.append(need)
|
||||
rests.remove(need)
|
||||
# # Sort occurences
|
||||
# occ = [(i, self.plannedNeeds.count(i)) for i in self.plannedNeeds]
|
||||
# occ.sort(key=lambda c: c[1])
|
||||
# # TODO Optimise for same product wanted more than once
|
||||
# Looks like it's not necessary for set 2, we'll see that later
|
||||
# Sort needs by weight
|
||||
couples = [(i, Product.get(i).weight) for i in self.plannedNeeds]
|
||||
couples = [(i, Product.get(i).weight) for i in needs]
|
||||
couples.sort(key=lambda c: c[1])
|
||||
for couple in couples:
|
||||
need, weight = couple
|
||||
|
@ -290,6 +296,7 @@ def newTurn():
|
|||
|
||||
# Determined by trial and error. Not really reliable
|
||||
CLIENT_TRIES = 3
|
||||
CLIENT_TRIES = 100
|
||||
def efficiency(pack, time):
|
||||
return Product.totalWeight(pack) / time
|
||||
#return len(pack) / time
|
||||
|
@ -301,8 +308,9 @@ def route(roadmap):
|
|||
#for client in remainingClients:
|
||||
options = []
|
||||
for client in remainingClients[:CLIENT_TRIES]:
|
||||
#for client in remainingClients:
|
||||
# Create a pack to deliver
|
||||
pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']))
|
||||
pack = client.pack(Drone.PAYLOAD - Product.totalWeight(roadmap['loads']), roadmap['warehouse'].plannedItems)
|
||||
if not pack:
|
||||
continue
|
||||
|
||||
|
@ -311,7 +319,7 @@ def route(roadmap):
|
|||
routeEfficiency = efficiency(pack, routeTime)
|
||||
if roadmap['stops']:
|
||||
# Calculates the efficiency of coming back to warehouse and to the client again
|
||||
backPack = client.pack()
|
||||
backPack = client.pack(rests=roadmap['warehouse'].items)
|
||||
backTime = len(list(set(backPack))) + distance(roadmap['pos'], roadmap['warehouse'].pos) + distance(roadmap['warehouse'].pos, client.pos)
|
||||
backEfficiency = efficiency(backPack, backTime)
|
||||
if backEfficiency > routeEfficiency:
|
||||
|
|
Reference in a new issue