From 78022242e604cc7a69b6e9f3130eb1a2924cc9fe Mon Sep 17 00:00:00 2001 From: JLo'w Date: Thu, 11 Feb 2016 19:24:11 +0100 Subject: [PATCH 1/5] Read function --- read.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/read.py b/read.py index 4287ca8..f32fba4 100644 --- a/read.py +++ b/read.py @@ -1 +1,34 @@ -# \ No newline at end of file +#Read the input file + +import sys.io + +def Read_input_file(file): + f = open(file, 'r') + + line = readline() + info = line.split(' ') + + GRILLE = (int(info[0]), int(info[1])) + D = int(info[2]) + T = int(info[3]) + M = int(info[4]) + + line = readline() + P = int(line) + + line = readline() + info = line.split(' ') + for (i in range(0, P)): + Pw[i] = int(info[i]) + + line = readline() + W = int(line) + + for (i in range(0, W)): + line = readline() + info = line.split(' ') + Wp[i] = (int(info[0]), int(info[1])) + line = readline() + info = line.split(' ') + + \ No newline at end of file From 192f6fad2e00a5c0bd29d5c68438f61e48d8e0e3 Mon Sep 17 00:00:00 2001 From: JLo'w Date: Thu, 11 Feb 2016 19:36:20 +0100 Subject: [PATCH 2/5] complete read function --- read.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/read.py b/read.py index f32fba4..3a458be 100644 --- a/read.py +++ b/read.py @@ -30,5 +30,25 @@ def Read_input_file(file): Wp[i] = (int(info[0]), int(info[1])) line = readline() info = line.split(' ') + productQ = {} + for (j in range(1, info.size()+1): + productQ[j] = int(info[j]) + Wi[i] = productsQ + + line = readline() + nbC = int(line) + + for(i in range(0, nbC)): + line = readline() + info = line.split(' ') + Cp[i] = (int(info[0]), int(info[1])) + line = readline() + nbP = int(line) + line = readline() + info = line.split(' ') + orderQ = {} + for (j in range(0, nbP)): + orderQ[j] = int(info[j]) + Ci[i] = orderQ - \ No newline at end of file + return \ No newline at end of file From 93881fd341959a9af817ac14543ac4f4a49ce8b1 Mon Sep 17 00:00:00 2001 From: JLo'w Date: Thu, 11 Feb 2016 19:50:19 +0100 Subject: [PATCH 3/5] readline() method wasn't call on file object --- read.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/read.py b/read.py index 3a458be..f77592e 100644 --- a/read.py +++ b/read.py @@ -1,11 +1,9 @@ #Read the input file -import sys.io - def Read_input_file(file): f = open(file, 'r') - line = readline() + line = f.readline() info = line.split(' ') GRILLE = (int(info[0]), int(info[1])) @@ -13,42 +11,42 @@ def Read_input_file(file): T = int(info[3]) M = int(info[4]) - line = readline() + line = f.readline() P = int(line) - line = readline() + line = f.readline() info = line.split(' ') - for (i in range(0, P)): + for i in range(0, P): Pw[i] = int(info[i]) - line = readline() + line = f.readline() W = int(line) - for (i in range(0, W)): - line = readline() + for i in range(0, W): + line = f.readline() info = line.split(' ') Wp[i] = (int(info[0]), int(info[1])) - line = readline() + line = f.readline() info = line.split(' ') productQ = {} - for (j in range(1, info.size()+1): + for j in range(1, info.size())+1: productQ[j] = int(info[j]) Wi[i] = productsQ - line = readline() + line = f.readline() nbC = int(line) - for(i in range(0, nbC)): - line = readline() + for i in range(0, nbC): + line = f.readline() info = line.split(' ') Cp[i] = (int(info[0]), int(info[1])) - line = readline() + line = f.readline() nbP = int(line) - line = readline() + line = f.readline() info = line.split(' ') orderQ = {} - for (j in range(0, nbP)): + for j in range(0, nbP): orderQ[j] = int(info[j]) Ci[i] = orderQ - return \ No newline at end of file + return From 4ee070a3053a391b27faf96a9ba676fdc5258745 Mon Sep 17 00:00:00 2001 From: JLo'w Date: Thu, 11 Feb 2016 19:55:30 +0100 Subject: [PATCH 4/5] Use append() method for lists --- read.py | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/read.py b/read.py index f77592e..99cd4e7 100644 --- a/read.py +++ b/read.py @@ -1,5 +1,34 @@ #Read the input file +X = 0 # Nb rows +Y = 0 # Nb columns +D = 0 # Nb drones +T = 0 # Deadline +M = 0 # Maximum load +P = 0 # Nb products +W = 0 # Nb warehouses +C = 0 # Nb customers + +Dp = []; # Positions of drones +# (x, y) +Di = []; # Items of drones +# {product number: qt} +Dd = []; # Turn avaibility of drone +# int + +Pw = []; # Weight of products +# int + +Wp = []; # Positions of warehouses +# (x, y) +Wi = []; # Items of warehouses +# {product number: qt} + +Cp = []; # Positions of customers +# (x, y) +Ci = []; # Needs of customers +# {product number: qt} + def Read_input_file(file): f = open(file, 'r') @@ -17,7 +46,7 @@ def Read_input_file(file): line = f.readline() info = line.split(' ') for i in range(0, P): - Pw[i] = int(info[i]) + Pw.append(int(info[i])) line = f.readline() W = int(line) @@ -25,13 +54,13 @@ def Read_input_file(file): for i in range(0, W): line = f.readline() info = line.split(' ') - Wp[i] = (int(info[0]), int(info[1])) + Wp.append((int(info[0]), int(info[1]))) line = f.readline() info = line.split(' ') productQ = {} - for j in range(1, info.size())+1: - productQ[j] = int(info[j]) - Wi[i] = productsQ + for j in range(0, info.size()): + productQ.append(int(info[j])) + Wi.append(productsQ) line = f.readline() nbC = int(line) @@ -39,14 +68,14 @@ def Read_input_file(file): for i in range(0, nbC): line = f.readline() info = line.split(' ') - Cp[i] = (int(info[0]), int(info[1])) + Cp.append((int(info[0]), int(info[1]))) line = f.readline() nbP = int(line) line = f.readline() info = line.split(' ') orderQ = {} for j in range(0, nbP): - orderQ[j] = int(info[j]) - Ci[i] = orderQ + orderQ.append(int(info[j])) + Ci.append(orderQ) return From f34c45470c7651da7db1821580c86df13d30781d Mon Sep 17 00:00:00 2001 From: JLo'w Date: Thu, 11 Feb 2016 20:09:19 +0100 Subject: [PATCH 5/5] Delete global var for test, remove append() method for dict and correct Ci construction --- read.py | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/read.py b/read.py index 99cd4e7..5e0cf97 100644 --- a/read.py +++ b/read.py @@ -1,34 +1,5 @@ #Read the input file -X = 0 # Nb rows -Y = 0 # Nb columns -D = 0 # Nb drones -T = 0 # Deadline -M = 0 # Maximum load -P = 0 # Nb products -W = 0 # Nb warehouses -C = 0 # Nb customers - -Dp = []; # Positions of drones -# (x, y) -Di = []; # Items of drones -# {product number: qt} -Dd = []; # Turn avaibility of drone -# int - -Pw = []; # Weight of products -# int - -Wp = []; # Positions of warehouses -# (x, y) -Wi = []; # Items of warehouses -# {product number: qt} - -Cp = []; # Positions of customers -# (x, y) -Ci = []; # Needs of customers -# {product number: qt} - def Read_input_file(file): f = open(file, 'r') @@ -58,9 +29,9 @@ def Read_input_file(file): line = f.readline() info = line.split(' ') productQ = {} - for j in range(0, info.size()): - productQ.append(int(info[j])) - Wi.append(productsQ) + for j in range(0, len(info)): + productQ[j] = int(info[j]) + Wi.append(productQ) line = f.readline() nbC = int(line) @@ -74,8 +45,10 @@ def Read_input_file(file): line = f.readline() info = line.split(' ') orderQ = {} + for k in range(0, P): + orderQ[k] = 0 for j in range(0, nbP): - orderQ.append(int(info[j])) + orderQ[int(info[j])] += 1 Ci.append(orderQ) return