-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbml.py
More file actions
135 lines (124 loc) · 5.25 KB
/
bml.py
File metadata and controls
135 lines (124 loc) · 5.25 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
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
import numpy as np
import random
import settings
def bml(lattice : np.ndarray) -> tuple:
for step in range(settings.SIMULATION_STEPS):
if step % 2 == 0:
for i, j in zip(*np.where(lattice == 1)):
if i < settings.LATTICE_SIZE - 1:
if lattice[i + 1, j] == 0:
lattice[i + 1, j] = 1
lattice[i, j] = 0
else:
if lattice[0, j] == 0:
lattice[0, j] = 1
lattice[i, j] = 0
elif step % 2 != 0:
for i, j in zip(*np.where(lattice == 2)):
if j < settings.LATTICE_SIZE - 1:
if lattice[i, j + 1] == 0:
lattice[i, j + 1] = 2
lattice[i, j] = 0
else:
if lattice[i, 0] == 0:
lattice[i, 0] = 2
lattice[i, j] = 0
yield step, lattice
def bmlr(lattice : np.ndarray) -> tuple:
for step in range(settings.SIMULATION_STEPS):
coords = [
(random.randint(0, settings.LATTICE_SIZE - 1),
random.randint(0, settings.LATTICE_SIZE - 1)) for _ in range(settings.LATTICE_SIZE**2)
]
for (i, j) in coords:
if lattice[i, j] == 1:
if i < settings.LATTICE_SIZE - 1:
if lattice[i + 1, j] == 0:
lattice[i + 1, j] = 1
lattice[i, j] = 0
else:
if lattice[0, j] == 0:
lattice[0, j] = 1
lattice[i, j] = 0
elif lattice[i, j] == 2:
if j < settings.LATTICE_SIZE - 1:
if lattice[i, j + 1] == 0:
lattice[i, j + 1] = 2
lattice[i, j] = 0
else:
if lattice[i, 0] == 0:
lattice[i, 0] = 2
lattice[i, j] = 0
yield step, lattice
def loop_klein(x) -> int:
return settings.LATTICE_SIZE - x - 1
def klein_bml(lattice : np.ndarray) -> tuple:
for step in range(settings.SIMULATION_STEPS):
if step % 2 == 0:
for i, j, k in zip(*np.where(lattice == 1)):
if i < settings.LATTICE_SIZE - 1:
if lattice[i + 1, j, k] == 0:
lattice[i + 1, j, k] = 1
lattice[i, j, k] = 0
else:
if k == 0:
if lattice[0, loop_klein(j), 1] == 0:
lattice[0, loop_klein(j), 1] = 1
lattice[i, j, k] = 0
else:
if lattice[0, loop_klein(j), 0] == 0:
lattice[0, loop_klein(j), 0] = 1
lattice[i, j, k] = 0
elif step % 2 != 0:
for i, j, k in zip(*np.where(lattice == 2)):
if j < settings.LATTICE_SIZE - 1:
if lattice[i, j + 1, k] == 0:
lattice[i, j + 1, k] = 2
lattice[i, j, k] = 0
else:
if k == 0:
if lattice[loop_klein(i), 0, 1] == 0:
lattice[loop_klein(i), 0, 1] = 2
lattice[i, j, k] = 0
else:
if lattice[loop_klein(i), 0, 0] == 0:
lattice[loop_klein(i), 0, 0] = 2
lattice[i, j, k] = 0
yield step, lattice
def klein_bmlr(lattice : np.ndarray) -> tuple:
for step in range(settings.SIMULATION_STEPS):
coords = [
(random.randint(0, settings.LATTICE_SIZE - 1),
random.randint(0, settings.LATTICE_SIZE - 1),
random.randint(0, 1)) for _ in range(settings.LATTICE_SIZE**2)
]
for (i, j, k) in coords:
if lattice[i, j, k] == 1:
if i < settings.LATTICE_SIZE - 1:
if lattice[i + 1, j, k] == 0:
lattice[i + 1, j, k] = 1
lattice[i, j, k] = 0
else:
if k == 0:
if lattice[0, loop_klein(j), 1] == 0:
lattice[0, loop_klein(j), 1] = 1
lattice[i, j, k] = 0
else:
if lattice[0, loop_klein(j), 0] == 0:
lattice[0, loop_klein(j), 0] = 1
lattice[i, j, k] = 0
elif lattice[i, j, k] == 2:
if j < settings.LATTICE_SIZE - 1:
if lattice[i, j + 1, k] == 0:
lattice[i, j + 1, k] = 2
lattice[i, j, k] = 0
else:
if k == 0:
if lattice[loop_klein(i), 0, 1] == 0:
lattice[loop_klein(i), 0, 1] = 2
lattice[i, j, k] = 0
else:
if lattice[loop_klein(i), 0, 0] == 0:
lattice[loop_klein(i), 0, 0] = 2
lattice[i, j, k] = 0
yield step, lattice