-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplay.py
147 lines (138 loc) · 5.88 KB
/
display.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
# some functions used for visualizing representations and intervals in 1D and 2D settings
from utils import Representation, Interval
def display_rep(rep):
"""
Input:
- Representation rep
Display the grid with vector space dimensions for each node,
and arrows between each pair of adjacent nodes iff there is a matrix between these two nodes.
"""
if len(rep.dimensions) > 2:
print(f"Error: The vizualization is only available for 1D or 2D grids, but the grid has dimension {len(rep.dimensions)}.")
elif len(rep.dimensions) == 2:
for i in range(rep.dimensions[0]):
for j in range(rep.dimensions[1]):
node = (i, j)
vecs_dim = rep.vecs.get(node, None)
edge = (node, (i, j+1))
if vecs_dim is not None:
if j != rep.dimensions[1] - 1:
if edge in rep.mats:
print(f"{vecs_dim} -------> ", end="")
else:
print(f"{vecs_dim} ", end="")
else:
print(f"{vecs_dim}", end="")
else:
if j != rep.dimensions[1] - 1:
if edge in rep.mats:
print(f". -------> ", end="")
else:
print(f". ", end="")
else:
print(".", end="")
print()
if i != rep.dimensions[0] - 1:
for j in range(rep.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in rep.mats:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(rep.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in rep.mats:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(rep.dimensions[1]):
edge = ((i, j), (i+1, j))
if edge in rep.mats:
print("v ", end="")
else:
print(" ", end="")
print()
elif len(rep.dimensions) == 1:
for j in range(rep.dimensions[0]):
node = (j,)
vecs_dim = rep.vecs.get(node, None)
edge = (node, (j+1,))
if vecs_dim is not None:
if j != rep.dimensions[0] - 1:
if edge in rep.mats:
print(f"{vecs_dim} -------> ", end="")
else:
print(f"{vecs_dim} ", end="")
else:
print(f"{vecs_dim}", end="")
else:
if j != rep.dimensions[0] - 1:
if edge in rep.mats:
print(f". -------> ", end="")
else:
print(f". ", end="")
else:
print(".", end="")
print()
def display_interval(rep, itv):
"""
Input:
- Representation rep
- Interval itv
Display the grid and arrows between each pair of adjacent nodes contained in the interval.
"""
if len(rep.dimensions) > 2:
print(f"Error: The vizualization is only available for 1D or 2D grids, but the grid has dimension {len(rep.dimensions)}.")
elif len(rep.dimensions) == 2:
hull = rep.int_hull(itv)
for i in range(rep.dimensions[0]):
for j in range(rep.dimensions[1]):
if j != rep.dimensions[1] - 1:
if (i,j) in hull and (i,j+1) in hull:
print(f"X -------> ", end="")
elif (i,j) in hull and (i,j+1) not in hull:
print(f"X ", end="")
else:
print(f". ", end="")
else:
if (i,j) in hull:
print("X", end="")
else:
print(".", end="")
print()
if i != rep.dimensions[0] - 1:
for j in range(rep.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(rep.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("| ", end="")
else:
print(" ", end="")
print()
for j in range(rep.dimensions[1]):
if (i,j) in hull and (i+1,j) in hull:
print("v ", end="")
else:
print(" ", end="")
print()
elif len(rep.dimensions) == 1:
hull = rep.int_hull(itv)
for j in range(rep.dimensions[0] - 1):
if (j,) in hull and ((j+1,)) in hull:
print("X -------> ", end="")
elif (j,) in hull and ((j+1,)) not in hull:
print("X ", end="")
else:
print(". ", end="")
else:
if (j,) in hull:
print("X", end="")
else:
print(".", end="")
print()