-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
56 lines (48 loc) · 1.42 KB
/
tools.py
File metadata and controls
56 lines (48 loc) · 1.42 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
def print_migration_matrix_simple(matrix: list[list[int]]):
"""
Print migration matrix in triangular format.
Args:
matrix: Migration matrix where matrix[t][m] == 1 means (m+1) tenants can migrate when t already migrated
"""
if not matrix:
return
T = len(matrix)
# Find the first row (from top) that contains at least one 1
first_nonempty_m = 0
for m in range(T - 1, -1, -1):
has_one = False
for t in range(T):
if m < len(matrix[t]) and matrix[t][m]:
has_one = True
break
if has_one:
first_nonempty_m = m
break
# Print top border
print("---+", end="")
for t in range(T):
print("---+", end="")
print()
# Print from top to bottom
for m in range(first_nonempty_m, -1, -1):
print(f"{m+1:2d} |", end="")
for t in range(T):
if m < len(matrix[t]):
val = '*' if matrix[t][m] else ' '
print(f" {val} ", end="")
else:
print(" ", end="")
print("|", end="")
print()
# Print horizontal grid line
print("---+", end="")
for t in range(T):
print("---+", end="")
print()
# Print column labels
print("m/t|", end="")
for t in range(T):
print(f"{t:2d} |", end="")
else:
print(f"{T:2d}=T")
print()