From ab2d199d04728d3ecb0f95067f3f1b90b6b02992 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Fri, 12 Feb 2016 17:44:38 +0100 Subject: [PATCH] Extended run preparation --- reborn.py | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100755 reborn.py diff --git a/reborn.py b/reborn.py new file mode 100755 index 0000000..602883e --- /dev/null +++ b/reborn.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 + +import sys + +class Product: + + ALL = [] + + def __init__(self, weight): + self.ALL.append(self) + + self.weight = weight + + def weight(pid): + return __class__.ALL[pid].weight + + def get(pid): + return __class__.ALL[pid] + + def len(): + return len(__class__.ALL) + +class Warehouse: + + ALL = [] + + def __init__(self, pos, items): + self.ALL.append(self) + + self.pos = pos + self.items = items + + def get(pid): + return __class__.ALL[pid] + + def len(): + return len(__class__.ALL) + +class Client: + + ALL = [] + + def __init__(self, pos, needs): + self.ALL.append(self) + + self.pos = pos + self.items = needs + + def get(pid): + return __class__.ALL[pid] + + def len(): + return len(__class__.ALL) + +class Drone: + + ALL = [] + PAYLOAD = 0 + + def __init__(self): + self.ALL.append(self) + + self.pos = Warehouse.get(0).pos + self.items = [] + self.avail = 0 + self.tasks = [] + + def get(pid): + return __class__.ALL[pid] + + def len(): + return len(__class__.ALL) + + +X = 0 # Nb rows +Y = 0 # Nb columns +T = 0 # Deadline + +def readFile(filename): + global X, Y, T + + with open(filename, 'r') as f: + # Parameters + X, Y, D, T, Drone.PAYLOAD = [int(i) for i in f.readline().split(' ')] + + # Products + P = int(f.readline()) + weights = f.readline().split(' ') + assert(len(weights) == P) + for w in weights: + Product(w) + + # Warehouses + for i in range(0, int(f.readline())): + pos = [int(i) for i in f.readline().split(' ')] + qtItems = [int(i) for i in f.readline().split(' ')] + assert(len(qtItems) == P) + + items = [] + for p in range(P): + for i in range(qtItems[p]): + items.append(p) + + Warehouse(pos, items) + + # Clients + for i in range(0, int(f.readline())): + pos = [int(i) for i in f.readline().split(' ')] + + N = int(f.readline()) + + needs = [int(i) for i in f.readline().split(' ')] + assert(len(needs) == N) + + Client(pos, needs) + + # Create drones + for d in range(D): + Drone() + +readFile(sys.argv[1])