-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_optimizer.py
147 lines (111 loc) · 4.53 KB
/
test_optimizer.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"""
Module for testing the optimizer class
"""
import optimizer as Optimizer
import grid as Grid
import container as Container
def test_unload():
manifest = open("case1.txt", "r", encoding="ascii")
ship_bay = Grid.ShipBay()
buffer = Grid.Buffer()
for line in manifest:
line = line.replace("[", "").replace("]", "").replace("{", "").replace("}", "")
data = line.split(",")
if str(data[3].strip()) != "UNUSED":
row = ship_bay.get_height() - int(data[0])
col = int(data[1]) - 1
cont = Container.Container(weight=int(data[2].strip()), description=str(data[3].strip()), on_ship=True)
ship_bay.add_container(cont, row, col)
ship_bay.convert_grid_to_stack()
buffer.convert_grid_to_stack()
o = Optimizer.Optimizer()
cont = Container.Container(99, "Cat")
return o.load(ship_bay, buffer, [], [cont])
def test_load():
manifest = open("case2.txt", "r", encoding="ascii")
ship_bay = Grid.ShipBay()
buffer = Grid.Buffer()
for line in manifest:
line = line.replace("[", "").replace("]", "").replace("{", "").replace("}", "")
data = line.split(",")
if str(data[3].strip()) != "UNUSED":
row = ship_bay.get_height() - int(data[0])
col = int(data[1]) - 1
cont = Container.Container(weight=int(data[2].strip()), description=str(data[3].strip()), on_ship=True)
ship_bay.add_container(cont, row, col)
ship_bay.convert_grid_to_stack()
buffer.convert_grid_to_stack()
o = Optimizer.Optimizer()
cont = Container.Container(431, "Bat")
return o.load(ship_bay, buffer, [cont], [])
def test_load_unload():
manifest = open("case3.txt", "r", encoding="ascii")
ship_bay = Grid.ShipBay()
buffer = Grid.Buffer()
for line in manifest:
line = line.replace("[", "").replace("]", "").replace("{", "").replace("}", "")
data = line.split(",")
if str(data[3].strip()) != "UNUSED":
row = ship_bay.get_height() - int(data[0])
col = int(data[1]) - 1
cont = Container.Container(weight=int(data[2].strip()), description=str(data[3].strip()), on_ship=True)
ship_bay.add_container(cont, row, col)
ship_bay.convert_grid_to_stack()
buffer.convert_grid_to_stack()
o = Optimizer.Optimizer()
load = []
load.append(Container.Container(532, "Bat"))
load.append(Container.Container(6317, "Rat"))
unload = []
unload.append(Container.Container(100, "Cow"))
return o.load(ship_bay, buffer, load, unload)
def test_balance_1():
manifest = open("case1.txt", "r", encoding="ascii")
ship_bay = Grid.ShipBay()
buffer = Grid.Buffer()
for line in manifest:
line = line.replace("[", "").replace("]", "").replace("{", "").replace("}", "")
data = line.split(",")
if str(data[3].strip()) != "UNUSED":
row = ship_bay.get_height() - int(data[0])
col = int(data[1]) - 1
cont = Container.Container(weight=int(data[2].strip()), description=str(data[3].strip()), on_ship=True)
ship_bay.add_container(cont, row, col)
ship_bay.convert_grid_to_stack()
buffer.convert_grid_to_stack()
o = Optimizer.Optimizer()
return o.balance(ship_bay, buffer)
def test_sift():
manifest = open("case5.txt", "r", encoding="ascii")
ship_bay = Grid.ShipBay()
buffer = Grid.Buffer()
for line in manifest:
line = line.replace("[", "").replace("]", "").replace("{", "").replace("}", "")
data = line.split(",")
if str(data[3].strip()) != "UNUSED":
row = ship_bay.get_height() - int(data[0])
col = int(data[1]) - 1
cont = Container.Container(weight=int(data[2].strip()), description=str(data[3].strip()), on_ship=True)
ship_bay.add_container(cont, row, col)
ship_bay.convert_grid_to_stack()
buffer.convert_grid_to_stack()
o = Optimizer.Optimizer()
return o.balance(ship_bay, buffer)
# vals, n_expanded, max_n = test_load_unload()
# while vals is not None:
# print(vals.get_bay())
# vals = vals.get_parent_move()
# print("Expanded: %s" % n_expanded)
# print("Max: %s" % max_n)
vals, n_expanded, max_n = test_balance_1()
while vals is not None:
print(vals.get_bay())
vals = vals.get_parent_move()
print("Expanded: %s" % n_expanded)
print("Max: %s" % max_n)
# vals, n_expanded, max_n = test_sift()
# while vals is not None:
# print(vals.get_bay())
# vals = vals.get_parent_move()
# print("Expanded: %s" % n_expanded)
# print("Max: %s" % max_n)