-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugger.py
57 lines (45 loc) · 1.65 KB
/
debugger.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
import numpy as np
from parse import parse_file
import segments as sgm
from csp import Nonogram_Solver
import ipdb, traceback, sys, inspect
import debug_wrappers
import drawing
if __name__ == '__main__':
try:
solver = Nonogram_Solver(heuristic_fun, *parse_file('data/reindeer.dat'))
initial_node = solver.generate_initial_node()
%prun solver.solve(initial_node.state)
print(solver.summarize())
x, y = solver.solution.state
col_height = x[0].shape[1]
row_height = y[0].shape[1]
import pdb; pdb.set_trace()
window = drawing.generate_window(col_height, row_height)
drawing.draw_state((x,y), window)
M = np.rot90(np.matrix([each[0] for each in x]), k=3)
M = np.rot90(M,k=3)
N = np.matrix([each[0] for each in y])
N = np.rot90(N,k=3)
print(M,'\n')
print(N,'\n')
is_solution = np.all(np.equal(M,N))
print(f'found solution: {is_solution}')
import pdb; pdb.set_trace()
except:
print('closing window')
window.close()
type, value, tb = sys.exc_info()
traceback.print_tb(tb)
print(type, value)
frame = tb.tb_frame
inner = [each for each in inspect.getinnerframes(tb)]
outer = [each for each in inspect.getouterframes(frame)]
combined = inner + outer
def fnames(frames):
return [each.function for each in frames]
last_function_call = inspect.getinnerframes(tb)[-1].function
db = lambda name: debug_wrappers.FUN(combined, name)
frame = db(last_function_call)
import ipdb; ipdb.set_trace()
# end