Browse Source

Add jj's checker.py + Makefile to move outputs

Olivier Marty 8 years ago
parent
commit
9aecfa138b
3 changed files with 81 additions and 5 deletions
  1. 2 2
      .gitignore
  2. 6 3
      Olivier/Makefile
  3. 73 0
      Olivier/checker.py

+ 2 - 2
.gitignore

@@ -1,4 +1,4 @@
-gurobi.log
 *.o
 main
-source.zip
+sources.zip
+*.out*

+ 6 - 3
Olivier/Makefile

@@ -1,25 +1,28 @@
 CPP=g++ -O2 -std=c++11
 SOURCES=instance.cpp main.cpp
 
-all: source.zip bd.out moaw.out red.out
+all: sources.zip bd.out moaw.out red.out
 
 bd.out: main
 	./main < ../busy_day.in > /tmp/hashcode
 	wc -l /tmp/hashcode | cut -d' ' -f1 > bd.out
 	cat /tmp/hashcode >> bd.out
+	./checker.py ../busy_day.in bd.out | xargs mv bd.out
 
 moaw.out: main
 	./main < ../mother_of_all_warehouses.in > /tmp/hashcode
 	wc -l /tmp/hashcode | cut -d' ' -f1 > moaw.out
 	cat /tmp/hashcode >> moaw.out
+	./checker.py ../mother_of_all_warehouses.in moaw.out | xargs mv moaw.out
 
 red.out: main
 	./main < ../redundancy.in > /tmp/hashcode
 	wc -l /tmp/hashcode | cut -d' ' -f1 > red.out
 	cat /tmp/hashcode >> red.out
+	./checker.py ../redundancy.in red.out | xargs mv red.out
 
-source.zip: $(SOURCES)
-	zip source.zip $(wildcard *.cpp)  $(wildcard *.h)
+sources.zip: $(wildcard *.cpp) $(wildcard *.h) $(wildcard *.py) Makefile
+	zip sources.zip $(wildcard *.cpp) $(wildcard *.h) $(wildcard *.py) Makefile
 
 main: $(SOURCES:.cpp=.o)
 	$(CPP) -o $@ $^ $(INC) $(LIBS)

+ 73 - 0
Olivier/checker.py

@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+
+from collections import Counter
+from math import sqrt, ceil
+import sys
+# from heapq import heappush, heappop
+
+FILE_IN = sys.argv[1]
+FILE_OUT = sys.argv[2]
+SCORE = 0
+
+lines = open(FILE_IN).read().splitlines()
+
+R, C, nb_drones, T, max_payload = map(int, lines[0].split())
+
+nb_types = int(lines[1])
+weights = map(int, lines[2].split())
+
+nb_warehouses = int(lines[3])
+coords_w = [None] * nb_warehouses
+stocks = [None] * nb_warehouses
+for w in range(nb_warehouses):
+    coords_w[w] = list(map(int, lines[4 + 2 * w].split()))
+    stocks[w] = list(map(int, lines[4 + 2 * w + 1].split()))
+
+nb_orders = int(lines[4 + 2 * nb_warehouses])
+coords_o = [None] * nb_orders
+request = [None] * nb_orders
+for o in range(nb_orders):
+    coords_o[o] = list(map(int, lines[4 + 2 * nb_warehouses + 1 + 3 * o].split()))
+    request[o] = Counter(map(int, lines[4 + 2 * nb_warehouses + 1 + 3 * o + 2].split()))
+
+# All drones start at 0
+coords_d = [coords_w[0]] * nb_drones
+time_d = [-1] * nb_drones
+load_d = [Counter() for _ in range(nb_drones)]
+
+delivery_times = {}
+
+def dist(c1, c2):
+    return sqrt(pow(c1[0] - c2[0], 2) + pow(c1[1] - c2[1], 2))
+
+def load(drone_id):
+    return sum(nb * weights[product_type] for product_type, nb in enumerate(load_d[drone_id]))
+
+with open(FILE_OUT) as f:
+    next(f)
+    for line in f:
+        if 'W' in line or 'U' in line:
+            pass
+        else:
+            drone_id, command, place_id, product_type, quantity = map(lambda x: int(x) if x not in 'DL' else x, line.split())
+        if command == 'L':
+            time_d[drone_id] += ceil(dist(coords_d[drone_id], coords_w[place_id]))
+            # TODO verify there is sufficient stock in warehouse
+            coords_d[drone_id] = coords_w[place_id]
+            load_d[drone_id][product_type] += quantity
+            # TODO verify max_payload
+            time_d[drone_id] += 1
+            # print('Drone %d loads from warehouse %d at turn %d' % (drone_id, place_id, time_d[drone_id]))
+        else:
+            time_d[drone_id] += ceil(dist(coords_d[drone_id], coords_o[place_id]))
+            coords_d[drone_id] = coords_o[place_id]
+            # TODO verify order is respected
+            load_d[drone_id][product_type] -= quantity
+            request[place_id][product_type] -= quantity
+            time_d[drone_id] += 1
+            current_time = time_d[drone_id]
+            delivery_times.setdefault(place_id, []).append(current_time)
+            if all(quantity == 0 for quantity in request[place_id].values()):
+                # print('Order %d is satisfied by drone %d at turn %d' % (place_id, drone_id, time_d[drone_id]))
+                SCORE += ceil((T - max(delivery_times[place_id])) * 100 / T)
+    print(FILE_OUT + "_" + str(SCORE))