Read into main

This commit is contained in:
Geoffrey Frogeye 2016-02-11 20:35:07 +01:00
parent 32278e7461
commit 8bf8936e35
2 changed files with 66 additions and 56 deletions

68
main.py
View file

@ -1,9 +1,12 @@
#!/usr/bin/env python3
import math
import sys
print("#hashcode2016")
import read
X = 0 # Nb rows
Y = 0 # Nb columns
D = 0 # Nb drones
@ -13,7 +16,7 @@ P = 0 # Nb products
W = 0 # Nb warehouses
C = 0 # Nb customers
t = 0 # Turn
t = -1 # Turn
Dp = []; # Positions of drones
# (x, y)
@ -37,9 +40,69 @@ Cp = []; # Positions of customers
Ci = []; # Needs of customers
# {product number: qt}
# Reading raw data
f = open(sys.argv[1], 'r')
line = f.readline()
info = line.split(' ')
GRILLE = (int(info[0]), int(info[1]))
X, Y = GRILLE
D = int(info[2])
T = int(info[3])
M = int(info[4])
line = f.readline()
P = int(line)
line = f.readline()
info = line.split(' ')
for i in range(0, P):
Pw.append(int(info[i]))
line = f.readline()
W = int(line)
for i in range(0, W):
line = f.readline()
info = line.split(' ')
Wp.append((int(info[0]), int(info[1])))
line = f.readline()
info = line.split(' ')
productQ = {}
for j in range(0, len(info)):
productQ[j] = int(info[j])
Wi.append(productQ)
line = f.readline()
C = int(line)
for i in range(0, C):
line = f.readline()
info = line.split(' ')
Cp.append((int(info[0]), int(info[1])))
line = f.readline()
nbP = int(line)
line = f.readline()
info = line.split(' ')
orderQ = {}
for k in range(0, P):
orderQ[k] = 0
for j in range(0, nbP):
orderQ[int(info[j])] += 1
Ci.append(orderQ)
f.close()
# Constituting data
for d in range(D):
Dp.append(Wp[0])
Di.append(dict((p, 0) for p in range(P)))
Dd.append(0)
# Debug
assert(len(Dp) == len(Di) == len(Dd) == len(Da) == D)
assert(len(Dp) == len(Di) == len(Dd) == D)
assert(len(Pw) == P)
assert(len(Wp) == len(Wi) == W)
assert(len(Cp) == len(Ci) == C)
@ -56,6 +119,7 @@ def showGrid():
print("C", end="")
else:
print("·", end="")
print()
# Utilities
def distance(A, B):

54
read.py
View file

@ -1,54 +0,0 @@
#Read the input file
def Read_input_file(file):
f = open(file, 'r')
line = f.readline()
info = line.split(' ')
GRILLE = (int(info[0]), int(info[1]))
D = int(info[2])
T = int(info[3])
M = int(info[4])
line = f.readline()
P = int(line)
line = f.readline()
info = line.split(' ')
for i in range(0, P):
Pw.append(int(info[i]))
line = f.readline()
W = int(line)
for i in range(0, W):
line = f.readline()
info = line.split(' ')
Wp.append((int(info[0]), int(info[1])))
line = f.readline()
info = line.split(' ')
productQ = {}
for j in range(0, len(info)):
productQ[j] = int(info[j])
Wi.append(productQ)
line = f.readline()
nbC = int(line)
for i in range(0, nbC):
line = f.readline()
info = line.split(' ')
Cp.append((int(info[0]), int(info[1])))
line = f.readline()
nbP = int(line)
line = f.readline()
info = line.split(' ')
orderQ = {}
for k in range(0, P):
orderQ[k] = 0
for j in range(0, nbP):
orderQ[int(info[j])] += 1
Ci.append(orderQ)
return