-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_checker.py
122 lines (93 loc) · 3.25 KB
/
output_checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
## CHECKS IF THE OUTPUT FILE IS CORRECT
## Requirements: output.txt file with correct output format.
import numpy as np
INF = 10**10
print("READING INPUT...")
with open("input.txt", "r") as f:
k = int(f.readline().strip())
num_uld = int(f.readline().strip())
uld_containers = {}
weights = {}
contains_priority = {}
for _ in range(num_uld):
uld_id, length, width, height, weight = f.readline().strip().split(",")
uld_containers[uld_id] = np.zeros((int(length), int(width), int(height)), dtype=int)
weights[uld_id] = int(weight)
contains_priority[uld_id] = False
num_packages = int(f.readline().strip())
packages = {}
for _ in range(num_packages):
(
package_id,
length,
width,
height,
weight,
package_type,
cost,
) = f.readline().strip().split(",")
packages[package_id] = [
int(length),
int(width),
int(height),
int(weight),
package_type,
INF if package_type == "Priority" else int(cost),
]
print("READING OUTPUT...")
with open("output.txt") as f:
data = f.readlines()
output_cost, output_packed, output_split = map(int, data[0].split(","))
def verify():
cost = 0
packed = 0
for line in data[1:]:
pid, uid, a, b, c, x, y, z = line.split(",")
a, b, c, x, y, z = map(int, [a, b, c, x, y, z])
if pid not in packages:
print(f"ERROR: {pid} doesn't exist / packed twice.")
return
if uid == "NONE":
if packages[pid][4] == "Priority":
print(f"ERROR: Priority package {pid} is not packed.")
return
cost += packages[pid][5]
del packages[pid]
continue
packed += 1
if uid not in uld_containers:
print(f"ERROR: ULD {uid} doesn't exist")
return
if packages[pid][4] == "Priority":
contains_priority[uid] = True
pkg = packages[pid]
if sorted([x - a, y - b, z - c]) != sorted(pkg[:3]):
print(f"ERROR: Dimensions of {pid} don't match packing")
return
# Check overlap using slicing
container_slice = uld_containers[uid][a:x, b:y, c:z]
if np.any(container_slice):
print(f"ERROR: Package {pid} overlaps.")
return
# Mark the space as filled
uld_containers[uid][a:x, b:y, c:z] = 1
weights[uid] -= packages[pid][3]
del packages[pid]
split = sum(contains_priority.values())
cost += split*k
if cost != output_cost:
print(f"ERROR: Costs don't match. Actual cost of given packing is {cost}")
return
for uld in weights:
if weights[uld] < 0:
print(f"ERROR: Weight in ULD {uld} exceeds by {-weights[uld]}")
return
if packed != output_packed:
print(f"ERROR: Packed count doesn't match. Actual packed count of given packing is {packed}")
return
if split != output_split:
print(f"ERROR: Splits don't match. Actual priority split of given packing is {split}")
return
print("SUCCESSFUL: Output is correct")
print("VERIFYING...")
verify()