-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_polypod.py
More file actions
101 lines (84 loc) · 3.16 KB
/
test_polypod.py
File metadata and controls
101 lines (84 loc) · 3.16 KB
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
import polypod
import tools
params = polypod.PolyPodParameters(S=1750, b1=0, u1=90, b2=0, u2=65)
# Test factory function
print("=== Testing Factory Function ===")
solver = polypod.create_polypod(params, T=11, mode="recreate")
print(f"Created solver using factory: {type(solver).__name__}")
print()
# Find shortest solution
solution = solver.find_shortest_solution()
print(f"Shortest solution (greedy): {solution}")
print(f"Solution length: {len(solution)}")
# Test get_matrix
matrix = solver.get_matrix()
print(f"\nMigration matrix size: {len(matrix)}")
# Print migration matrix in triangular format
print("\nMigration Matrix (t=x-axis, m=y-axis):")
tools.print_migration_matrix_simple(matrix)
# Test BFS iteration (shortest solutions first)
print("\n--- BFS Solutions (shortest first) ---")
solver.bfs_reset()
count = 0
while True:
sol = solver.bfs_next_solution()
if not sol:
break
count += 1
print(f"Solution {count} (len={len(sol)}): {sol}")
if count >= 5: # Limit output for brevity
print("... (more solutions may exist)")
break
print(f"Total BFS solutions found: {count}")
# Test DFS iteration with prefer_max=True (greedy for largest steps)
print("\n--- DFS Solutions (prefer_max=True, largest steps first) ---")
solver.dfs_reset()
count = 0
while True:
sol = solver.dfs_next_solution(prefer_max=True)
if not sol:
break
count += 1
print(f"Solution {count} (len={len(sol)}): {sol}")
if count >= 5:
print("... (more solutions may exist)")
break
print(f"Total DFS (max) solutions found: {count}")
# Test DFS iteration with prefer_max=False (greedy for smallest steps)
print("\n--- DFS Solutions (prefer_max=False, smallest steps first) ---")
solver.dfs_reset()
count = 0
while True:
sol = solver.dfs_next_solution(prefer_max=False)
if not sol:
break
count += 1
print(f"Solution {count} (len={len(sol)}): {sol}")
if count >= 5:
print("... (more solutions may exist)")
break
print(f"Total DFS (min) solutions found: {count}")
# Test find_maximum_T_with_solution
print("\n--- Finding Maximum T with Solution ---")
params2 = polypod.PolyPodParameters(S=1750, b1=0, u1=90, b2=0, u2=65)
solver2 = polypod.InPlacePolyPod(params2, T=1)
max_solution = solver2.find_maximum_T_with_solution()
print(f"Maximum T: {solver2.getT()}")
print(f"Solution: {max_solution}")
print(f"Solution length: {len(max_solution)}")
# Test factory with different modes
print("\n--- Testing Factory with Different Modes ---")
inplace_solver = polypod.create_polypod(params, T=6, mode="inplace")
recreate_solver = polypod.create_polypod(params, T=6, mode="recreate")
print(f"Inplace solver type: {type(inplace_solver).__name__}")
print(f"Recreate solver type: {type(recreate_solver).__name__}")
inplace_sol = inplace_solver.find_shortest_solution()
recreate_sol = recreate_solver.find_shortest_solution()
print(f"Inplace solution: {inplace_sol}")
print(f"Recreate solution: {recreate_sol}")
# Test invalid mode (should raise error)
print("\n--- Testing Invalid Mode ---")
try:
bad_solver = polypod.create_polypod(params, T=6, mode="invalid")
except ValueError as e:
print(f"Caught expected error: {e}")