Drone task list

This commit is contained in:
Geoffrey Frogeye 2016-02-13 13:44:11 +01:00
parent 8728346ace
commit 6da3a76ca5

View file

@ -44,6 +44,8 @@ class Warehouse:
self.pos = pos
self.items = items
self.plannedItems = self.items
def near(pos):
couples = []
for el in __class__.ALL:
@ -67,6 +69,8 @@ class Client:
self.pos = pos
self.needs = needs
self.plannedNeeds = self.needs
def satisfied(self):
return len(self.needs) == 0
@ -94,8 +98,21 @@ class Drone:
self.pos = Warehouse.get(0).pos
self.items = []
self.avail = 0
self.tasks = []
def addTask(self, *task):
self.tasks.append(task)
def executeTask(self):
if self.available():
if len(self.tasks):
task = self.tasks[0]
getattr(self, task[0])(*task[1:])
self.tasks = self.tasks[1:]
else:
self.wait()
def weight(self):
s = 0
for i in self.items:
@ -223,26 +240,26 @@ readFile(sys.argv[1])
def newTurn():
global turn
# Finishing turn
for drone in [drone for drone in Drone.ALL if drone.available()]:
drone.wait()
for drone in Drone.ALL:
drone.executeTask()
# New turn
turn += 1
log("--- Turn", turn)
availableDrones = [str(drone.id) for drone in Drone.ALL if drone.available()]
log("Drones", ", ".join(availableDrones), "("+str(len(availableDrones))+")", "are available")
SIMULATION = 2
try:
d = 0
c = Client.near(Warehouse.get(0).pos)[0]
for c in Client.near(Warehouse.get(0).pos):
N = c.needs.copy()
for n in N:
Drone.get(d).load(Warehouse.get(0), Product.get(n), 1)
if d < Drone.len():
Drone.get(d).addTask('load', Warehouse.get(0), Product.get(n), 1)
Drone.get(d).addTask('deliver', c, Product.get(n), 1)
d += 1
while turn < SIMULATION:
newTurn()
d = 0
for n in N:
Drone.get(d).deliver(c, Product.get(Drone.get(d).items[0]), 1)
d += 1
except KeyboardInterrupt: